Skip to content
Myr

Merge pull request #861 from jcaplan/no-strip/760

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

show "./" prefix when search path provided

authored by David Peter · committed by GitHub · parents 0484486, 92bd785 · Browse files · 7 files+425 added−378 removed
This commit

State

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

Diff stats

7 files+425 added−378 removed

  • tests:+403 added−371 removed
  • other:+22 added−7 removed

7 files+425 added−378 removed

modified:src/exec/mod.rs+1 added-4 removed
12 unmodified lines
13use once_cell::sync::Lazy;14use regex::Regex;1516use crate::exit_codes::ExitCode;17use crate::filesystem::strip_current_dir;1718use self::command::execute_command;19use self::input::{basename, dirname, remove_extension};20pub use self::job::{batch, job};
121 unmodified lines
142 input: &Path,143 out_perm: Arc<Mutex<()>>,144 buffer_output: bool,145 ) -> ExitCode {147 let input = strip_current_dir(input);148146 let mut cmd = Command::new(self.args[0].generate(&input, self.path_separator.as_deref()));147 for arg in &self.args[1..] {148 cmd.arg(arg.generate(&input, self.path_separator.as_deref()));149 }
23 unmodified lines
173174 // A single `Tokens` is expected175 // So we can directly consume the iterator once and for all176 for path in &mut paths {180 cmd.arg(arg.generate(strip_current_dir(path), self.path_separator.as_deref()));177 cmd.arg(arg.generate(path, self.path_separator.as_deref()));178 has_path = true;179 }180 } else {181 cmd.arg(arg.generate("", None));
277 unmodified lines
modified:src/app.rs+11 added
702 unmodified lines
703 "Provide paths to search as an alternative to the positional <path> \704 argument. Changes the usage to `fd [FLAGS/OPTIONS] --search-path <path> \705 --search-path <path2> [<pattern>]`",706 ),707 )708 .arg(709 Arg::with_name("strip-cwd-prefix")710 .long("strip-cwd-prefix")711 .conflicts_with_all(&["path", "search-path"])712 .hidden_short_help(true)713 .help("strip './' prefix from non-tty outputs")714 .long_help(715 "By default, relative paths are prefixed with './' when the output goes to a non \716 interactive terminal (TTY). Use this flag to disable this behaviour."717 )718 );719720 if cfg!(unix) {721 app = app.arg(
39 unmodified lines
modified:src/config.rs+3 added
111 unmodified lines
112 pub path_separator: Option<String>,113114 /// The maximum number of search results115 pub max_results: Option<usize>,116117 /// Whether or not to strip the './' prefix for search results118 pub strip_cwd_prefix: bool,119}
modified:src/main.rs+3 added
378 unmodified lines
379 } else {380 None381 }382 }),383 strip_cwd_prefix: (!matches.is_present("path")384 && !matches.is_present("search-path")385 && (interactive_terminal || matches.is_present("strip-cwd-prefix"))),386 })387}388389fn extract_command(
179 unmodified lines
modified:src/output.rs+3 added-3 removed
20 unmodified lines
21 entry: &Path,22 config: &Config,23 wants_to_quit: &Arc<AtomicBool>,24) {25 let path = if entry.is_absolute() {26 entry27 } else {25 let path = if config.strip_cwd_prefix {26 strip_current_dir(entry)27 } else {28 entry29 };3031 let r = if let Some(ref ls_colors) = config.ls_colors {32 print_entry_colorized(stdout, path, config, ls_colors, wants_to_quit)
112 unmodified lines
modified:tests/tests.rs+403 added-371 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 one86 one/b.foo87 one/two88 one/two/c.foo89 one/two/C.Foo290 one/two/three91 one/two/three/d.foo92 one/two/three/directory_foo93 symlink";83 let expected = "./a.foo84 ./e1 e285 ./one86 ./one/b.foo87 ./one/two88 ./one/two/c.foo89 ./one/two/C.Foo290 ./one/two/three91 ./one/two/three/d.foo92 ./one/two/three/directory_foo93 ./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/// Custom ignore files (--ignore-file)
8 unmodified lines
626 .unwrap();627628 te.assert_output(629 &["--ignore-file", "custom.ignore", "foo"],630 "a.foo631 one/b.foo632 one/two/c.foo",630 "./a.foo631 ./one/b.foo632 ./one/two/c.foo",633 );634}635636/// Ignored files with ripgrep aliases (-u / -uu)
2 unmodified lines
639 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);640641 te.assert_output(642 &["-u", "foo"],643 "a.foo644 fdignored.foo645 gitignored.foo646 one/b.foo647 one/two/c.foo648 one/two/C.Foo2649 one/two/three/d.foo650 one/two/three/directory_foo",643 "./a.foo644 ./fdignored.foo645 ./gitignored.foo646 ./one/b.foo647 ./one/two/c.foo648 ./one/two/C.Foo2649 ./one/two/three/d.foo650 ./one/two/three/directory_foo",651 );652653 te.assert_output(654 &["-uu", "foo"],655 ".hidden.foo656 a.foo657 fdignored.foo658 gitignored.foo659 one/b.foo660 one/two/c.foo661 one/two/C.Foo2662 one/two/three/d.foo663 one/two/three/directory_foo",655 "./.hidden.foo656 ./a.foo657 ./fdignored.foo658 ./gitignored.foo659 ./one/b.foo660 ./one/two/c.foo661 ./one/two/C.Foo2662 ./one/two/three/d.foo663 ./one/two/three/directory_foo",664 );665}666667/// Symlinks (--follow)
2 unmodified lines
670 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);671672 te.assert_output(673 &["--follow", "c.foo"],674 "one/two/c.foo675 one/two/C.Foo2676 symlink/c.foo677 symlink/C.Foo2",674 "./one/two/c.foo675 ./one/two/C.Foo2676 ./symlink/c.foo677 ./symlink/C.Foo2",678 );679}680681// File system boundaries (--one-file-system)
46 unmodified lines
728 .expect("Failed to create broken symlink.");729730 te.assert_output(731 &["symlink"],732 "broken_symlink733 symlink",732 "./broken_symlink733 ./symlink",734 );735 te.assert_output(736 &["--type", "symlink", "symlink"],737 "broken_symlink738 symlink",737 "./broken_symlink738 ./symlink",739 );740741 te.assert_output(&["--type", "file", "symlink"], "");742743 te.assert_output(744 &["--follow", "--type", "symlink", "symlink"],745 "broken_symlink",745 "./broken_symlink",746 );747 te.assert_output(&["--follow", "--type", "file", "symlink"], "");748}749
3 unmodified lines
753 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);754755 te.assert_output(756 &["--print0", "foo"],757 "a.fooNULL758 one/b.fooNULL759 one/two/C.Foo2NULL760 one/two/c.fooNULL761 one/two/three/d.fooNULL762 one/two/three/directory_fooNULL",757 "./a.fooNULL758 ./one/b.fooNULL759 ./one/two/C.Foo2NULL760 ./one/two/c.fooNULL761 ./one/two/three/d.fooNULL762 ./one/two/three/directory_fooNULL",763 );764}765766/// Maximum depth (--max-depth)
2 unmodified lines
769 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);770771 te.assert_output(772 &["--max-depth", "3"],773 "a.foo774 e1 e2775 one776 one/b.foo777 one/two778 one/two/c.foo779 one/two/C.Foo2780 one/two/three781 symlink",773 "./a.foo774 ./e1 e2775 ./one776 ./one/b.foo777 ./one/two778 ./one/two/c.foo779 ./one/two/C.Foo2780 ./one/two/three781 ./symlink",782 );783784 te.assert_output(785 &["--max-depth", "2"],786 "a.foo787 e1 e2788 one789 one/b.foo790 one/two791 symlink",786 "./a.foo787 ./e1 e2788 ./one789 ./one/b.foo790 ./one/two791 ./symlink",792 );793794 te.assert_output(795 &["--max-depth", "1"],796 "a.foo797 e1 e2798 one799 symlink",796 "./a.foo797 ./e1 e2798 ./one799 ./symlink",800 );801}802803/// Minimum depth (--min-depth)
2 unmodified lines
806 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);807808 te.assert_output(809 &["--min-depth", "3"],810 "one/two/c.foo811 one/two/C.Foo2812 one/two/three813 one/two/three/d.foo814 one/two/three/directory_foo",810 "./one/two/c.foo811 ./one/two/C.Foo2812 ./one/two/three813 ./one/two/three/d.foo814 ./one/two/three/directory_foo",815 );816817 te.assert_output(818 &["--min-depth", "4"],819 "one/two/three/d.foo820 one/two/three/directory_foo",819 "./one/two/three/d.foo820 ./one/two/three/directory_foo",821 );822}823824/// Exact depth (--exact-depth)
2 unmodified lines
827 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);828829 te.assert_output(830 &["--exact-depth", "3"],831 "one/two/c.foo832 one/two/C.Foo2833 one/two/three",831 "./one/two/c.foo832 ./one/two/C.Foo2833 ./one/two/three",834 );835}836837/// Pruning (--prune)838#[test]839fn test_prune() {840 let dirs = &["foo/bar", "bar/foo", "baz"];841 let files = &[842 "foo/foo.file",843 "foo/bar/foo.file",844 "bar/foo.file",845 "bar/foo/foo.file",846 "baz/foo.file",842 "./foo/foo.file",843 "./foo/bar/foo.file",844 "./bar/foo.file",845 "./bar/foo/foo.file",846 "./baz/foo.file",847 ];848849 let te = TestEnv::new(dirs, files);850851 te.assert_output(852 &["foo"],853 "foo854 foo/foo.file855 foo/bar/foo.file856 bar/foo.file857 bar/foo858 bar/foo/foo.file859 baz/foo.file",853 "./foo854 ./foo/foo.file855 ./foo/bar/foo.file856 ./bar/foo.file857 ./bar/foo858 ./bar/foo/foo.file859 ./baz/foo.file",860 );861862 te.assert_output(863 &["--prune", "foo"],864 "foo865 bar/foo866 bar/foo.file867 baz/foo.file",864 "./foo865 ./bar/foo866 ./bar/foo.file867 ./baz/foo.file",868 );869}870871/// Absolute paths (--absolute-path)
78 unmodified lines
950 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);951952 te.assert_output(953 &["--type", "f"],954 "a.foo955 e1 e2956 one/b.foo957 one/two/c.foo958 one/two/C.Foo2959 one/two/three/d.foo",954 "./a.foo955 ./e1 e2956 ./one/b.foo957 ./one/two/c.foo958 ./one/two/C.Foo2959 ./one/two/three/d.foo",960 );961962 te.assert_output(&["--type", "f", "e1"], "e1 e2");962 te.assert_output(&["--type", "f", "e1"], "./e1 e2");963964 te.assert_output(965 &["--type", "d"],966 "one967 one/two968 one/two/three969 one/two/three/directory_foo",966 "./one967 ./one/two968 ./one/two/three969 ./one/two/three/directory_foo",970 );971972 te.assert_output(973 &["--type", "d", "--type", "l"],974 "one975 one/two976 one/two/three977 one/two/three/directory_foo978 symlink",974 "./one975 ./one/two976 ./one/two/three977 ./one/two/three/directory_foo978 ./symlink",979 );980981 te.assert_output(&["--type", "l"], "symlink");981 te.assert_output(&["--type", "l"], "./symlink");982}983984/// Test `--type executable`985#[cfg(unix)]
9 unmodified lines
995 .mode(0o777)996 .open(te.test_root().join("executable-file.sh"))997 .unwrap();998999 te.assert_output(&["--type", "executable"], "executable-file.sh");999 te.assert_output(&["--type", "executable"], "./executable-file.sh");10001001 te.assert_output(1002 &["--type", "executable", "--type", "directory"],1003 "executable-file.sh1004 one1005 one/two1006 one/two/three1007 one/two/three/directory_foo",1003 "./executable-file.sh1004 ./one1005 ./one/two1006 ./one/two/three1007 ./one/two/three/directory_foo",1008 );1009}10101011/// Test `--type empty`
7 unmodified lines
1019 create_file_with_size(te.test_root().join("dir_nonempty").join("2_bytes.foo"), 2);10201021 te.assert_output(1022 &["--type", "empty"],1023 "0_bytes.foo1024 dir_empty",1023 "./0_bytes.foo1024 ./dir_empty",1025 );10261027 te.assert_output(1028 &["--type", "empty", "--type", "file", "--type", "directory"],1029 "0_bytes.foo1030 dir_empty",1029 "./0_bytes.foo1030 ./dir_empty",1031 );10321033 te.assert_output(&["--type", "empty", "--type", "file"], "0_bytes.foo");1033 te.assert_output(&["--type", "empty", "--type", "file"], "./0_bytes.foo");10341035 te.assert_output(&["--type", "empty", "--type", "directory"], "dir_empty");1035 te.assert_output(&["--type", "empty", "--type", "directory"], "./dir_empty");1036}10371038/// File extension (--extension)1039#[test]
1 unmodified line
1041 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);10421043 te.assert_output(1044 &["--extension", "foo"],1045 "a.foo1046 one/b.foo1047 one/two/c.foo1048 one/two/three/d.foo",1045 "./a.foo1046 ./one/b.foo1047 ./one/two/c.foo1048 ./one/two/three/d.foo",1049 );10501051 te.assert_output(1052 &["--extension", ".foo"],1053 "a.foo1054 one/b.foo1055 one/two/c.foo1056 one/two/three/d.foo",1053 "./a.foo1054 ./one/b.foo1055 ./one/two/c.foo1056 ./one/two/three/d.foo",1057 );10581059 te.assert_output(1060 &["--extension", ".foo", "--extension", "foo2"],1061 "a.foo1062 one/b.foo1063 one/two/c.foo1064 one/two/three/d.foo1065 one/two/C.Foo2",1061 "./a.foo1062 ./one/b.foo1063 ./one/two/c.foo1064 ./one/two/three/d.foo1065 ./one/two/C.Foo2",1066 );10671068 te.assert_output(&["--extension", ".foo", "a"], "a.foo");1068 te.assert_output(&["--extension", ".foo", "a"], "./a.foo");10691070 te.assert_output(&["--extension", "foo2"], "one/two/C.Foo2");1070 te.assert_output(&["--extension", "foo2"], "./one/two/C.Foo2");10711072 let te2 = TestEnv::new(&[], &["spam.bar.baz", "egg.bar.baz", "yolk.bar.baz.sig"]);10731074 te2.assert_output(1075 &["--extension", ".bar.baz"],1076 "spam.bar.baz1077 egg.bar.baz",1076 "./spam.bar.baz1077 ./egg.bar.baz",1078 );10791080 te2.assert_output(&["--extension", "sig"], "yolk.bar.baz.sig");1080 te2.assert_output(&["--extension", "sig"], "./yolk.bar.baz.sig");10811082 te2.assert_output(&["--extension", "bar.baz.sig"], "yolk.bar.baz.sig");1082 te2.assert_output(&["--extension", "bar.baz.sig"], "./yolk.bar.baz.sig");10831084 let te3 = TestEnv::new(&[], &["latin1.e\u{301}xt", "smiley.☻"]);10851086 te3.assert_output(&["--extension", "☻"], "smiley.☻");1086 te3.assert_output(&["--extension", "☻"], "./smiley.☻");10871088 te3.assert_output(&["--extension", ".e\u{301}xt"], "latin1.e\u{301}xt");1088 te3.assert_output(&["--extension", ".e\u{301}xt"], "./latin1.e\u{301}xt");10891090 let te4 = TestEnv::new(&[], &[".hidden", "test.hidden"]);10911092 te4.assert_output(&["--hidden", "--extension", ".hidden"], "test.hidden");1092 te4.assert_output(&["--hidden", "--extension", ".hidden"], "./test.hidden");1093}10941095/// No file extension (test for the pattern provided in the --help text)1096#[test]
4 unmodified lines
1101 );11021103 te.assert_output(1104 &["^[^.]+$"],1105 "aa1106 one1107 one/bb1108 one/two1109 one/two/three1110 one/two/three/d1111 one/two/three/directory_foo1112 symlink",1105 "./aa1106 ./one1107 ./one/bb1108 ./one/two1109 ./one/two/three1110 ./one/two/three/d1111 ./one/two/three/directory_foo1112 ./symlink",1113 );11141115 te.assert_output(1116 &["^[^.]+$", "--type", "file"],1117 "aa1118 one/bb1119 one/two/three/d",1117 "./aa1118 ./one/bb1119 ./one/two/three/d",1120 );1121}11221123/// Symlink as search directory
126 unmodified lines
1250 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);12511252 te.assert_output(1253 &["--exclude", "*.foo"],1254 "one1255 one/two1256 one/two/C.Foo21257 one/two/three1258 one/two/three/directory_foo1259 e1 e21260 symlink",1254 "./one1255 ./one/two1256 ./one/two/C.Foo21257 ./one/two/three1258 ./one/two/three/directory_foo1259 ./e1 e21260 ./symlink",1261 );12621263 te.assert_output(1264 &["--exclude", "*.foo", "--exclude", "*.Foo2"],1265 "one1266 one/two1267 one/two/three1268 one/two/three/directory_foo1269 e1 e21270 symlink",1265 "./one1266 ./one/two1267 ./one/two/three1268 ./one/two/three/directory_foo1269 ./e1 e21270 ./symlink",1271 );12721273 te.assert_output(1274 &["--exclude", "*.foo", "--exclude", "*.Foo2", "foo"],1275 "one/two/three/directory_foo",1275 "./one/two/three/directory_foo",1276 );12771278 te.assert_output(1279 &["--exclude", "one/two", "foo"],1280 "a.foo1281 one/b.foo",1280 "./a.foo1281 ./one/b.foo",1282 );12831284 te.assert_output(1285 &["--exclude", "one/**/*.foo"],1286 "a.foo1287 e1 e21288 one1289 one/two1290 one/two/C.Foo21291 one/two/three1292 one/two/three/directory_foo1293 symlink",1286 "./a.foo1287 ./e1 e21288 ./one1289 ./one/two1290 ./one/two/C.Foo21291 ./one/two/three1292 ./one/two/three/directory_foo1293 ./symlink",1294 );1295}12961297/// Shell script execution (--exec)
16 unmodified lines
1314 );13151316 te.assert_output(1317 &["foo", "--exec", "echo", "{}"],1318 "a.foo1319 one/b.foo1320 one/two/C.Foo21321 one/two/c.foo1322 one/two/three/d.foo1323 one/two/three/directory_foo",1318 "./a.foo1319 ./one/b.foo1320 ./one/two/C.Foo21321 ./one/two/c.foo1322 ./one/two/three/d.foo1323 ./one/two/three/directory_foo",1324 );13251326 te.assert_output(1327 &["foo", "--exec", "echo", "{.}"],
27 unmodified lines
13551356 te.assert_output(1357 &["foo", "--exec", "echo", "{//}"],1358 ".1359 one1360 one/two1361 one/two1362 one/two/three1363 one/two/three",1359 ./one1360 ./one/two1361 ./one/two1362 ./one/two/three1363 ./one/two/three",1364 );13651366 te.assert_output(&["e1", "--exec", "printf", "%s.%s\n"], "e1 e2.");1366 te.assert_output(&["e1", "--exec", "printf", "%s.%s\n"], "./e1 e2.");1367 }1368}13691370#[test]
12 unmodified lines
1383 );13841385 te.assert_output(1386 &["foo", "--exec-batch", "echo", "{}"],1387 "a.foo one/b.foo one/two/C.Foo2 one/two/c.foo one/two/three/d.foo one/two/three/directory_foo",1387 "./a.foo ./one/b.foo ./one/two/C.Foo2 ./one/two/c.foo ./one/two/three/d.foo ./one/two/three/directory_foo",1388 );13891390 te.assert_output(1391 &["foo", "--exec-batch", "echo", "{/}"],
37 unmodified lines
1429 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);14301431 te.assert_output(1432 &["foo", "--batch-size", "0", "--exec-batch", "echo", "{}"],1433 "a.foo one/b.foo one/two/C.Foo2 one/two/c.foo one/two/three/d.foo one/two/three/directory_foo",1433 "./a.foo ./one/b.foo ./one/two/C.Foo2 ./one/two/c.foo ./one/two/three/d.foo ./one/two/three/directory_foo",1434 );14351436 let output = te.assert_success_and_get_output(1437 ".",
12 unmodified lines
1450 paths.sort_unstable();1451 assert_eq!(1452 &paths,1453 &[1454 "a.foo",1455 "one/b.foo",1456 "one/two/C.Foo2",1457 "one/two/c.foo",1458 "one/two/three/d.foo",1459 "one/two/three/directory_foo"1454 "./a.foo",1455 "./one/b.foo",1456 "./one/two/C.Foo2",1457 "./one/two/c.foo",1458 "./one/two/three/d.foo",1459 "./one/two/three/directory_foo"1460 ],1461 );1462}1463
21 unmodified lines
1485 );14861487 te.assert_output(1488 &["--path-separator=#", "foo", "--exec", "echo", "{}"],1489 "a.foo1490 one#b.foo1491 one#two#C.Foo21492 one#two#c.foo1493 one#two#three#d.foo1494 one#two#three#directory_foo",1489 ".#a.foo1490 .#one#b.foo1491 .#one#two#C.Foo21492 .#one#two#c.foo1493 .#one#two#three#d.foo1494 .#one#two#three#directory_foo",1495 );14961497 te.assert_output(1498 &["--path-separator=#", "foo", "--exec", "echo", "{.}"],
27 unmodified lines
15261527 te.assert_output(1528 &["--path-separator=#", "foo", "--exec", "echo", "{//}"],1529 ".1530 one1531 one#two1532 one#two1533 one#two#three1534 one#two#three",1530 .#one1531 .#one#two1532 .#one#two1533 .#one#two#three1534 .#one#two#three",1535 );15361537 te.assert_output(1538 &["--path-separator=#", "e1", "--exec", "printf", "%s.%s\n"],1539 "e1 e2.",1539 ".#e1 e2.",1540 );1541}15421543/// Non-zero exit code (--quiet)
18 unmodified lines
15621563 // Regex search, dot is treated as "any character"1564 te.assert_output(1565 &["a.foo"],1566 "test1/a.foo1567 test1/a_foo",1566 "./test1/a.foo1567 ./test1/a_foo",1568 );15691570 // Literal search, dot is treated as character1571 te.assert_output(&["--fixed-strings", "a.foo"], "test1/a.foo");1571 te.assert_output(&["--fixed-strings", "a.foo"], "./test1/a.foo");15721573 // Regex search, parens are treated as group1574 te.assert_output(&["download (1)"], "");15751576 // Literal search, parens are treated as characters1577 te.assert_output(1578 &["--fixed-strings", "download (1)"],1579 "test2/Download (1).tar.gz",1579 "./test2/Download (1).tar.gz",1580 );15811582 // Combine with --case-sensitive1583 te.assert_output(&["--fixed-strings", "--case-sensitive", "download (1)"], "");
37 unmodified lines
16211622 // Zero and non-zero sized files.1623 te.assert_output(1624 &["", "--size", "+0B"],1625 "0_bytes.foo1626 11_bytes.foo1627 30_bytes.foo1628 3_kilobytes.foo1629 4_kibibytes.foo",1625 "./0_bytes.foo1626 ./11_bytes.foo1627 ./30_bytes.foo1628 ./3_kilobytes.foo1629 ./4_kibibytes.foo",1630 );16311632 // Zero sized files.1633 te.assert_output(&["", "--size", "-0B"], "0_bytes.foo");1634 te.assert_output(&["", "--size", "0B"], "0_bytes.foo");1635 te.assert_output(&["", "--size=0B"], "0_bytes.foo");1636 te.assert_output(&["", "-S", "0B"], "0_bytes.foo");1633 te.assert_output(&["", "--size", "-0B"], "./0_bytes.foo");1634 te.assert_output(&["", "--size", "0B"], "./0_bytes.foo");1635 te.assert_output(&["", "--size=0B"], "./0_bytes.foo");1636 te.assert_output(&["", "-S", "0B"], "./0_bytes.foo");16371638 // Files with 2 bytes or more.1639 te.assert_output(1640 &["", "--size", "+2B"],1641 "11_bytes.foo1642 30_bytes.foo1643 3_kilobytes.foo1644 4_kibibytes.foo",1641 "./11_bytes.foo1642 ./30_bytes.foo1643 ./3_kilobytes.foo1644 ./4_kibibytes.foo",1645 );16461647 // Files with 2 bytes or less.1648 te.assert_output(&["", "--size", "-2B"], "0_bytes.foo");1648 te.assert_output(&["", "--size", "-2B"], "./0_bytes.foo");16491650 // Files with size between 1 byte and 11 bytes.1651 te.assert_output(&["", "--size", "+1B", "--size", "-11B"], "11_bytes.foo");1651 te.assert_output(&["", "--size", "+1B", "--size", "-11B"], "./11_bytes.foo");16521653 // Files with size equal 11 bytes.1654 te.assert_output(&["", "--size", "11B"], "11_bytes.foo");1654 te.assert_output(&["", "--size", "11B"], "./11_bytes.foo");16551656 // Files with size between 1 byte and 30 bytes.1657 te.assert_output(1658 &["", "--size", "+1B", "--size", "-30B"],1659 "11_bytes.foo1660 30_bytes.foo",1659 "./11_bytes.foo1660 ./30_bytes.foo",1661 );16621663 // Combine with a search pattern1664 te.assert_output(&["^11_", "--size", "+1B", "--size", "-30B"], "11_bytes.foo");1664 te.assert_output(1665 &["^11_", "--size", "+1B", "--size", "-30B"],1666 "./11_bytes.foo",1667 );16681669 // Files with size between 12 and 30 bytes.1667 te.assert_output(&["", "--size", "+12B", "--size", "-30B"], "30_bytes.foo");1670 te.assert_output(&["", "--size", "+12B", "--size", "-30B"], "./30_bytes.foo");16711672 // Files with size between 31 and 100 bytes.1673 te.assert_output(&["", "--size", "+31B", "--size", "-100B"], "");16741675 // Files with size between 3 kibibytes and 5 kibibytes.1673 te.assert_output(&["", "--size", "+3ki", "--size", "-5ki"], "4_kibibytes.foo");1676 te.assert_output(1677 &["", "--size", "+3ki", "--size", "-5ki"],1678 "./4_kibibytes.foo",1679 );16801681 // Files with size between 3 kilobytes and 5 kilobytes.1682 te.assert_output(1683 &["", "--size", "+3k", "--size", "-5k"],1678 "3_kilobytes.foo1679 4_kibibytes.foo",1684 "./3_kilobytes.foo1685 ./4_kibibytes.foo",1686 );16871688 // Files with size greater than 3 kilobytes and less than 3 kibibytes.1683 te.assert_output(&["", "--size", "+3k", "--size", "-3ki"], "3_kilobytes.foo");1689 te.assert_output(1690 &["", "--size", "+3k", "--size", "-3ki"],1691 "./3_kilobytes.foo",1692 );16931694 // Files with size equal 4 kibibytes.1686 te.assert_output(&["", "--size", "+4ki", "--size", "-4ki"], "4_kibibytes.foo");1687 te.assert_output(&["", "--size", "4ki"], "4_kibibytes.foo");1695 te.assert_output(1696 &["", "--size", "+4ki", "--size", "-4ki"],1697 "./4_kibibytes.foo",1698 );1699 te.assert_output(&["", "--size", "4ki"], "./4_kibibytes.foo");1700}17011702#[cfg(test)]1703fn create_file_with_modified<P: AsRef<Path>>(path: P, duration_in_secs: u64) {
27 unmodified lines
1731 create_file_with_modified(te.test_root().join("bar_1_day"), 24 * 60 * 60);17321733 te.assert_output(1734 &["", "--changed-within", "15min"],1723 "foo_0_now1724 bar_1_min1725 foo_10_min",1735 "./foo_0_now1736 ./bar_1_min1737 ./foo_10_min",1738 );17391740 te.assert_output(1741 &["", "--change-older-than", "15min"],1730 "bar_1_h1731 foo_2_h1732 bar_1_day",1742 "./bar_1_h1743 ./foo_2_h1744 ./bar_1_day",1745 );17461747 te.assert_output(1748 &["foo", "--changed-within", "12h"],1737 "foo_0_now1738 foo_10_min1739 foo_2_h",1749 "./foo_0_now1750 ./foo_10_min1751 ./foo_2_h",1752 );1753}17541755#[cfg(test)]
11 unmodified lines
1767 change_file_modified(te.test_root().join("30dec2017"), "2017-12-30T23:59:00Z");17681769 te.assert_output(1770 &["", "--change-newer-than", "2018-01-01 00:00:00"],1759 "15mar2018",1771 "./15mar2018",1772 );1773 te.assert_output(1774 &["", "--changed-before", "2018-01-01 00:00:00"],1763 "30dec2017",1775 "./30dec2017",1776 );1777}17781779#[test]
15 unmodified lines
1795 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);17961797 te.assert_output(1798 &["--base-directory", "one"],1787 "b.foo1788 two1789 two/c.foo1790 two/C.Foo21791 two/three1792 two/three/d.foo1793 two/three/directory_foo",1799 "./b.foo1800 ./two1801 ./two/c.foo1802 ./two/C.Foo21803 ./two/three1804 ./two/three/d.foo1805 ./two/three/directory_foo",1806 );18071808 te.assert_output(1809 &["--base-directory", "one/two", "foo"],1798 "c.foo1799 C.Foo21800 three/d.foo1801 three/directory_foo",1810 "./c.foo1811 ./C.Foo21812 ./three/d.foo1813 ./three/directory_foo",1814 );18151816 // Explicit root path1817 te.assert_output(
27 unmodified lines
18451846 // Unrestricted1847 te.assert_output(1848 &["--max-results=0", "c.foo"],1837 "one/two/C.Foo21838 one/two/c.foo",1849 "./one/two/C.Foo21850 ./one/two/c.foo",1851 );18521853 // Limited to two results1854 te.assert_output(1855 &["--max-results=2", "c.foo"],1844 "one/two/C.Foo21845 one/two/c.foo",1856 "./one/two/C.Foo21857 ./one/two/c.foo",1858 );18591860 // Limited to one result. We could find either C.Foo2 or c.foo1861 let assert_just_one_result_with_option = |option| {1862 let output = te.assert_success_and_get_output(".", &[option, "c.foo"]);1863 let stdout = String::from_utf8_lossy(&output.stdout)1864 .trim()1865 .replace(&std::path::MAIN_SEPARATOR.to_string(), "/");1854 assert!(stdout == "one/two/C.Foo2" || stdout == "one/two/c.foo");1866 assert!(stdout == "./one/two/C.Foo2" || stdout == "./one/two/c.foo");1867 };1868 assert_just_one_result_with_option("--max-results=1");1869 assert_just_one_result_with_option("-1");1870}
104 unmodified lines
19751976 te.assert_failure(&["^\\.gitignore"]);1977 te.assert_failure(&["--glob", ".gitignore"]);19781967 te.assert_output(&["--hidden", "^\\.gitignore"], ".gitignore");1968 te.assert_output(&["--hidden", "--glob", ".gitignore"], ".gitignore");1979 te.assert_output(&["--hidden", "^\\.gitignore"], "./.gitignore");1980 te.assert_output(&["--hidden", "--glob", ".gitignore"], "./.gitignore");1981 te.assert_output(&[".gitignore"], "");1982}19831984#[test]1985fn test_strip_cwd_prefix() {1986 let te = TestEnv::new(DEFAULT_DIRS, DEFAULT_FILES);19871988 te.assert_output(1989 &["--strip-cwd-prefix", "."],1990 "a.foo1991 e1 e21992 one1993 one/b.foo1994 one/two1995 one/two/c.foo1996 one/two/C.Foo21997 one/two/three1998 one/two/three/d.foo1999 one/two/three/directory_foo2000 symlink",2001 );2002}
modified:CHANGELOG.md+1 added
16 unmodified lines
17 https://github.com/sharkdp/lscolors/pull/35 (@tavianator)1819## Bugfixes2021- Always show the `./` prefix for search results unless the output is a TTY or `--strip-cwd-prefix` is set, see #760 and #861 (@jcaplan)22- Set default path separator to `/` in MSYS, see #537 and #730 (@aswild)23- fd cannot search files under a RAM disk, see #75224- fd doesn't show substituted drive on Windows, see #36525- Properly handle write errors to devices that are full, see #737
518 unmodified lines