Skip to content
Myr

Enable --strip-cwd-prefix by default except with -0

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fixes #1046.

authored by Tavian Barnes · committed by David Peter · parent e46d402 · Browse files · 3 files+331 added−343 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+331 added−343 removed

  • tests:+327 added−339 removed
  • other:+4 added−4 removed

3 files+331 added−343 removed

modified:src/app.rs+3 added-3 removed
717 unmodified lines
718 Arg::new("strip-cwd-prefix")719 .long("strip-cwd-prefix")720 .conflicts_with_all(&["path", "search-path"])721 .hide_short_help(true)722 .help("strip './' prefix from non-tty outputs")722 .help("strip './' prefix from -0/--print0 output")723 .long_help(724 "By default, relative paths are prefixed with './' when the output goes to a non \725 interactive terminal (TTY). Use this flag to disable this behaviour."724 "By default, relative paths are prefixed with './' when -0/--print0 is given, to \725 make them safer for use with xargs. Use this flag to disable this behaviour."726 )727 );728729 if cfg!(unix) {
45 unmodified lines
modified:src/main.rs+1 added-1 removed
383 unmodified lines
384 }385 }),386 strip_cwd_prefix: (!matches.is_present("path")387 && !matches.is_present("search-path")388 && (interactive_terminal || matches.is_present("strip-cwd-prefix"))),388 && (!matches.is_present("null_separator") || matches.is_present("strip-cwd-prefix"))),389 })390}391392fn extract_command(
175 unmodified lines
modified:tests/tests.rs+327 added-339 removed
59 unmodified lines
60#[test]61fn test_simple() {62 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);6364 te.assert_output(&["a.foo"], "./a.foo");65 te.assert_output(&["b.foo"], "./one/b.foo");66 te.assert_output(&["d.foo"], "./one/two/three/d.foo");64 te.assert_output(&["a.foo"], "a.foo");65 te.assert_output(&["b.foo"], "one/b.foo");66 te.assert_output(&["d.foo"], "one/two/three/d.foo");6768 te.assert_output(69 &["foo"],70 "./a.foo71 ./one/b.foo72 ./one/two/c.foo73 ./one/two/C.Foo274 ./one/two/three/d.foo75 ./one/two/three/directory_foo/",70 "a.foo71 one/b.foo72 one/two/c.foo73 one/two/C.Foo274 one/two/three/d.foo75 one/two/three/directory_foo/",76 );77}7879/// Test each pattern type with an empty pattern.80#[test]81fn test_empty_pattern() {82 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);83 let expected = "./a.foo84 ./e1 e285 ./one/86 ./one/b.foo87 ./one/two/88 ./one/two/c.foo89 ./one/two/C.Foo290 ./one/two/three/91 ./one/two/three/d.foo92 ./one/two/three/directory_foo/93 ./symlink";83 let expected = "a.foo84 e1 e285 one/86 one/b.foo87 one/two/88 one/two/c.foo89 one/two/C.Foo290 one/two/three/91 one/two/three/d.foo92 one/two/three/directory_foo/93 symlink";9495 te.assert_output(&["--regex"], expected);96 te.assert_output(&["--fixed-strings"], expected);97 te.assert_output(&["--glob"], expected);
110 unmodified lines
208 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);209210 te.assert_output(211 &["[a-c].foo"],212 "./a.foo213 ./one/b.foo214 ./one/two/c.foo215 ./one/two/C.Foo2",212 "a.foo213 one/b.foo214 one/two/c.foo215 one/two/C.Foo2",216 );217218 te.assert_output(219 &["--case-sensitive", "[a-c].foo"],220 "./a.foo221 ./one/b.foo222 ./one/two/c.foo",220 "a.foo221 one/b.foo222 one/two/c.foo",223 );224}225226/// Smart case
2 unmodified lines
229 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);230231 te.assert_output(232 &["c.foo"],233 "./one/two/c.foo234 ./one/two/C.Foo2",233 "one/two/c.foo234 one/two/C.Foo2",235 );236237 te.assert_output(&["C.Foo"], "./one/two/C.Foo2");237 te.assert_output(&["C.Foo"], "one/two/C.Foo2");238239 te.assert_output(&["Foo"], "./one/two/C.Foo2");239 te.assert_output(&["Foo"], "one/two/C.Foo2");240241 // Only literal uppercase chars should trigger case sensitivity.242 te.assert_output(243 &["\\Ac"],244 "./one/two/c.foo245 ./one/two/C.Foo2",244 "one/two/c.foo245 one/two/C.Foo2",246 );247 te.assert_output(&["\\AC"], "./one/two/C.Foo2");247 te.assert_output(&["\\AC"], "one/two/C.Foo2");248}249250/// Case sensitivity (--case-sensitive)251#[test]252fn test_case_sensitive() {253 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);254255 te.assert_output(&["--case-sensitive", "c.foo"], "./one/two/c.foo");255 te.assert_output(&["--case-sensitive", "c.foo"], "one/two/c.foo");256257 te.assert_output(&["--case-sensitive", "C.Foo"], "./one/two/C.Foo2");257 te.assert_output(&["--case-sensitive", "C.Foo"], "one/two/C.Foo2");258259 te.assert_output(260 &["--ignore-case", "--case-sensitive", "C.Foo"],261 "./one/two/C.Foo2",261 "one/two/C.Foo2",262 );263}264265/// Case insensitivity (--ignore-case)
2 unmodified lines
268 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);269270 te.assert_output(271 &["--ignore-case", "C.Foo"],272 "./one/two/c.foo273 ./one/two/C.Foo2",272 "one/two/c.foo273 one/two/C.Foo2",274 );275276 te.assert_output(277 &["--case-sensitive", "--ignore-case", "C.Foo"],278 "./one/two/c.foo279 ./one/two/C.Foo2",278 "one/two/c.foo279 one/two/C.Foo2",280 );281}282283/// Glob-based searches (--glob)
2 unmodified lines
286 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);287288 te.assert_output(289 &["--glob", "*.foo"],290 "./a.foo291 ./one/b.foo292 ./one/two/c.foo293 ./one/two/three/d.foo",290 "a.foo291 one/b.foo292 one/two/c.foo293 one/two/three/d.foo",294 );295296 te.assert_output(297 &["--glob", "[a-c].foo"],298 "./a.foo299 ./one/b.foo300 ./one/two/c.foo",298 "a.foo299 one/b.foo300 one/two/c.foo",301 );302303 te.assert_output(304 &["--glob", "[a-c].foo*"],305 "./a.foo306 ./one/b.foo307 ./one/two/C.Foo2308 ./one/two/c.foo",305 "a.foo306 one/b.foo307 one/two/C.Foo2308 one/two/c.foo",309 );310}311312/// Glob-based searches (--glob) in combination with full path searches (--full-path)
3 unmodified lines
316 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);317318 te.assert_output(319 &["--glob", "--full-path", "**/one/**/*.foo"],320 "./one/b.foo321 ./one/two/c.foo322 ./one/two/three/d.foo",320 "one/b.foo321 one/two/c.foo322 one/two/three/d.foo",323 );324325 te.assert_output(326 &["--glob", "--full-path", "**/one/*/*.foo"],327 " ./one/two/c.foo",327 " one/two/c.foo",328 );329330 te.assert_output(331 &["--glob", "--full-path", "**/one/*/*/*.foo"],332 " ./one/two/three/d.foo",332 " one/two/three/d.foo",333 );334}335336#[test]
1 unmodified line
338 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);339340 te.assert_output(341 &["--glob", "c.foo*"],342 "./one/two/C.Foo2343 ./one/two/c.foo",342 "one/two/C.Foo2343 one/two/c.foo",344 );345346 te.assert_output(&["--glob", "C.Foo*"], "./one/two/C.Foo2");346 te.assert_output(&["--glob", "C.Foo*"], "one/two/C.Foo2");347}348349/// Glob-based searches (--glob) in combination with --case-sensitive350#[test]351fn test_case_sensitive_glob_searches() {352 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);353354 te.assert_output(&["--glob", "--case-sensitive", "c.foo*"], "./one/two/c.foo");354 te.assert_output(&["--glob", "--case-sensitive", "c.foo*"], "one/two/c.foo");355}356357/// Glob-based searches (--glob) in combination with --extension358#[test]
1 unmodified line
360 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);361362 te.assert_output(363 &["--glob", "--extension", "foo2", "[a-z].*"],364 "./one/two/C.Foo2",364 "one/two/C.Foo2",365 );366}367368/// Make sure that --regex overrides --glob369#[test]370fn test_regex_overrides_glob() {371 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);372373 te.assert_output(&["--glob", "--regex", "Foo2$"], "./one/two/C.Foo2");373 te.assert_output(&["--glob", "--regex", "Foo2$"], "one/two/C.Foo2");374}375376/// Full path search (--full-path)377#[test]
7 unmodified lines
385 &[386 "--full-path",387 &format!("^{prefix}.*three.*foo$", prefix = prefix),388 ],389 "./one/two/three/d.foo390 ./one/two/three/directory_foo/",389 "one/two/three/d.foo390 one/two/three/directory_foo/",391 );392}393394/// Hidden files (--hidden)
2 unmodified lines
397 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);398399 te.assert_output(400 &["--hidden", "foo"],401 "./.hidden.foo402 ./a.foo403 ./one/b.foo404 ./one/two/c.foo405 ./one/two/C.Foo2406 ./one/two/three/d.foo407 ./one/two/three/directory_foo/",401 ".hidden.foo402 a.foo403 one/b.foo404 one/two/c.foo405 one/two/C.Foo2406 one/two/three/d.foo407 one/two/three/directory_foo/",408 );409}410411/// Hidden file attribute on Windows
13 unmodified lines
425 .attributes(FILE_ATTRIBUTE_HIDDEN)426 .open(te.test_root().join("hidden-file.txt"))427 .unwrap();428429 te.assert_output(&["--hidden", "hidden-file.txt"], "./hidden-file.txt");429 te.assert_output(&["--hidden", "hidden-file.txt"], "hidden-file.txt");430 te.assert_output(&["hidden-file.txt"], "");431}432433/// Ignored files (--no-ignore)
2 unmodified lines
436 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);437438 te.assert_output(439 &["--no-ignore", "foo"],440 "./a.foo441 ./fdignored.foo442 ./gitignored.foo443 ./one/b.foo444 ./one/two/c.foo445 ./one/two/C.Foo2446 ./one/two/three/d.foo447 ./one/two/three/directory_foo/",440 "a.foo441 fdignored.foo442 gitignored.foo443 one/b.foo444 one/two/c.foo445 one/two/C.Foo2446 one/two/three/d.foo447 one/two/three/directory_foo/",448 );449450 te.assert_output(451 &["--hidden", "--no-ignore", "foo"],452 "./.hidden.foo453 ./a.foo454 ./fdignored.foo455 ./gitignored.foo456 ./one/b.foo457 ./one/two/c.foo458 ./one/two/C.Foo2459 ./one/two/three/d.foo460 ./one/two/three/directory_foo/",452 ".hidden.foo453 a.foo454 fdignored.foo455 gitignored.foo456 one/b.foo457 one/two/c.foo458 one/two/C.Foo2459 one/two/three/d.foo460 one/two/three/directory_foo/",461 );462}463464/// .gitignore and .fdignore
16 unmodified lines
481 .unwrap()482 .write_all(b"ignored-by-gitignore\nignored-by-both")483 .unwrap();484485 te.assert_output(&["ignored"], "./ignored-by-nothing");485 te.assert_output(&["ignored"], "ignored-by-nothing");486487 te.assert_output(488 &["--no-ignore-vcs", "ignored"],489 "./ignored-by-nothing490 ./ignored-by-gitignore",489 "ignored-by-nothing490 ignored-by-gitignore",491 );492493 te.assert_output(494 &["--no-ignore", "ignored"],495 "./ignored-by-nothing496 ./ignored-by-fdignore497 ./ignored-by-gitignore498 ./ignored-by-both",495 "ignored-by-nothing496 ignored-by-fdignore497 ignored-by-gitignore498 ignored-by-both",499 );500}501502/// Ignore parent ignore files (--no-ignore-parent)
17 unmodified lines
520 .unwrap()521 .write_all(b"child-ignored")522 .unwrap();523524 te.assert_output_subdirectory("inner", &[], "./not-ignored");524 te.assert_output_subdirectory("inner", &[], "not-ignored");525526 te.assert_output_subdirectory(527 "inner",528 &["--no-ignore-parent"],529 "./parent-ignored530 ./not-ignored",529 "parent-ignored530 not-ignored",531 );532}533534/// Ignore parent ignore files (--no-ignore-parent) with an inner git repo
23 unmodified lines
558559 te.assert_output_subdirectory(560 "inner",561 &[],562 "./not-ignored563 ./parent-ignored",562 "not-ignored563 parent-ignored",564 );565566 te.assert_output_subdirectory(567 "inner",568 &["--no-ignore-parent"],569 "./not-ignored570 ./parent-ignored",569 "not-ignored570 parent-ignored",571 );572}573574/// Precedence of .fdignore files
14 unmodified lines
589 .unwrap()590 .write_all(b"!foo")591 .unwrap();592593 te.assert_output(&["foo"], "./inner/foo");593 te.assert_output(&["foo"], "inner/foo");594595 te.assert_output(&["--no-ignore-vcs", "foo"], "./inner/foo");595 te.assert_output(&["--no-ignore-vcs", "foo"], "inner/foo");596597 te.assert_output(&["--no-ignore", "foo"], "./inner/foo");597 te.assert_output(&["--no-ignore", "foo"], "inner/foo");598}599600/// VCS ignored files (--no-ignore-vcs)601#[test]
1 unmodified line
603 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);604605 te.assert_output(606 &["--no-ignore-vcs", "foo"],607 "./a.foo608 ./gitignored.foo609 ./one/b.foo610 ./one/two/c.foo611 ./one/two/C.Foo2612 ./one/two/three/d.foo613 ./one/two/three/directory_foo/",607 "a.foo608 gitignored.foo609 one/b.foo610 one/two/c.foo611 one/two/C.Foo2612 one/two/three/d.foo613 one/two/three/directory_foo/",614 );615}616617/// Test that --no-ignore-vcs still respects .fdignored in parent directory
6 unmodified lines
624625 te.assert_output_subdirectory(626 "inner",627 &["--no-ignore-vcs", "foo"],628 "./foo629 ./gitignored.foo",628 "foo629 gitignored.foo",630 );631}632633/// Custom ignore files (--ignore-file)
8 unmodified lines
642 .unwrap();643644 te.assert_output(645 &["--ignore-file", "custom.ignore", "foo"],646 "./a.foo647 ./one/b.foo648 ./one/two/c.foo",646 "a.foo647 one/b.foo648 one/two/c.foo",649 );650}651652/// Ignored files with ripgrep aliases (-u / -uu)
2 unmodified lines
655 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);656657 te.assert_output(658 &["-u", "foo"],659 "./.hidden.foo660 ./a.foo661 ./fdignored.foo662 ./gitignored.foo663 ./one/b.foo664 ./one/two/c.foo665 ./one/two/C.Foo2666 ./one/two/three/d.foo667 ./one/two/three/directory_foo/",659 ".hidden.foo660 a.foo661 fdignored.foo662 gitignored.foo663 one/b.foo664 one/two/c.foo665 one/two/C.Foo2666 one/two/three/d.foo667 one/two/three/directory_foo/",668 );669}670671/// Symlinks (--follow)
2 unmodified lines
674 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);675676 te.assert_output(677 &["--follow", "c.foo"],678 "./one/two/c.foo679 ./one/two/C.Foo2680 ./symlink/c.foo681 ./symlink/C.Foo2",678 "one/two/c.foo679 one/two/C.Foo2680 symlink/c.foo681 symlink/C.Foo2",682 );683}684685// File system boundaries (--one-file-system)
46 unmodified lines
732 .expect("Failed to create broken symlink.");733734 te.assert_output(735 &["symlink"],736 "./broken_symlink737 ./symlink",736 "broken_symlink737 symlink",738 );739 te.assert_output(740 &["--type", "symlink", "symlink"],741 "./broken_symlink742 ./symlink",741 "broken_symlink742 symlink",743 );744745 te.assert_output(&["--type", "file", "symlink"], "");746747 te.assert_output(748 &["--follow", "--type", "symlink", "symlink"],749 "./broken_symlink",749 "broken_symlink",750 );751 te.assert_output(&["--follow", "--type", "file", "symlink"], "");752}753
19 unmodified lines
773 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);774775 te.assert_output(776 &["--max-depth", "3"],777 "./a.foo778 ./e1 e2779 ./one/780 ./one/b.foo781 ./one/two/782 ./one/two/c.foo783 ./one/two/C.Foo2784 ./one/two/three/785 ./symlink",777 "a.foo778 e1 e2779 one/780 one/b.foo781 one/two/782 one/two/c.foo783 one/two/C.Foo2784 one/two/three/785 symlink",786 );787788 te.assert_output(789 &["--max-depth", "2"],790 "./a.foo791 ./e1 e2792 ./one/793 ./one/b.foo794 ./one/two/795 ./symlink",790 "a.foo791 e1 e2792 one/793 one/b.foo794 one/two/795 symlink",796 );797798 te.assert_output(799 &["--max-depth", "1"],800 "./a.foo801 ./e1 e2802 ./one/803 ./symlink",800 "a.foo801 e1 e2802 one/803 symlink",804 );805}806807/// Minimum depth (--min-depth)
2 unmodified lines
810 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);811812 te.assert_output(813 &["--min-depth", "3"],814 "./one/two/c.foo815 ./one/two/C.Foo2816 ./one/two/three/817 ./one/two/three/d.foo818 ./one/two/three/directory_foo/",814 "one/two/c.foo815 one/two/C.Foo2816 one/two/three/817 one/two/three/d.foo818 one/two/three/directory_foo/",819 );820821 te.assert_output(822 &["--min-depth", "4"],823 "./one/two/three/d.foo824 ./one/two/three/directory_foo/",823 "one/two/three/d.foo824 one/two/three/directory_foo/",825 );826}827828/// Exact depth (--exact-depth)
2 unmodified lines
831 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);832833 te.assert_output(834 &["--exact-depth", "3"],835 "./one/two/c.foo836 ./one/two/C.Foo2837 ./one/two/three/",835 "one/two/c.foo836 one/two/C.Foo2837 one/two/three/",838 );839}840841/// Pruning (--prune)842#[test]843fn test_prune() {844 let dirs = &["foo/bar", "bar/foo", "baz"];845 let files = &[846 "./foo/foo.file",847 "./foo/bar/foo.file",848 "./bar/foo.file",849 "./bar/foo/foo.file",850 "./baz/foo.file",846 "foo/foo.file",847 "foo/bar/foo.file",848 "bar/foo.file",849 "bar/foo/foo.file",850 "baz/foo.file",851 ];852853 let te = TestEnv::new(dirs, files);854855 te.assert_output(856 &["foo"],857 "./foo/858 ./foo/foo.file859 ./foo/bar/foo.file860 ./bar/foo.file861 ./bar/foo/862 ./bar/foo/foo.file863 ./baz/foo.file",857 "foo/858 foo/foo.file859 foo/bar/foo.file860 bar/foo.file861 bar/foo/862 bar/foo/foo.file863 baz/foo.file",864 );865866 te.assert_output(867 &["--prune", "foo"],868 "./foo/869 ./bar/foo/870 ./bar/foo.file871 ./baz/foo.file",868 "foo/869 bar/foo/870 bar/foo.file871 baz/foo.file",872 );873}874875/// Absolute paths (--absolute-path)
78 unmodified lines
954 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);955956 te.assert_output(957 &["--type", "f"],958 "./a.foo959 ./e1 e2960 ./one/b.foo961 ./one/two/c.foo962 ./one/two/C.Foo2963 ./one/two/three/d.foo",958 "a.foo959 e1 e2960 one/b.foo961 one/two/c.foo962 one/two/C.Foo2963 one/two/three/d.foo",964 );965966 te.assert_output(&["--type", "f", "e1"], "./e1 e2");966 te.assert_output(&["--type", "f", "e1"], "e1 e2");967968 te.assert_output(969 &["--type", "d"],970 "./one/971 ./one/two/972 ./one/two/three/973 ./one/two/three/directory_foo/",970 "one/971 one/two/972 one/two/three/973 one/two/three/directory_foo/",974 );975976 te.assert_output(977 &["--type", "d", "--type", "l"],978 "./one/979 ./one/two/980 ./one/two/three/981 ./one/two/three/directory_foo/982 ./symlink",978 "one/979 one/two/980 one/two/three/981 one/two/three/directory_foo/982 symlink",983 );984985 te.assert_output(&["--type", "l"], "./symlink");985 te.assert_output(&["--type", "l"], "symlink");986}987988/// Test `--type executable`989#[cfg(unix)]
9 unmodified lines
999 .mode(0o777)1000 .open(te.test_root().join("executable-file.sh"))1001 .unwrap();10021003 te.assert_output(&["--type", "executable"], "./executable-file.sh");1003 te.assert_output(&["--type", "executable"], "executable-file.sh");10041005 te.assert_output(1006 &["--type", "executable", "--type", "directory"],1007 "./executable-file.sh1008 ./one/1009 ./one/two/1010 ./one/two/three/1011 ./one/two/three/directory_foo/",1007 "executable-file.sh1008 one/1009 one/two/1010 one/two/three/1011 one/two/three/directory_foo/",1012 );1013}10141015/// Test `--type empty`
7 unmodified lines
1023 create_file_with_size(te.test_root().join("dir_nonempty").join("2_bytes.foo"), 2);10241025 te.assert_output(1026 &["--type", "empty"],1027 "./0_bytes.foo1028 ./dir_empty/",1027 "0_bytes.foo1028 dir_empty/",1029 );10301031 te.assert_output(1032 &["--type", "empty", "--type", "file", "--type", "directory"],1033 "./0_bytes.foo1034 ./dir_empty/",1033 "0_bytes.foo1034 dir_empty/",1035 );10361037 te.assert_output(&["--type", "empty", "--type", "file"], "./0_bytes.foo");1037 te.assert_output(&["--type", "empty", "--type", "file"], "0_bytes.foo");10381039 te.assert_output(&["--type", "empty", "--type", "directory"], "./dir_empty/");1039 te.assert_output(&["--type", "empty", "--type", "directory"], "dir_empty/");1040}10411042/// File extension (--extension)1043#[test]
1 unmodified line
1045 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);10461047 te.assert_output(1048 &["--extension", "foo"],1049 "./a.foo1050 ./one/b.foo1051 ./one/two/c.foo1052 ./one/two/three/d.foo",1049 "a.foo1050 one/b.foo1051 one/two/c.foo1052 one/two/three/d.foo",1053 );10541055 te.assert_output(1056 &["--extension", ".foo"],1057 "./a.foo1058 ./one/b.foo1059 ./one/two/c.foo1060 ./one/two/three/d.foo",1057 "a.foo1058 one/b.foo1059 one/two/c.foo1060 one/two/three/d.foo",1061 );10621063 te.assert_output(1064 &["--extension", ".foo", "--extension", "foo2"],1065 "./a.foo1066 ./one/b.foo1067 ./one/two/c.foo1068 ./one/two/three/d.foo1069 ./one/two/C.Foo2",1065 "a.foo1066 one/b.foo1067 one/two/c.foo1068 one/two/three/d.foo1069 one/two/C.Foo2",1070 );10711072 te.assert_output(&["--extension", ".foo", "a"], "./a.foo");1072 te.assert_output(&["--extension", ".foo", "a"], "a.foo");10731074 te.assert_output(&["--extension", "foo2"], "./one/two/C.Foo2");1074 te.assert_output(&["--extension", "foo2"], "one/two/C.Foo2");10751076 let te2 = TestEnv::new(&[], &["spam.bar.baz", "egg.bar.baz", "yolk.bar.baz.sig"]);10771078 te2.assert_output(1079 &["--extension", ".bar.baz"],1080 "./spam.bar.baz1081 ./egg.bar.baz",1080 "spam.bar.baz1081 egg.bar.baz",1082 );10831084 te2.assert_output(&["--extension", "sig"], "./yolk.bar.baz.sig");1084 te2.assert_output(&["--extension", "sig"], "yolk.bar.baz.sig");10851086 te2.assert_output(&["--extension", "bar.baz.sig"], "./yolk.bar.baz.sig");1086 te2.assert_output(&["--extension", "bar.baz.sig"], "yolk.bar.baz.sig");10871088 let te3 = TestEnv::new(&[], &["latin1.e\u{301}xt", "smiley.☻"]);10891090 te3.assert_output(&["--extension", "☻"], "./smiley.☻");1090 te3.assert_output(&["--extension", "☻"], "smiley.☻");10911092 te3.assert_output(&["--extension", ".e\u{301}xt"], "./latin1.e\u{301}xt");1092 te3.assert_output(&["--extension", ".e\u{301}xt"], "latin1.e\u{301}xt");10931094 let te4 = TestEnv::new(&[], &[".hidden", "test.hidden"]);10951096 te4.assert_output(&["--hidden", "--extension", ".hidden"], "./test.hidden");1096 te4.assert_output(&["--hidden", "--extension", ".hidden"], "test.hidden");1097}10981099/// No file extension (test for the pattern provided in the --help text)1100#[test]
4 unmodified lines
1105 );11061107 te.assert_output(1108 &["^[^.]+$"],1109 "./aa1110 ./one/1111 ./one/bb1112 ./one/two/1113 ./one/two/three/1114 ./one/two/three/d1115 ./one/two/three/directory_foo/1116 ./symlink",1109 "aa1110 one/1111 one/bb1112 one/two/1113 one/two/three/1114 one/two/three/d1115 one/two/three/directory_foo/1116 symlink",1117 );11181119 te.assert_output(1120 &["^[^.]+$", "--type", "file"],1121 "./aa1122 ./one/bb1123 ./one/two/three/d",1121 "aa1122 one/bb1123 one/two/three/d",1124 );1125}11261127/// Symlink as search directory
126 unmodified lines
1254 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);12551256 te.assert_output(1257 &["--exclude", "*.foo"],1258 "./one/1259 ./one/two/1260 ./one/two/C.Foo21261 ./one/two/three/1262 ./one/two/three/directory_foo/1263 ./e1 e21264 ./symlink",1258 "one/1259 one/two/1260 one/two/C.Foo21261 one/two/three/1262 one/two/three/directory_foo/1263 e1 e21264 symlink",1265 );12661267 te.assert_output(1268 &["--exclude", "*.foo", "--exclude", "*.Foo2"],1269 "./one/1270 ./one/two/1271 ./one/two/three/1272 ./one/two/three/directory_foo/1273 ./e1 e21274 ./symlink",1269 "one/1270 one/two/1271 one/two/three/1272 one/two/three/directory_foo/1273 e1 e21274 symlink",1275 );12761277 te.assert_output(1278 &["--exclude", "*.foo", "--exclude", "*.Foo2", "foo"],1279 "./one/two/three/directory_foo/",1279 "one/two/three/directory_foo/",1280 );12811282 te.assert_output(1283 &["--exclude", "one/two/", "foo"],1284 "./a.foo1285 ./one/b.foo",1284 "a.foo1285 one/b.foo",1286 );12871288 te.assert_output(1289 &["--exclude", "one/**/*.foo"],1290 "./a.foo1291 ./e1 e21292 ./one/1293 ./one/two/1294 ./one/two/C.Foo21295 ./one/two/three/1296 ./one/two/three/directory_foo/1297 ./symlink",1290 "a.foo1291 e1 e21292 one/1293 one/two/1294 one/two/C.Foo21295 one/two/three/1296 one/two/three/directory_foo/1297 symlink",1298 );1299}13001301/// Shell script execution (--exec)
374 unmodified lines
16761677 // Regex search, dot is treated as "any character"1678 te.assert_output(1679 &["a.foo"],1680 "./test1/a.foo1681 ./test1/a_foo",1680 "test1/a.foo1681 test1/a_foo",1682 );16831684 // Literal search, dot is treated as character1685 te.assert_output(&["--fixed-strings", "a.foo"], "./test1/a.foo");1685 te.assert_output(&["--fixed-strings", "a.foo"], "test1/a.foo");16861687 // Regex search, parens are treated as group1688 te.assert_output(&["download (1)"], "");16891690 // Literal search, parens are treated as characters1691 te.assert_output(1692 &["--fixed-strings", "download (1)"],1693 "./test2/Download (1).tar.gz",1693 "test2/Download (1).tar.gz",1694 );16951696 // Combine with --case-sensitive1697 te.assert_output(&["--fixed-strings", "--case-sensitive", "download (1)"], "");
37 unmodified lines
17351736 // Zero and non-zero sized files.1737 te.assert_output(1738 &["", "--size", "+0B"],1739 "./0_bytes.foo1740 ./11_bytes.foo1741 ./30_bytes.foo1742 ./3_kilobytes.foo1743 ./4_kibibytes.foo",1739 "0_bytes.foo1740 11_bytes.foo1741 30_bytes.foo1742 3_kilobytes.foo1743 4_kibibytes.foo",1744 );17451746 // Zero sized files.1747 te.assert_output(&["", "--size", "-0B"], "./0_bytes.foo");1748 te.assert_output(&["", "--size", "0B"], "./0_bytes.foo");1749 te.assert_output(&["", "--size=0B"], "./0_bytes.foo");1750 te.assert_output(&["", "-S", "0B"], "./0_bytes.foo");1747 te.assert_output(&["", "--size", "-0B"], "0_bytes.foo");1748 te.assert_output(&["", "--size", "0B"], "0_bytes.foo");1749 te.assert_output(&["", "--size=0B"], "0_bytes.foo");1750 te.assert_output(&["", "-S", "0B"], "0_bytes.foo");17511752 // Files with 2 bytes or more.1753 te.assert_output(1754 &["", "--size", "+2B"],1755 "./11_bytes.foo1756 ./30_bytes.foo1757 ./3_kilobytes.foo1758 ./4_kibibytes.foo",1755 "11_bytes.foo1756 30_bytes.foo1757 3_kilobytes.foo1758 4_kibibytes.foo",1759 );17601761 // Files with 2 bytes or less.1762 te.assert_output(&["", "--size", "-2B"], "./0_bytes.foo");1762 te.assert_output(&["", "--size", "-2B"], "0_bytes.foo");17631764 // Files with size between 1 byte and 11 bytes.1765 te.assert_output(&["", "--size", "+1B", "--size", "-11B"], "./11_bytes.foo");1765 te.assert_output(&["", "--size", "+1B", "--size", "-11B"], "11_bytes.foo");17661767 // Files with size equal 11 bytes.1768 te.assert_output(&["", "--size", "11B"], "./11_bytes.foo");1768 te.assert_output(&["", "--size", "11B"], "11_bytes.foo");17691770 // Files with size between 1 byte and 30 bytes.1771 te.assert_output(1772 &["", "--size", "+1B", "--size", "-30B"],1773 "./11_bytes.foo1774 ./30_bytes.foo",1773 "11_bytes.foo1774 30_bytes.foo",1775 );17761777 // Combine with a search pattern1778 te.assert_output(1779 &["^11_", "--size", "+1B", "--size", "-30B"],1780 "./11_bytes.foo",1781 );1778 te.assert_output(&["^11_", "--size", "+1B", "--size", "-30B"], "11_bytes.foo");17791780 // Files with size between 12 and 30 bytes.1784 te.assert_output(&["", "--size", "+12B", "--size", "-30B"], "./30_bytes.foo");1781 te.assert_output(&["", "--size", "+12B", "--size", "-30B"], "30_bytes.foo");17821783 // Files with size between 31 and 100 bytes.1784 te.assert_output(&["", "--size", "+31B", "--size", "-100B"], "");17851786 // Files with size between 3 kibibytes and 5 kibibytes.1790 te.assert_output(1791 &["", "--size", "+3ki", "--size", "-5ki"],1792 "./4_kibibytes.foo",1793 );1787 te.assert_output(&["", "--size", "+3ki", "--size", "-5ki"], "4_kibibytes.foo");17881789 // Files with size between 3 kilobytes and 5 kilobytes.1790 te.assert_output(1791 &["", "--size", "+3k", "--size", "-5k"],1798 "./3_kilobytes.foo1799 ./4_kibibytes.foo",1792 "3_kilobytes.foo1793 4_kibibytes.foo",1794 );17951796 // Files with size greater than 3 kilobytes and less than 3 kibibytes.1803 te.assert_output(1804 &["", "--size", "+3k", "--size", "-3ki"],1805 "./3_kilobytes.foo",1806 );1797 te.assert_output(&["", "--size", "+3k", "--size", "-3ki"], "3_kilobytes.foo");17981799 // Files with size equal 4 kibibytes.1809 te.assert_output(1810 &["", "--size", "+4ki", "--size", "-4ki"],1811 "./4_kibibytes.foo",1812 );1813 te.assert_output(&["", "--size", "4ki"], "./4_kibibytes.foo");1800 te.assert_output(&["", "--size", "+4ki", "--size", "-4ki"], "4_kibibytes.foo");1801 te.assert_output(&["", "--size", "4ki"], "4_kibibytes.foo");1802}18031804#[cfg(test)]1805fn create_file_with_modified<P: AsRef<Path>>(path: P, duration_in_secs: u64) {
27 unmodified lines
1833 create_file_with_modified(te.test_root().join("bar_1_day"), 24 * 60 * 60);18341835 te.assert_output(1836 &["", "--changed-within", "15min"],1849 "./foo_0_now1850 ./bar_1_min1851 ./foo_10_min",1837 "foo_0_now1838 bar_1_min1839 foo_10_min",1840 );18411842 te.assert_output(1843 &["", "--change-older-than", "15min"],1856 "./bar_1_h1857 ./foo_2_h1858 ./bar_1_day",1844 "bar_1_h1845 foo_2_h1846 bar_1_day",1847 );18481849 te.assert_output(1850 &["foo", "--changed-within", "12h"],1863 "./foo_0_now1864 ./foo_10_min1865 ./foo_2_h",1851 "foo_0_now1852 foo_10_min1853 foo_2_h",1854 );1855}18561857#[cfg(test)]
11 unmodified lines
1869 change_file_modified(te.test_root().join("30dec2017"), "2017-12-30T23:59:00Z");18701871 te.assert_output(1872 &["", "--change-newer-than", "2018-01-01 00:00:00"],1885 "./15mar2018",1873 "15mar2018",1874 );1875 te.assert_output(1876 &["", "--changed-before", "2018-01-01 00:00:00"],1889 "./30dec2017",1877 "30dec2017",1878 );1879}18801881#[test]
15 unmodified lines
1897 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);18981899 te.assert_output(1900 &["--base-directory", "one"],1913 "./b.foo1914 ./two/1915 ./two/c.foo1916 ./two/C.Foo21917 ./two/three/1918 ./two/three/d.foo1919 ./two/three/directory_foo/",1901 "b.foo1902 two/1903 two/c.foo1904 two/C.Foo21905 two/three/1906 two/three/d.foo1907 two/three/directory_foo/",1908 );19091910 te.assert_output(1911 &["--base-directory", "one/two/", "foo"],1924 "./c.foo1925 ./C.Foo21926 ./three/d.foo1927 ./three/directory_foo/",1912 "c.foo1913 C.Foo21914 three/d.foo1915 three/directory_foo/",1916 );19171918 // Explicit root path1919 te.assert_output(
27 unmodified lines
19471948 // Unrestricted1949 te.assert_output(1950 &["--max-results=0", "c.foo"],1963 "./one/two/C.Foo21964 ./one/two/c.foo",1951 "one/two/C.Foo21952 one/two/c.foo",1953 );19541955 // Limited to two results1956 te.assert_output(1957 &["--max-results=2", "c.foo"],1970 "./one/two/C.Foo21971 ./one/two/c.foo",1958 "one/two/C.Foo21959 one/two/c.foo",1960 );19611962 // Limited to one result. We could find either C.Foo2 or c.foo1963 let assert_just_one_result_with_option = |option| {1964 let output = te.assert_success_and_get_output(".", &[option, "c.foo"]);1965 let stdout = String::from_utf8_lossy(&output.stdout)1966 .trim()1967 .replace(&std::path::MAIN_SEPARATOR.to_string(), "/");1980 assert!(stdout == "./one/two/C.Foo2" || stdout == "./one/two/c.foo");1968 assert!(stdout == "one/two/C.Foo2" || stdout == "one/two/c.foo");1969 };1970 assert_just_one_result_with_option("--max-results=1");1971 assert_just_one_result_with_option("-1");1972}
104 unmodified lines
20772078 te.assert_failure(&["^\\.gitignore"]);2079 te.assert_failure(&["--glob", ".gitignore"]);20802093 te.assert_output(&["--hidden", "^\\.gitignore"], "./.gitignore");2094 te.assert_output(&["--hidden", "--glob", ".gitignore"], "./.gitignore");2081 te.assert_output(&["--hidden", "^\\.gitignore"], ".gitignore");2082 te.assert_output(&["--hidden", "--glob", ".gitignore"], ".gitignore");2083 te.assert_output(&[".gitignore"], "");2084}20852086#[test]
41 unmodified lines