From 076ff32e85740e42634c66783d77a8699c1a5ee5 Mon Sep 17 00:00:00 2001 From: Tyler Date: Fri, 23 Jul 2021 14:53:24 -0700 Subject: [PATCH] Removes project-specific cspell files. --- .vscode/cSpell.json | 2 +- .../cspell.dictionaries/jargon.wordlist.txt | 19 +++ src/uu/dd/cspell.json | 67 ---------- src/uu/dd/src/dd.rs | 56 ++++++-- src/uu/dd/src/parseargs/unit_tests.rs | 120 +++++++++++------- tests/by-util/test_dd.rs | 2 + tests/fixtures/dd/cspell.json | 31 ----- 7 files changed, 138 insertions(+), 159 deletions(-) delete mode 100644 src/uu/dd/cspell.json delete mode 100644 tests/fixtures/dd/cspell.json diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json index 9869923a4..498360139 100644 --- a/.vscode/cSpell.json +++ b/.vscode/cSpell.json @@ -11,7 +11,7 @@ { "name": "workspace", "path": "./cspell.dictionaries/workspace.wordlist.txt" } ], // ignorePaths - a list of globs to specify which files are to be ignored - "ignorePaths": ["Cargo.lock", "target/**", "tests/**/fixtures/**"], + "ignorePaths": ["Cargo.lock", "target/**", "tests/**/fixtures/**", "src/uu/dd/test-resources/**"], // ignoreWords - a list of words to be ignored (even if they are in the flagWords) "ignoreWords": [], // words - list of words to be always considered correct diff --git a/.vscode/cspell.dictionaries/jargon.wordlist.txt b/.vscode/cspell.dictionaries/jargon.wordlist.txt index c2e2c29f3..38abc75b1 100644 --- a/.vscode/cspell.dictionaries/jargon.wordlist.txt +++ b/.vscode/cspell.dictionaries/jargon.wordlist.txt @@ -12,6 +12,7 @@ colorizable colorize coprime consts +conv cyclomatic dedup deduplication @@ -23,6 +24,7 @@ dev devs discoverability duplicative +dsync enqueue errored executable @@ -30,7 +32,10 @@ executables exponentiate eval falsey +fileio flamegraph +fullblock +gibi gibibytes glob globbing @@ -39,8 +44,12 @@ hardlink hardlinks hasher hashsums +infile +iflag +iflags kibi kibibytes +lcase mebi mebibytes mergeable @@ -49,8 +58,15 @@ microbenchmarks microbenchmarking multibyte multicall +noatime +nocreat nonportable nonprinting +notrunc +noxfer +ofile +oflag +oflags peekable performant precompiled @@ -73,6 +89,7 @@ shortcodes subcommand subexpression submodule +sync symlink symlinks syscall @@ -80,12 +97,14 @@ syscalls tokenize toolchain truthy +ucase unbuffered unescape unintuitive unprefixed unportable unsync +urand whitespace wordlist wordlists diff --git a/src/uu/dd/cspell.json b/src/uu/dd/cspell.json deleted file mode 100644 index 4e47b090f..000000000 --- a/src/uu/dd/cspell.json +++ /dev/null @@ -1,67 +0,0 @@ -{ - "version": "0.1", - "language": "en", - "words": [ - "ucase", - "lcase", - "nocreat", - "noerror", - "notrunc", - "nocache", - "dsync", - "sync", - "nonblock", - "noctty", - "nofollow", - "nolinks", - "fullblock", - "noxfer", - "iflag", - "iflags", - "oflag", - "oflags", - "infile", - "outfile", - "fileio", - "urand", - "xfer", - "cflags", - "ctable", - "gnudd", - "atoe", - "etoa", - "atoibm", - "bmax", - "datastructures", - "creat", - "mult", - "behaviour", - "ctty", - "noatime", - "fname", - "fileout", - "ofile", - "doesnt", - "parseargs", - "rlen", - "wlen", - "rstat", - "wstat", - "rposition", - "btotal", - "sigval", - "sigusr", - "rmax", - "rsofar", - "rremain", - "bremain", - "oconvflags", - "fpath", - "testfile", - "specfile" - ], - "ignorePaths": [ - "**/test-resources/*.test", - "**/test-resources/*.spec" - ] -} diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index d0faaacf7..6eef1350e 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -714,6 +714,10 @@ fn gen_prog_updater(rx: mpsc::Receiver, print_level: Option bool { env::var("POSIXLY_CORRECT").is_ok() } + // Since signal-prompted progress printing is only availible on Linux so far, we allow unused + // variables to remove build warnings on Windows and other platforms. + // Remove when possible. + #[allow(unused_variables)] fn register_signal_handlers(sigval: Arc) -> Result<(), Box> { #[cfg(target_os = "linux")] if !posixly_correct() { @@ -1028,61 +1032,81 @@ pub fn uu_app() -> clap::App<'static, 'static> { clap::Arg::with_name(options::INFILE) .long(options::INFILE) .takes_value(true) - .help("if=FILE (alternatively --if FILE) specifies the file used for input. When not specified, stdin is used instead") + .require_equals(true) + .value_name("FILE") + .help("(alternatively if=FILE) specifies the file used for input. When not specified, stdin is used instead") ) .arg( clap::Arg::with_name(options::OUTFILE) .long(options::OUTFILE) .takes_value(true) - .help("of=FILE (alternatively --of FILE) specifies the file used for output. When not specified, stdout is used instead") + .require_equals(true) + .value_name("FILE") + .help("(alternatively of=FILE) specifies the file used for output. When not specified, stdout is used instead") ) .arg( clap::Arg::with_name(options::IBS) .long(options::IBS) .takes_value(true) - .help("ibs=N (alternatively --ibs N) specifies the size of buffer used for reads (default: 512). Multiplier strings permitted.") + .require_equals(true) + .value_name("N") + .help("(alternatively ibs=N) specifies the size of buffer used for reads (default: 512). Multiplier strings permitted.") ) .arg( clap::Arg::with_name(options::OBS) .long(options::OBS) .takes_value(true) - .help("obs=N (alternatively --obs N) specifies the size of buffer used for writes (default: 512). Multiplier strings permitted.") + .require_equals(true) + .value_name("N") + .help("(alternatively obs=N) specifies the size of buffer used for writes (default: 512). Multiplier strings permitted.") ) .arg( clap::Arg::with_name(options::BS) .long(options::BS) .takes_value(true) - .help("bs=N (alternatively --bs N) specifies ibs=N and obs=N (default: 512). If ibs or obs are also specified, bs=N takes precedence. Multiplier strings permitted.") + .require_equals(true) + .value_name("N") + .help("(alternatively bs=N) specifies ibs=N and obs=N (default: 512). If ibs or obs are also specified, bs=N takes precedence. Multiplier strings permitted.") ) .arg( clap::Arg::with_name(options::CBS) .long(options::CBS) .takes_value(true) - .help("cbs=BYTES (alternatively --cbs BYTES) specifies the 'conversion block size' in bytes. Applies to the conv=block, and conv=unblock operations. Multiplier strings permitted.") + .require_equals(true) + .value_name("N") + .help("(alternatively cbs=BYTES) specifies the 'conversion block size' in bytes. Applies to the conv=block, and conv=unblock operations. Multiplier strings permitted.") ) .arg( clap::Arg::with_name(options::SKIP) .long(options::SKIP) .takes_value(true) - .help("skip=N (alternatively --skip N) causes N ibs-sized records of input to be skipped before beginning copy/convert operations. See iflag=count_bytes if skipping N bytes is preferred. Multiplier strings permitted.") + .require_equals(true) + .value_name("N") + .help("(alternatively skip=N) causes N ibs-sized records of input to be skipped before beginning copy/convert operations. See iflag=count_bytes if skipping N bytes is preferred. Multiplier strings permitted.") ) .arg( clap::Arg::with_name(options::SEEK) .long(options::SEEK) .takes_value(true) - .help("seek=N (alternatively --seek N) seeks N obs-sized records into output before beginning copy/convert operations. See oflag=seek_bytes if seeking N bytes is preferred. Multiplier strings permitted.") + .require_equals(true) + .value_name("N") + .help("(alternatively seek=N) seeks N obs-sized records into output before beginning copy/convert operations. See oflag=seek_bytes if seeking N bytes is preferred. Multiplier strings permitted.") ) .arg( clap::Arg::with_name(options::COUNT) .long(options::COUNT) .takes_value(true) - .help("count=N (alternatively --count N) stop reading input after N ibs-sized read operations rather than proceeding until EOF. See iflag=count_bytes if stopping after N bytes is preferred. Multiplier strings permitted.") + .require_equals(true) + .value_name("N") + .help("(alternatively count=N) stop reading input after N ibs-sized read operations rather than proceeding until EOF. See iflag=count_bytes if stopping after N bytes is preferred. Multiplier strings permitted.") ) .arg( clap::Arg::with_name(options::STATUS) .long(options::STATUS) .takes_value(true) - .help("status=LEVEL (alternatively --status LEVEL) controls whether volume and performance stats are written to stderr. + .require_equals(true) + .value_name("LEVEL") + .help("(alternatively status=LEVEL) controls whether volume and performance stats are written to stderr. When unspecified, dd will print stats upon completion. An example is below. \t6+0 records in @@ -1104,7 +1128,9 @@ Printing performance stats is also triggered by the INFO signal (where supported clap::Arg::with_name(options::CONV) .long(options::CONV) .takes_value(true) - .help("conv=CONV[,CONV] (alternatively --conv CONV[,CONV]) specifies a comma-separated list of conversion options or (for legacy reasons) file flags. Conversion options and file flags may be intermixed. + .require_equals(true) + .value_name("CONV") + .help("(alternatively conv=CONV[,CONV]) specifies a comma-separated list of conversion options or (for legacy reasons) file flags. Conversion options and file flags may be intermixed. Conversion options: \t One of {ascii, ebcdic, ibm} will perform an encoding conversion. @@ -1139,7 +1165,9 @@ Conversion Flags: clap::Arg::with_name(options::IFLAG) .long(options::IFLAG) .takes_value(true) - .help("iflag=FLAG[,FLAG] (alternatively --iflag FLAG[,FLAG]) a comma separated list of input flags which specify how the input source is treated. FLAG may be any of the input-flags or general-flags specified below. + .require_equals(true) + .value_name("FLAG") + .help("(alternatively iflag=FLAG[,FLAG]) a comma separated list of input flags which specify how the input source is treated. FLAG may be any of the input-flags or general-flags specified below. Input-Flags \t 'count_bytes' a value to count=N will be interpreted as bytes. @@ -1163,7 +1191,9 @@ General-Flags clap::Arg::with_name(options::OFLAG) .long(options::OFLAG) .takes_value(true) - .help("oflag=FLAG[,FLAG] (alternatively --oflag FLAG[,FLAG]) a comma separated list of output flags which specify how the output source is treated. FLAG may be any of the output-flags or general-flags specified below. + .require_equals(true) + .value_name("FLAG") + .help("(alternatively oflag=FLAG[,FLAG]) a comma separated list of output flags which specify how the output source is treated. FLAG may be any of the output-flags or general-flags specified below. Output-Flags \t 'append' open file in append mode. Consider setting conv=notrunc as well. diff --git a/src/uu/dd/src/parseargs/unit_tests.rs b/src/uu/dd/src/parseargs/unit_tests.rs index 765eb6f46..7a6fefb5a 100644 --- a/src/uu/dd/src/parseargs/unit_tests.rs +++ b/src/uu/dd/src/parseargs/unit_tests.rs @@ -104,7 +104,7 @@ fn test_status_level_none() { } #[test] -fn test_all_top_level_args_no_leading_dashes_sep_by_equals() { +fn test_all_top_level_args_no_leading_dashes() { let args = vec![ String::from("dd"), String::from("if=foo.file"), @@ -187,25 +187,23 @@ fn test_all_top_level_args_no_leading_dashes_sep_by_equals() { ); } -#[ignore] #[test] -// TODO: This should work, but Clap doesn't seem to understand it. Leaving it for now since the traditional dd if=foo.file works just fine. -fn test_all_top_level_args_leading_dashes_sep_by_spaces() { +fn test_all_top_level_args_with_leading_dashes() { let args = vec![ String::from("dd"), - String::from("--if foo.file"), - String::from("--of bar.file"), - String::from("--ibs 10"), - String::from("--obs 10"), - String::from("--cbs 1"), - String::from("--bs 100"), - String::from("--count 2"), - String::from("--skip 2"), - String::from("--seek 2"), - String::from("--status progress"), - String::from("--conv ascii,ucase"), - String::from("--iflag count_bytes,skip_bytes"), - String::from("--oflag append,seek_bytes"), + String::from("--if=foo.file"), + String::from("--of=bar.file"), + String::from("--ibs=10"), + String::from("--obs=10"), + String::from("--cbs=1"), + String::from("--bs=100"), + String::from("--count=2"), + String::from("--skip=2"), + String::from("--seek=2"), + String::from("--status=progress"), + String::from("--conv=ascii,ucase"), + String::from("--iflag=count_bytes,skip_bytes"), + String::from("--oflag=append,seek_bytes"), ]; let args = args .into_iter() @@ -415,27 +413,13 @@ fn parse_iflag_tokens() { Flag::FullBlock, Flag::CountBytes, Flag::SkipBytes, - // Flag::Cio, - Flag::Direct, - Flag::Directory, - Flag::Dsync, - Flag::Sync, - // Flag::NoCache, - Flag::NonBlock, - Flag::NoATime, - Flag::NoCtty, - Flag::NoFollow, - // Flag::NoLinks, - // Flag::Binary, - // Flag::Text, Flag::Append, Flag::SeekBytes, ]; let args = vec![ String::from("dd"), - String::from("--iflag=fullblock,count_bytes,skip_bytes,direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow,append,seek_bytes"), - // String::from("--iflag=fullblock,count_bytes,skip_bytes,cio,direct,directory,dsync,sync,nocache,nonblock,noatime,noctty,nofollow,nolinks,binary,text,append,seek_bytes"), + String::from("--iflag=fullblock,count_bytes,skip_bytes,append,seek_bytes"), ]; let matches = uu_app().get_matches_from_safe(args).unwrap(); @@ -453,27 +437,69 @@ fn parse_oflag_tokens() { Flag::FullBlock, Flag::CountBytes, Flag::SkipBytes, - // Flag::Cio, - Flag::Direct, - Flag::Directory, - Flag::Dsync, - Flag::Sync, - // Flag::NoCache, - Flag::NonBlock, - Flag::NoATime, - Flag::NoCtty, - Flag::NoFollow, - // Flag::NoLinks, - // Flag::Binary, - // Flag::Text, Flag::Append, Flag::SeekBytes, ]; let args = vec![ String::from("dd"), - String::from("--oflag=fullblock,count_bytes,skip_bytes,direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow,append,seek_bytes"), - // String::from("--oflag=fullblock,count_bytes,skip_bytes,cio,direct,directory,dsync,sync,nocache,nonblock,noatime,noctty,nofollow,nolinks,binary,text,append,seek_bytes"), + String::from("--oflag=fullblock,count_bytes,skip_bytes,append,seek_bytes"), + ]; + let matches = uu_app().get_matches_from_safe(args).unwrap(); + + let act = parse_flag_list::("oflag", &matches).unwrap(); + + assert_eq!(exp.len(), act.len()); + for cf in &exp { + assert!(exp.contains(&cf)); + } +} + +#[cfg(target_os = "linux")] +#[test] +fn parse_iflag_tokens_linux() { + let exp = vec![ + Flag::Direct, + Flag::Directory, + Flag::Dsync, + Flag::Sync, + Flag::NonBlock, + Flag::NoATime, + Flag::NoCtty, + Flag::NoFollow, + ]; + + let args = vec![ + String::from("dd"), + String::from("--iflag=direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow"), + ]; + let matches = uu_app().get_matches_from_safe(args).unwrap(); + + let act = parse_flag_list::("iflag", &matches).unwrap(); + + assert_eq!(exp.len(), act.len()); + for cf in &exp { + assert!(exp.contains(&cf)); + } +} + +#[cfg(target_os = "linux")] +#[test] +fn parse_oflag_tokens_linux() { + let exp = vec![ + Flag::Direct, + Flag::Directory, + Flag::Dsync, + Flag::Sync, + Flag::NonBlock, + Flag::NoATime, + Flag::NoCtty, + Flag::NoFollow, + ]; + + let args = vec![ + String::from("dd"), + String::from("--oflag=direct,directory,dsync,sync,nonblock,noatime,noctty,nofollow"), ]; let matches = uu_app().get_matches_from_safe(args).unwrap(); diff --git a/tests/by-util/test_dd.rs b/tests/by-util/test_dd.rs index e038ee24b..821e9f0c3 100644 --- a/tests/by-util/test_dd.rs +++ b/tests/by-util/test_dd.rs @@ -1,3 +1,5 @@ +// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio + use crate::common::util::*; use std::fs::{File, OpenOptions}; diff --git a/tests/fixtures/dd/cspell.json b/tests/fixtures/dd/cspell.json deleted file mode 100644 index 65fa927d6..000000000 --- a/tests/fixtures/dd/cspell.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "version": "0.1", - "language": "en", - "words": [ - "fname", - "fpath", - "specfile", - "testfile", - "iflag", - "iflags", - "oflag", - "oflags", - "noxfer", - "nocreat", - "noatime", - "infile", - "outfile", - "unspec", - "fullblock", - "urand", - "tname", - "fileio", - "gibi", - "ucase", - "lcase" - ], - "ignorePaths": [ - "*.txt", - "*.spec" - ] -}