From 62fe68850e185672de62f63df79a97dce3be5083 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Fri, 26 Mar 2021 10:35:51 +0300 Subject: [PATCH] pr: Fixes after rebasing Only the minimum needed to: * Make everything compile without warnings * Move files according to the new project structure * Make tests pass --- Cargo.lock | 22 +++++++++++-- Cargo.toml | 3 +- README.md | 2 +- src/pr/Cargo.toml | 28 ---------------- src/uu/pr/Cargo.toml | 33 +++++++++++++++++++ src/uu/pr/src/main.rs | 1 + src/{pr => uu/pr/src}/pr.rs | 30 +++++++---------- tests/{ => by-util}/test_pr.rs | 13 ++++---- .../pr/test_one_page_no_ht.log.expected | 3 +- 9 files changed, 76 insertions(+), 59 deletions(-) delete mode 100644 src/pr/Cargo.toml create mode 100644 src/uu/pr/Cargo.toml create mode 100644 src/uu/pr/src/main.rs rename src/{pr => uu/pr/src}/pr.rs (98%) rename tests/{ => by-util}/test_pr.rs (98%) diff --git a/Cargo.lock b/Cargo.lock index 4851a6e13..4f61fb1b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,6 +182,7 @@ dependencies = [ name = "coreutils" version = "0.0.4" dependencies = [ + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "filetime 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -251,6 +252,7 @@ dependencies = [ "uu_paste 0.0.4", "uu_pathchk 0.0.4", "uu_pinky 0.0.4", + "uu_pr 0.0.4", "uu_printenv 0.0.4", "uu_printf 0.0.4", "uu_ptx 0.0.4", @@ -441,7 +443,7 @@ dependencies = [ "cfg-if 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -712,7 +714,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memoffset" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1884,6 +1886,20 @@ dependencies = [ "uucore_procs 0.0.5", ] +[[package]] +name = "uu_pr" +version = "0.0.4" +dependencies = [ + "chrono 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "getopts 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "itertools 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-error 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", + "uucore 0.0.7", + "uucore_procs 0.0.5", +] + [[package]] name = "uu_printenv" version = "0.0.4" @@ -2530,7 +2546,7 @@ dependencies = [ "checksum md5 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "79c56d6a0b07f9e19282511c83fc5b086364cbae4ba8c7d5f190c3d9b0425a48" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum memchr 2.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" -"checksum memoffset 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "157b4208e3059a8f9e78d559edc658e13df41410cb3ae03979c83130067fdd87" +"checksum memoffset 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cc14fc54a812b4472b4113facc3e44d099fbc0ea2ce0551fa5c703f8edfbfd38" "checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b" "checksum nodrop 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" "checksum num-integer 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" diff --git a/Cargo.toml b/Cargo.toml index 8afd36761..1bd559763 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -286,7 +286,7 @@ od = { optional=true, version="0.0.4", package="uu_od", path="src/uu/od" } paste = { optional=true, version="0.0.4", package="uu_paste", path="src/uu/paste" } pathchk = { optional=true, version="0.0.4", package="uu_pathchk", path="src/uu/pathchk" } pinky = { optional=true, version="0.0.4", package="uu_pinky", path="src/uu/pinky" } -pr = { optional=true, path="src/pr" } +pr = { optional=true, version="0.0.4", package="uu_pr", path="src/uu/pr" } printenv = { optional=true, version="0.0.4", package="uu_printenv", path="src/uu/printenv" } printf = { optional=true, version="0.0.4", package="uu_printf", path="src/uu/printf" } ptx = { optional=true, version="0.0.4", package="uu_ptx", path="src/uu/ptx" } @@ -332,6 +332,7 @@ yes = { optional=true, version="0.0.4", package="uu_yes", path="src/uu/yes" #pin_cc = { version="1.0.61, < 1.0.62", package="cc" } ## cc v1.0.62 has compiler errors for MinRustV v1.32.0, requires 1.34 (for `std::str::split_ascii_whitespace()`) [dev-dependencies] +chrono = "0.4.11" conv = "0.3" filetime = "0.2" glob = "0.3.0" diff --git a/README.md b/README.md index 8071e66b2..f292b7184 100644 --- a/README.md +++ b/README.md @@ -301,7 +301,7 @@ Utilities | cut | join | | | dircolors | df | | | dirname | tac | | -| du | | | +| du | pr | | | echo | | | | env | | | | expand | | | diff --git a/src/pr/Cargo.toml b/src/pr/Cargo.toml deleted file mode 100644 index 481404b3a..000000000 --- a/src/pr/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "pr" -version = "0.0.1" -authors = ["Tilak Patidar "] -build = "../../mkmain.rs" - -[lib] -name = "uu_pr" -path = "pr.rs" - -[dependencies] -getopts = "0.2.18" -time = "0.1.40" -chrono = "0.4.6" -quick-error = "1.2.2" -itertools = "0.7.8" -regex = "1.0.1" - -[dependencies.uucore] -path = "../uucore" -features = ["libc"] - -[target.'cfg(unix)'.dependencies] -unix_socket = "0.5.0" - -[[bin]] -name = "pr" -path = "../../uumain.rs" diff --git a/src/uu/pr/Cargo.toml b/src/uu/pr/Cargo.toml new file mode 100644 index 000000000..2eb8a03fe --- /dev/null +++ b/src/uu/pr/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "uu_pr" +version = "0.0.4" +authors = ["uutils developers"] +license = "MIT" +description = "pr ~ (uutils) convert text files for printing" + +homepage = "https://github.com/uutils/coreutils" +repository = "https://github.com/uutils/coreutils/tree/master/src/uu/pinky" +keywords = ["coreutils", "uutils", "cross-platform", "cli", "utility"] +categories = ["command-line-utilities"] +edition = "2018" + +[lib] +path = "src/pr.rs" + +[dependencies] +uucore = { version=">=0.0.7", package="uucore", path="../../uucore", features=["utmpx", "entries"] } +uucore_procs = { version=">=0.0.5", package="uucore_procs", path="../../uucore_procs" } +getopts = "0.2.21" +time = "0.1.41" +# A higher version would cause a conflict with time +chrono = "0.4.11" +quick-error = "1.2.3" +itertools = "0.10" +regex = "1.0" + +#[target.'cfg(unix)'.dependencies] +#unix_socket = "0.5.0" + +[[bin]] +name = "pr" +path = "src/main.rs" diff --git a/src/uu/pr/src/main.rs b/src/uu/pr/src/main.rs new file mode 100644 index 000000000..893145c3e --- /dev/null +++ b/src/uu/pr/src/main.rs @@ -0,0 +1 @@ +uucore_procs::main!(uu_pr); // spell-checker:ignore procs uucore diff --git a/src/pr/pr.rs b/src/uu/pr/src/pr.rs similarity index 98% rename from src/pr/pr.rs rename to src/uu/pr/src/pr.rs index ca35b6c1c..73386eaf0 100644 --- a/src/pr/pr.rs +++ b/src/uu/pr/src/pr.rs @@ -6,15 +6,8 @@ // that was distributed with this source code. // -#[cfg(unix)] -extern crate unix_socket; #[macro_use] extern crate quick_error; -extern crate chrono; -extern crate getopts; -extern crate itertools; -extern crate regex; -extern crate uucore; use chrono::offset::Local; use chrono::DateTime; @@ -26,7 +19,7 @@ use quick_error::ResultExt; use regex::Regex; use std::convert::From; use std::fs::{metadata, File, Metadata}; -use std::io::{stderr, stdin, stdout, BufRead, BufReader, Lines, Read, Stdin, Stdout, Write}; +use std::io::{stdin, stdout, BufRead, BufReader, Lines, Read, Stdin, Stdout, Write}; use std::iter::{FlatMap, Map}; use std::num::ParseIntError; #[cfg(unix)] @@ -185,7 +178,8 @@ quick_error! { } } -pub fn uumain(args: Vec) -> i32 { +pub fn uumain(args: impl uucore::Args) -> i32 { + let args = args.collect_str(); let mut opts = getopts::Options::new(); opts.opt( @@ -482,7 +476,7 @@ fn recreate_arguments(args: &Vec) -> Vec { fn print_error(matches: &Matches, err: PrError) { if !matches.opt_present(SUPPRESS_PRINTING_ERROR) { - writeln!(&mut stderr(), "{}", err); + eprintln!("{}", err); } } @@ -838,10 +832,10 @@ fn build_options( }) } -fn open(path: &str) -> Result, PrError> { +fn open(path: &str) -> Result, PrError> { if path == FILE_STDIN { let stdin: Stdin = stdin(); - return Ok(Box::new(stdin) as Box); + return Ok(Box::new(stdin) as Box); } metadata(path) @@ -858,7 +852,7 @@ fn open(path: &str) -> Result, PrError> { ft if ft.is_socket() => Err(PrError::IsSocket(path_string)), ft if ft.is_dir() => Err(PrError::IsDirectory(path_string)), ft if ft.is_file() || ft.is_symlink() => { - Ok(Box::new(File::open(path).context(path)?) as Box) + Ok(Box::new(File::open(path).context(path)?) as Box) } _ => Err(PrError::UnknownFiletype(path_string)), } @@ -907,10 +901,10 @@ fn split_lines_if_form_feed(file_content: Result) -> Vec Result { - let lines: Lines>> = + let lines: Lines>> = BufReader::with_capacity(READ_BUFFER_SIZE, open(path)?).lines(); - let pages: Box)>> = + let pages: Box)>> = read_stream_and_create_pages(options, lines, 0); for page_with_page_number in pages { @@ -923,9 +917,9 @@ fn pr(path: &String, options: &OutputOptions) -> Result { fn read_stream_and_create_pages( options: &OutputOptions, - lines: Lines>>, + lines: Lines>>, file_id: usize, -) -> Box)>> { +) -> Box)>> { let start_page: usize = options.start_page; let start_line_number: usize = get_start_line_number(options); let last_page: Option = options.end_page; @@ -994,7 +988,7 @@ fn mpr(paths: &Vec, options: &OutputOptions) -> Result { let file_line_groups: GroupBy< usize, - KMergeBy)>>, _>, _, _>, _>, + KMergeBy)>>, _>, _, _>, _>, _, > = paths .iter() diff --git a/tests/test_pr.rs b/tests/by-util/test_pr.rs similarity index 98% rename from tests/test_pr.rs rename to tests/by-util/test_pr.rs index 61b9a647c..1cd8fbdc8 100644 --- a/tests/test_pr.rs +++ b/tests/by-util/test_pr.rs @@ -1,9 +1,7 @@ -extern crate chrono; - -use common::util::*; +use crate::common::util::*; use std::fs::metadata; -use test_pr::chrono::offset::Local; -use test_pr::chrono::DateTime; +use chrono::offset::Local; +use chrono::DateTime; fn file_last_modified_time(ucmd: &UCommand, path: &str) -> String { let tmp_dir_path = ucmd.get_full_fixture_path(path); @@ -243,10 +241,11 @@ fn test_with_no_header_trailer_option() { let test_file_path = "test_one_page.log"; let expected_test_file_path = "test_one_page_no_ht.log.expected"; let mut scenario = new_ucmd!(); + let value = file_last_modified_time(&scenario, test_file_path); scenario .args(&["-t", test_file_path]) .succeeds() - .stdout_is_fixture(expected_test_file_path); + .stdout_is_templated_fixture(expected_test_file_path, vec![(&"{last_modified_time}".to_string(), &value)]); } #[test] @@ -480,7 +479,7 @@ fn test_with_pr_core_utils_tests() { arguments.extend(input_file.clone()); - let mut scenario_with_args = scenario.args(&arguments); + let scenario_with_args = scenario.args(&arguments); let scenario_with_expected_status = if return_code == 0 { scenario_with_args.succeeds() diff --git a/tests/fixtures/pr/test_one_page_no_ht.log.expected b/tests/fixtures/pr/test_one_page_no_ht.log.expected index 3d5131358..2abea9890 100644 --- a/tests/fixtures/pr/test_one_page_no_ht.log.expected +++ b/tests/fixtures/pr/test_one_page_no_ht.log.expected @@ -53,4 +53,5 @@ Mon Dec 10 11:42:58.960 Info: -[AirPortExtraImplementati Mon Dec 10 11:42:59.155 Info: 802.1X changed Mon Dec 10 11:42:59.157 Info: -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0 Mon Dec 10 11:42:59.159 Info: -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars -Mon Dec 10 11:42:59.352 Info: 802.1X changed \ No newline at end of file +Mon Dec 10 11:42:59.352 Info: 802.1X changed +