61 lines
1.8 KiB
Bash
Executable File
61 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# tests/test_find.sh - Tests for find applet
|
|
_test_name="find"
|
|
. "$(dirname "$0")/harness.sh"
|
|
|
|
setup_tmpdir
|
|
FIND="$VX find"
|
|
|
|
echo "Running find tests..."
|
|
|
|
mkdir -p tree/sub
|
|
printf 'hello\n' > tree/a.txt
|
|
printf 'world!!' > tree/sub/b.c
|
|
ln -s ../a.txt tree/sub/link_to_a
|
|
chmod 754 tree/sub/b.c
|
|
|
|
a_count="$($FIND tree -name '*.txt' -type f | wc -l | tr -d ' ')"
|
|
check_eq "$a_count" "1" "basic: -name and -type"
|
|
|
|
out="$($FIND tree -maxdepth 1 -type d | sort)"
|
|
exp="$(printf '%s\n' tree tree/sub)"
|
|
check_eq "$out" "$exp" "maxdepth: top-level directories"
|
|
|
|
out="$($FIND tree/sub -name '*.c' -exec echo FOUND:{} ';')"
|
|
check_eq "$out" "FOUND:tree/sub/b.c" "exec: substitution works"
|
|
|
|
out="$($FIND tree/sub -name 'b.c' -printf '%f|%h|%p|%s|%m\n')"
|
|
check_eq "$out" "b.c|tree/sub|tree/sub/b.c|7|0754" "printf: common directives"
|
|
|
|
out="$($FIND tree/sub -name 'b.c' -printf '%TY-%Tm-%Td %TH:%TM\n')"
|
|
case "$out" in
|
|
????-??-??' '??:??) pass "printf: time fields" ;;
|
|
*) fail "printf: time fields" "got: $out" ;;
|
|
esac
|
|
|
|
out="$($FIND tree/sub -type l -printf '%l\n')"
|
|
check_eq "$out" "../a.txt" "printf: symlink target"
|
|
|
|
expected_printf="$(printf 'A\nB\tC')"
|
|
out="$($FIND tree/sub -name 'b.c' -printf 'A\nB\tC')"
|
|
check_eq "$out" "$expected_printf" "printf: backslash escapes"
|
|
|
|
fstype="$(stat -f -c '%T' . 2>/dev/null)"
|
|
if [ -n "$fstype" ]; then
|
|
out="$($FIND . -maxdepth 1 -fstype "$fstype" -name tree)"
|
|
check_eq "$out" "./tree" "fstype: current fs matches"
|
|
fi
|
|
|
|
mkdir daystart
|
|
printf 'y\n' > daystart/late_yesterday
|
|
if touch -d 'yesterday 23:59' daystart/late_yesterday 2>/dev/null; then
|
|
out="$($FIND daystart -daystart -name late_yesterday -mtime 1)"
|
|
check_eq "$out" "daystart/late_yesterday" "daystart: shifts boundary to start of day"
|
|
else
|
|
pass "daystart: touch -d unavailable (skip)"
|
|
fi
|
|
|
|
check_exit "exit: no path exits 1" 1 $FIND
|
|
|
|
summary
|