OILS / tools / find / find-test.sh View on Github | oilshell.org

84 lines, 71 significant
1#!/bin/sh
2
3set -e
4
5cd "$(realpath "$(dirname "$0")")"
6BASE="$PWD/../.."
7export PYTHONPATH="$BASE:$BASE/vendor"
8
9lorem_ipsum() {
10 echo "Lorem ipsum dolor sit amet, consectetur adipisici elit"
11}
12setup_testdir() (
13 mkdir -p "$1"
14 cd "$1"
15
16 touch emptyfile.txt
17 ln -s emptyfile.txt softlink.ln
18 ln emptyfile.txt hardlink.ln
19
20 mkdir dir_a dir_b dir_c
21
22 for d in ./dir_*
23 do
24 for i in $(seq 4)
25 do lorem_ipsum >"${d}/plainfile_${i}.txt"
26 done
27 done
28
29 mkdir dir_p
30 for p in R W X RW RX WX RWX
31 do touch dir_p/$p
32 done
33 for f in ./dir_p/*
34 do
35 chmod 000 "$f"
36 case $f in
37 */*X*) chmod +x "$f"
38 esac
39 case $f in
40 */*W*) chmod +w "$f"
41 esac
42 case $f in
43 */*R*) chmod +r "$f"
44 esac
45 done
46)
47
48testdir="_tmp/find-testdir"
49test -d "$testdir" || setup_testdir "$testdir"
50
51if [ $# -eq 0 ]
52then set -- "$PWD"/testdata/*
53fi
54
55eval 'find_py() (' "cd $PWD/../..;" "$(realpath ./find.py)" '"$@";' ')'
56
57set +e
58
59for test
60do
61 stdout="_tmp/$(basename "$test")_stdout"
62 stderr="_tmp/$(basename "$test")_stderr"
63 eval find "$(realpath "$testdir")" $(cat "$test") 2>/dev/null | sort >"${stdout}_expected" &
64 eval find_py "$(realpath "$testdir")" $(cat "$test") 2>"$stderr"| sort >"${stdout}_actual"
65 rc_actual=$?
66 wait %1
67 rc_expected=$?
68 if ! cmp -s "${stdout}_expected" "${stdout}_actual"
69 then
70 echo "!!! $(basename "$test") failed: files differ"
71 echo "--- EXPECTED ---"
72 cat "${stdout}_expected"
73 echo "---- ACTUAL ----"
74 cat "${stdout}_actual"
75 echo "----------------"
76 cat "$stderr"
77 elif [ $rc_expected != $rc_actual ]
78 then
79 echo "!!! $(basename "$test") failed: rcs differ"
80 echo "EXPECTED=$rc_expected ACTUAL=$rc_actual"
81 else
82 echo " $(basename "$test") ok"
83 fi
84done