Add more unit tests, search directories and symlinks too
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent 10cd964 · Browse files · 2 files·+96 added−57 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+96 added−57 removed
- tests:+95 added−54 removed
- other:+1 added−3 removed
Provenance
- Commit
0757a50- Tree
983cacf- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
10cd964
2 files changed+96 added−57 removed
modified:src/main.rs+1 added-3 removed
114 unmodified lines115 let search_str =116 if config.search_full_path {117 path_rel.to_str()118 } else {119- if !path_rel.is_file() { continue }120-119 path_rel.file_name()120 .and_then(OsStr::to_str)121 };122 72 unmodified lines195 "print this help message");196 opts.optflag("s", "sensitive",197 "case-sensitive search (default: smart case)");198 opts.optflag("p", "full-path",201- "search full path (default: filename only)");199+ "search full path (default: file-/dirname only)");200 opts.optflag("H", "hidden",201 "search hidden files/directories");202 opts.optflag("I", "no-ignore",203 "do not respect .(git)ignore files");62 unmodified linesmodified:tests/test.sh+95 added-54 removed
38 unmodified lines394041424343444546473 unmodified lines51525354555657585960616263646555565758596061626364656667686970727374757677787971727374757677787980818283848586878889909192939495969798991001011021038384851041051061071081091108911111211311411511611711811912012193949596979812212312412512612712812913013110210310410510610713213313413513613713813910911011111211311411514014114214314414514614714814915011912012112215115215315415515615712612712812913013113215815916016116216316416516616716816917017117217317417517638 unmodified lines echo -e "${green}actual${reset} output:\n"
diff -C3 --label expected --label actual --color \ "$tmp_expected" "$tmp_output" || true # exit 1 exit 1 fi}
root=$(mktemp --directory)3 unmodified lines# Setup test environment
mkdir -p one/two/three
touch a.cpptouch one/b.cpptouch one/two/c.cpptouch one/two/C.cpptouch one/two/three/d.cpptouch ignored.cpp
touch .hidden.cpp
echo "ignored.cpp" > .gitignore
touch a.footouch one/b.footouch one/two/c.footouch one/two/C.Footouch one/two/three/d.foomkdir one/two/three/directory_footouch ignored.footouch .hidden.fooln -s one/two symlink
echo "ignored.foo" > .gitignore
# Run the tests
suite "Simple tests"expect "a.cpp" a.cppexpect "one/b.cpp" b.cppexpect "one/two/three/d.cpp" d.cppexpect "a.cppone/b.cppone/two/c.cppone/two/C.cppone/two/three/d.cpp" cppexpect "a.foo" a.fooexpect "one/b.foo" b.fooexpect "one/two/three/d.foo" d.fooexpect "a.fooone/b.fooone/two/c.fooone/two/C.Fooone/two/three/d.fooone/two/three/directory_foo" fooexpect "a.foooneone/b.fooone/twoone/two/c.fooone/two/C.Fooone/two/threeone/two/three/d.fooone/two/three/directory_foosymlink" # run 'fd' without arguments
suite "Regex searches"expect "a.fooone/b.fooone/two/c.fooone/two/C.Foo" '[a-c].foo'expect "a.fooone/b.fooone/two/c.foo" --sensitive '[a-c].foo'
suite "Smart case"expect "one/two/c.cppone/two/C.cpp" c.cppexpect "one/two/C.cpp" C.cppexpect "one/two/c.fooone/two/C.Foo" c.fooexpect "one/two/C.Foo" C.Fooexpect "one/two/C.Foo" Foo
suite "Case-sensitivity (--sensitive)"expect "one/two/C.cpp" --sensitive C.cppexpect "one/two/c.foo" --sensitive c.fooexpect "one/two/C.Foo" --sensitive C.Foo
suite "Full path search (--full-path)"expect "one/two/three/d.fooone/two/three/directory_foo" --full-path 'three.*foo'expect "a.foo" --full-path '^a\.foo$'
suite "Hidden files (--hidden)"expect "a.cpp.hidden.cppone/b.cppone/two/c.cppone/two/C.cppone/two/three/d.cpp" --hidden cppexpect "a.foo.hidden.fooone/b.fooone/two/c.fooone/two/C.Fooone/two/three/d.fooone/two/three/directory_foo" --hidden foo
suite "Ignored files (--no-ignore)"expect "a.cppignored.cppone/b.cppone/two/c.cppone/two/C.cppone/two/three/d.cpp" --no-ignore cppexpect "a.fooignored.fooone/b.fooone/two/c.fooone/two/C.Fooone/two/three/d.fooone/two/three/directory_foo" --no-ignore foo
expect "a.cpp.hidden.cppignored.cppone/b.cppone/two/c.cppone/two/C.cppone/two/three/d.cpp" --hidden --no-ignore cppexpect "a.foo.hidden.fooignored.fooone/b.fooone/two/c.fooone/two/C.Fooone/two/three/d.fooone/two/three/directory_foo" --hidden --no-ignore foo
suite "Symlinks (--follow)"expect "one/two/c.cppone/two/C.cppsymlink/c.cppsymlink/C.cpp" --follow c.cppexpect "one/two/c.fooone/two/C.Foosymlink/c.foosymlink/C.Foo" --follow c.foo
suite "Maximum depth (--max-depth)"expect "a.cppone/b.cppone/two/c.cppone/two/C.cpp" --max-depth 3expect "a.cppone/b.cpp" --max-depth 2expect "a.cpp" --max-depth 1expect "a.foooneone/b.fooone/twoone/two/c.fooone/two/C.Fooone/two/threesymlink" --max-depth 3expect "a.foooneone/b.fooone/twosymlink" --max-depth 2expect "a.fooonesymlink" --max-depth 1
# All doneecho