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
This commit is contained in:
Max Semenik 2021-03-26 10:35:51 +03:00
parent 75b35e6002
commit 62fe68850e
9 changed files with 76 additions and 59 deletions

22
Cargo.lock generated
View file

@ -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"

View file

@ -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"

View file

@ -301,7 +301,7 @@ Utilities
| cut | join | |
| dircolors | df | |
| dirname | tac | |
| du | | |
| du | pr | |
| echo | | |
| env | | |
| expand | | |

View file

@ -1,28 +0,0 @@
[package]
name = "pr"
version = "0.0.1"
authors = ["Tilak Patidar <tilakpatidar@gmail.com>"]
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"

33
src/uu/pr/Cargo.toml Normal file
View file

@ -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"

1
src/uu/pr/src/main.rs Normal file
View file

@ -0,0 +1 @@
uucore_procs::main!(uu_pr); // spell-checker:ignore procs uucore

View file

@ -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<String>) -> 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<String>) -> Vec<String> {
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<Box<Read>, PrError> {
fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
if path == FILE_STDIN {
let stdin: Stdin = stdin();
return Ok(Box::new(stdin) as Box<Read>);
return Ok(Box::new(stdin) as Box<dyn Read>);
}
metadata(path)
@ -858,7 +852,7 @@ fn open(path: &str) -> Result<Box<Read>, 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<Read>)
Ok(Box::new(File::open(path).context(path)?) as Box<dyn Read>)
}
_ => Err(PrError::UnknownFiletype(path_string)),
}
@ -907,10 +901,10 @@ fn split_lines_if_form_feed(file_content: Result<String, IOError>) -> Vec<FileLi
}
fn pr(path: &String, options: &OutputOptions) -> Result<i32, PrError> {
let lines: Lines<BufReader<Box<Read>>> =
let lines: Lines<BufReader<Box<dyn Read>>> =
BufReader::with_capacity(READ_BUFFER_SIZE, open(path)?).lines();
let pages: Box<Iterator<Item = (usize, Vec<FileLine>)>> =
let pages: Box<dyn Iterator<Item = (usize, Vec<FileLine>)>> =
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<i32, PrError> {
fn read_stream_and_create_pages(
options: &OutputOptions,
lines: Lines<BufReader<Box<Read>>>,
lines: Lines<BufReader<Box<dyn Read>>>,
file_id: usize,
) -> Box<Iterator<Item = (usize, Vec<FileLine>)>> {
) -> Box<dyn Iterator<Item = (usize, Vec<FileLine>)>> {
let start_page: usize = options.start_page;
let start_line_number: usize = get_start_line_number(options);
let last_page: Option<usize> = options.end_page;
@ -994,7 +988,7 @@ fn mpr(paths: &Vec<String>, options: &OutputOptions) -> Result<i32, PrError> {
let file_line_groups: GroupBy<
usize,
KMergeBy<FlatMap<Map<Box<Iterator<Item = (usize, Vec<FileLine>)>>, _>, _, _>, _>,
KMergeBy<FlatMap<Map<Box<dyn Iterator<Item = (usize, Vec<FileLine>)>>, _>, _, _>, _>,
_,
> = paths
.iter()

View file

@ -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()

View file

@ -53,4 +53,5 @@ Mon Dec 10 11:42:58.960 Info: <Wi-Fi Menu Extra[335]> -[AirPortExtraImplementati
Mon Dec 10 11:42:59.155 Info: <Wi-Fi Menu Extra[335]> 802.1X changed
Mon Dec 10 11:42:59.157 Info: <Wi-Fi Menu Extra[335]> -[AirPortExtraImplementation processAirPortStateChanges]: pppConnectionState 0
Mon Dec 10 11:42:59.159 Info: <Wi-Fi Menu Extra[335]> -[AirPortExtraImplementation processAirPortStateChanges]: old state=4 bars, new state=4 bars
Mon Dec 10 11:42:59.352 Info: <Wi-Fi Menu Extra[335]> 802.1X changed
Mon Dec 10 11:42:59.352 Info: <Wi-Fi Menu Extra[335]> 802.1X changed