diff options
Diffstat (limited to 'myfind/myfind/tests/fun/tests.sh')
| -rwxr-xr-x | myfind/myfind/tests/fun/tests.sh | 196 |
1 files changed, 196 insertions, 0 deletions
diff --git a/myfind/myfind/tests/fun/tests.sh b/myfind/myfind/tests/fun/tests.sh new file mode 100755 index 0000000..f229a92 --- /dev/null +++ b/myfind/myfind/tests/fun/tests.sh @@ -0,0 +1,196 @@ +#!/bin/sh + +REF_OUT="ref.out" +TEST_OUT="test.out" + +testfiles() +{ + echo "Finding path '$@'..." + find "$@" > "$REF_OUT" + sed -i '/.*\.out/d' "$REF_OUT" + ./myfind "$@" > "$TEST_OUT" + [ $(echo "$?") -eq 0 ] && echo "Return value OK" + sed -i '/.*\.out/d' "$TEST_OUT" + diff "$REF_OUT" "$TEST_OUT" && echo "Success" +} + +testperm() +{ + echo "Finding perm '$@'..." + find "$@" > "$REF_OUT" + sed -i '/.*\.out/d' "$REF_OUT" + ./myfind "$@" > "$TEST_OUT" + [ $(echo "$?") -eq 0 ] && echo "Return value OK" + sed -i '/.*\.out/d' "$TEST_OUT" + diff "$REF_OUT" "$TEST_OUT" && echo "Success" +} + +testug() +{ + echo "Finding '$@'..." + find "$@" > "$REF_OUT" + sed -i '/.*\.out/d' "$REF_OUT" + ./myfind "$@" > "$TEST_OUT" + [ $(echo "$?") -eq 0 ] && echo "Return value OK" + sed -i '/.*\.out/d' "$TEST_OUT" + diff "$REF_OUT" "$TEST_OUT" && echo "Success" +} + +testflags() +{ + echo "Finding flags '$@'..." + find "$@" > "$REF_OUT" + sed -i '/.*\.out/d' "$REF_OUT" + ./myfind "$@" > "$TEST_OUT" + [ $(echo "$?") -eq 0 ] && echo "Return value OK" + sed -i '/.*\.out/d' "$TEST_OUT" + diff "$REF_OUT" "$TEST_OUT" && echo "Success" +} + +testboth() +{ + echo "Finding '$@'..." + find "$@" > "$REF_OUT" + sed -i '/.*\.out/d' "$REF_OUT" + ./myfind "$@" > "$TEST_OUT" + [ $(echo "$?") -eq 0 ] && echo "Return value OK" + sed -i '/.*\.out/d' "$TEST_OUT" + diff "$REF_OUT" "$TEST_OUT" && echo "Success" +} + +testerror() +{ + echo "Attempting to find '$@'..." + find "$@" > "$REF_OUT" + sed -i '/.*\.out/d' "$REF_OUT" + ./myfind "$@" > "$TEST_OUT" + ret=$(echo "$?") + ([ "$ret" -eq 1 ] && echo "Return value OK") || echo "Invalid return value " $ret + sed -i '/.*\.out/d' "$TEST_OUT" + diff "$REF_OUT" "$TEST_OUT" && echo "Success" +} + +clean() +{ + rm "$REF_OUT" "$TEST_OUT" +} + +# Files + +echo "Tests files:" +echo "======" + +testfiles +testfiles tests +testfiles src +testfiles src/// + +echo +echo "=============================================" +echo + +# Perms + +mkdir foo +touch foo/foo foo/bar foo/baz +chmod 123 foo/foo +chmod 777 foo/bar +chmod 644 foo/baz + +echo "Tests perm:" +echo "======" + +# Should only match foo/foo +testperm foo -perm 123 +# Should match foo/bar and foo/foo +testperm foo -perm -121 +# Should match foo/bar and foo/baz +testperm foo -perm /641 +# Should only match foo/bar +testperm foo -perm /060 +# Should only match foo/foo +chmod 644 foo/bar +chmod 644 foo/baz +testperm foo -perm -121 + +echo +echo "=============================================" +echo + +echo "Tests user:" +echo "======" + +testug foo -user marcellus +# sudo chown nobody foo/bar +testug foo -user marcellus +testug foo -user nobody + +echo +echo "=============================================" +echo + +echo "Tests group:" +echo "======" + +testug foo -group marcellus +# sudo chown :wheel foo/bar +testug foo -group marcellus +testug foo -group wheel + +# Clean +rm -rf foo + +echo +echo "=============================================" +echo + +# Flags + +echo "Tests flags:" +echo "======" + +testflags -type d +testflags -type f +testflags -name '*' +testflags -newer Makefile + +echo +echo "=============================================" +echo + +# Both + +echo "Tests both:" +echo "======" + +testboth tests -type d +testboth src/ -type f +testboth ../ -name '*.h' -a -type f +testboth ../ -name Makefile -o -newer Makefile + +echo +echo "=============================================" +echo + +# Errors + +echo "Error tests:" +echo "======" + +testerror -type ff +testerror -name +testerror -newer +testerror -type +testerror -name '*.c' -print -newer -o -print +mkdir foo +touch foo/foo foo/bar foo/baz +testerror foo -user dghdfkhg +rm -rf foo +testerror -name '*.c' -a -a -group marcellus +testerror -name '*.c' -o -a -group marcellus +testerror -name '*.c' -a -o -group marcellus +testerror -name '*.c' -o -o -group marcellus + +# Cleanup + +clean |
