2017-05-23 00:34:27 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
|
|
|
|
fd="${SCRIPT_DIR}/../target/debug/fd"
|
|
|
|
|
2017-06-13 21:08:02 +02:00
|
|
|
MKTEMP_TEMPLATE="fd-tests.XXXXXXXXXX"
|
|
|
|
|
2017-05-23 00:34:27 +02:00
|
|
|
export reset='\x1b[0m'
|
|
|
|
export bold='\x1b[01m'
|
|
|
|
export green='\x1b[32;01m'
|
|
|
|
export red='\x1b[31;01m'
|
|
|
|
|
|
|
|
set -eou pipefail
|
|
|
|
|
|
|
|
suite() {
|
|
|
|
echo
|
|
|
|
echo -e "${bold}$1${reset}"
|
|
|
|
echo
|
|
|
|
}
|
|
|
|
|
|
|
|
expect() {
|
|
|
|
expected_output="$1"
|
|
|
|
shift
|
|
|
|
|
2017-06-13 21:08:02 +02:00
|
|
|
tmp_expected="$(mktemp -t "$MKTEMP_TEMPLATE")"
|
|
|
|
tmp_output="$(mktemp -t "$MKTEMP_TEMPLATE")"
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
echo "$expected_output" > "$tmp_expected"
|
|
|
|
|
|
|
|
"$fd" "$@" | sort > "$tmp_output"
|
|
|
|
|
|
|
|
echo -ne " ${bold}▶${reset} Testing 'fd $*' ... "
|
|
|
|
|
|
|
|
if diff -q "$tmp_expected" "$tmp_output" > /dev/null; then
|
|
|
|
echo -e "${green}✓ okay${reset}"
|
2017-06-13 21:08:02 +02:00
|
|
|
|
|
|
|
rm -f "$tmp_expected" "$tmp_output"
|
2017-05-23 00:34:27 +02:00
|
|
|
else
|
|
|
|
echo -e "${red}❌FAILED${reset}"
|
|
|
|
|
|
|
|
echo -ne "\nShowing diff between ${red}expected${reset} and "
|
|
|
|
echo -e "${green}actual${reset} output:\n"
|
|
|
|
|
|
|
|
diff -C3 --label expected --label actual --color \
|
|
|
|
"$tmp_expected" "$tmp_output" || true
|
2017-06-13 21:08:02 +02:00
|
|
|
|
|
|
|
rm -f "$tmp_expected" "$tmp_output"
|
|
|
|
|
2017-05-24 22:16:55 +02:00
|
|
|
exit 1
|
2017-05-23 00:34:27 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2017-06-13 21:08:02 +02:00
|
|
|
root=$(mktemp -d -t "$MKTEMP_TEMPLATE")
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
cd "$root"
|
|
|
|
|
|
|
|
# Setup test environment
|
|
|
|
|
|
|
|
mkdir -p one/two/three
|
|
|
|
|
2017-05-24 22:16:55 +02:00
|
|
|
touch a.foo
|
|
|
|
touch one/b.foo
|
|
|
|
touch one/two/c.foo
|
|
|
|
touch one/two/C.Foo
|
|
|
|
touch one/two/three/d.foo
|
|
|
|
mkdir one/two/three/directory_foo
|
|
|
|
touch ignored.foo
|
|
|
|
touch .hidden.foo
|
2017-05-23 00:34:27 +02:00
|
|
|
ln -s one/two symlink
|
|
|
|
|
2017-05-28 19:35:27 +02:00
|
|
|
echo "ignored.foo" > .ignore
|
2017-05-24 22:16:55 +02:00
|
|
|
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
# Run the tests
|
|
|
|
|
|
|
|
suite "Simple tests"
|
2017-05-24 22:16:55 +02:00
|
|
|
expect "a.foo" a.foo
|
|
|
|
expect "one/b.foo" b.foo
|
|
|
|
expect "one/two/three/d.foo" d.foo
|
|
|
|
expect "a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo" foo
|
|
|
|
expect "a.foo
|
|
|
|
one
|
|
|
|
one/b.foo
|
|
|
|
one/two
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
one/two/three
|
|
|
|
one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo
|
|
|
|
symlink" # run 'fd' without arguments
|
|
|
|
|
2017-06-05 16:25:13 +02:00
|
|
|
suite "Explicit root path"
|
|
|
|
expect "one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo" foo one
|
|
|
|
expect "one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo" foo one/two/three
|
|
|
|
(
|
|
|
|
cd one/two
|
|
|
|
expect "../../a.foo
|
|
|
|
../b.foo
|
|
|
|
c.foo
|
|
|
|
C.Foo
|
|
|
|
three/d.foo
|
|
|
|
three/directory_foo" foo ../../
|
|
|
|
)
|
2017-05-24 22:16:55 +02:00
|
|
|
|
|
|
|
suite "Regex searches"
|
|
|
|
expect "a.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo" '[a-c].foo'
|
|
|
|
expect "a.foo
|
|
|
|
one/b.foo
|
2017-06-11 14:15:25 +02:00
|
|
|
one/two/c.foo" --case-sensitive '[a-c].foo'
|
2017-05-24 22:16:55 +02:00
|
|
|
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
suite "Smart case"
|
2017-05-24 22:16:55 +02:00
|
|
|
expect "one/two/c.foo
|
|
|
|
one/two/C.Foo" c.foo
|
|
|
|
expect "one/two/C.Foo" C.Foo
|
|
|
|
expect "one/two/C.Foo" Foo
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
|
2017-06-11 14:15:25 +02:00
|
|
|
suite "Case-sensitivity (--case-sensitive)"
|
|
|
|
expect "one/two/c.foo" --case-sensitive c.foo
|
|
|
|
expect "one/two/C.Foo" --case-sensitive C.Foo
|
2017-05-24 22:16:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
suite "Full path search (--full-path)"
|
|
|
|
expect "one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo" --full-path 'three.*foo'
|
|
|
|
expect "a.foo" --full-path '^a\.foo$'
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
suite "Hidden files (--hidden)"
|
2017-05-24 22:16:55 +02:00
|
|
|
expect "a.foo
|
|
|
|
.hidden.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo" --hidden foo
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
suite "Ignored files (--no-ignore)"
|
2017-05-24 22:16:55 +02:00
|
|
|
expect "a.foo
|
|
|
|
ignored.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo" --no-ignore foo
|
|
|
|
|
|
|
|
expect "a.foo
|
|
|
|
.hidden.foo
|
|
|
|
ignored.foo
|
|
|
|
one/b.foo
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
one/two/three/d.foo
|
|
|
|
one/two/three/directory_foo" --hidden --no-ignore foo
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
suite "Symlinks (--follow)"
|
2017-05-24 22:16:55 +02:00
|
|
|
expect "one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
symlink/c.foo
|
|
|
|
symlink/C.Foo" --follow c.foo
|
2017-05-23 00:34:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
suite "Maximum depth (--max-depth)"
|
2017-05-24 22:16:55 +02:00
|
|
|
expect "a.foo
|
|
|
|
one
|
|
|
|
one/b.foo
|
|
|
|
one/two
|
|
|
|
one/two/c.foo
|
|
|
|
one/two/C.Foo
|
|
|
|
one/two/three
|
|
|
|
symlink" --max-depth 3
|
|
|
|
expect "a.foo
|
|
|
|
one
|
|
|
|
one/b.foo
|
|
|
|
one/two
|
|
|
|
symlink" --max-depth 2
|
|
|
|
expect "a.foo
|
|
|
|
one
|
|
|
|
symlink" --max-depth 1
|
2017-05-23 00:34:27 +02:00
|
|
|
|
2017-06-05 21:18:27 +02:00
|
|
|
|
2017-06-11 14:15:25 +02:00
|
|
|
suite "Absolute paths (--absolute-path)"
|
2017-06-05 21:18:27 +02:00
|
|
|
expect "$root/a.foo
|
|
|
|
$root/one/b.foo
|
|
|
|
$root/one/two/c.foo
|
|
|
|
$root/one/two/C.Foo
|
|
|
|
$root/one/two/three/d.foo
|
2017-06-11 14:15:25 +02:00
|
|
|
$root/one/two/three/directory_foo" --absolute-path foo
|
2017-06-11 20:55:01 +02:00
|
|
|
expect "$root/a.foo
|
|
|
|
$root/one/b.foo
|
|
|
|
$root/one/two/c.foo
|
|
|
|
$root/one/two/C.Foo
|
|
|
|
$root/one/two/three/d.foo
|
|
|
|
$root/one/two/three/directory_foo" foo "$root"
|
2017-06-05 21:18:27 +02:00
|
|
|
|
2017-06-11 15:28:18 +02:00
|
|
|
|
|
|
|
suite "Invalid UTF-8"
|
|
|
|
touch "$(printf 'test-invalid-utf8-\xc3.txt')"
|
|
|
|
expect "$(printf 'test-invalid-utf8-\ufffd.txt')" test-invalid-utf8
|
|
|
|
|
2017-05-23 00:34:27 +02:00
|
|
|
# All done
|
|
|
|
echo
|