diff options
| author | Jack O'Connor <[email protected]> | 2020-05-23 12:34:02 -0400 |
|---|---|---|
| committer | Jack O'Connor <[email protected]> | 2020-05-23 12:46:45 -0400 |
| commit | 48512ec4f06cffaa3b3fba7af344f4924c1e6b10 (patch) | |
| tree | 5579e744508aab82cd9674847e866ccbca55c744 | |
| parent | c9a1676942841973dc412f2b1e1f2d67b20949e2 (diff) | |
use wild::args_os to support globbing on Windows
| -rw-r--r-- | b3sum/Cargo.toml | 1 | ||||
| -rw-r--r-- | b3sum/src/main.rs | 4 | ||||
| -rw-r--r-- | b3sum/tests/cli_tests.rs | 27 |
3 files changed, 31 insertions, 1 deletions
diff --git a/b3sum/Cargo.toml b/b3sum/Cargo.toml index a72450e..3b1368c 100644 --- a/b3sum/Cargo.toml +++ b/b3sum/Cargo.toml @@ -20,6 +20,7 @@ clap = "2.33.1" hex = "0.4.0" memmap = "0.7.0" rayon = "1.2.1" +wild = "2.0.3" [dev-dependencies] duct = "0.13.3" diff --git a/b3sum/src/main.rs b/b3sum/src/main.rs index 10f19ea..5d82f40 100644 --- a/b3sum/src/main.rs +++ b/b3sum/src/main.rs @@ -114,7 +114,9 @@ impl Args { Must be used with --check.", ), ) - .get_matches(); + // wild::args_os() is equivalent to std::env::args_os() on Unix, + // but on Windows it adds support for globbing. + .get_matches_from(wild::args_os()); let file_args = if let Some(iter) = inner.values_of_os(FILE_ARG) { iter.map(|s| s.into()).collect() } else { diff --git a/b3sum/tests/cli_tests.rs b/b3sum/tests/cli_tests.rs index 729e0e8..2f4b47c 100644 --- a/b3sum/tests/cli_tests.rs +++ b/b3sum/tests/cli_tests.rs @@ -483,3 +483,30 @@ fn test_check_invalid_characters() { assert_eq!("b3sum: Backslash in path\n", stderr); } } + +#[test] +fn test_globbing() { + // On Unix, globbing is provided by the shell. On Windows, globbing is + // provided by us, using the `wild` crate. + let dir = tempfile::tempdir().unwrap(); + let file1 = dir.path().join("file1"); + fs::write(&file1, b"foo").unwrap(); + let file2 = dir.path().join("file2"); + fs::write(&file2, b"bar").unwrap(); + + let foo_hash = blake3::hash(b"foo"); + let bar_hash = blake3::hash(b"bar"); + let expected = format!("{} file1\n{} file2", foo_hash.to_hex(), bar_hash.to_hex()); + + let star_command = format!("{} *", b3sum_exe().to_str().unwrap()); + let (exe, c_flag) = if cfg!(windows) { + ("cmd.exe", "/C") + } else { + ("/bin/sh", "-c") + }; + let output = cmd!(exe, c_flag, star_command) + .dir(dir.path()) + .read() + .unwrap(); + assert_eq!(expected, output); +} |
