forked from PLTools/OCanren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
executable file
·99 lines (76 loc) · 1.97 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
# simple script for running test and diffing its result with the expected;
# please, run the script from the toplevel directory of the project
# predefined directory with tests
TESTDIR="regression"
# path to the file containing list of tests
TESTLIST="${TESTDIR}/tests.txt"
# directories to search for tests
SEARCH_DIRS="${TESTDIR} samples"
PROMOTE=0
ARG=""
USAGE_MSG="usage: $0 [--promote] (<test name> | all)"
if test $# = 0; then
echo "${USAGE_MSG}"
exit 1
fi
if [[ $1 == "--promote" ]]; then
if test $# = 1; then
echo "${USAGE_MSG}"
exit 1
fi
PROMOTE=1
ARG=$2
else
ARG=$1
fi
if [[ ${ARG} == "all" ]]; then
# read test names from the file
TESTS=`cat ${TESTLIST}`
else
# try to find test/sample in predefined directories
FOUND=0
for DIR in ${SEARCH_DIRS}; do
TESTDIR=${DIR}
TESTSRC="${TESTDIR}/${ARG}.ml"
if [[ -f ${TESTSRC} ]]; then
FOUND=1
break
fi
done
if [[ ${FOUND} -eq "0" ]]; then
echo "cannot find ${ARG}"
echo "searched in ${SEARCH_DIRS}"
exit
fi
TESTS=${ARG}
fi
# compile all tests ahead of time
dune build `printf "${TESTDIR}/%s.exe " ${TESTS}`
for TEST in ${TESTS}; do
TESTEXE="${TESTDIR}/${TEST}.exe"
TESTLOG="${TESTDIR}/${TEST}.log"
TESTDIFF="${TESTDIR}/${TEST}.diff"
TESTORIG="${TESTDIR}/orig/${TEST}.orig"
# if the `--promote` option set, perform the promotion
if [[ ${PROMOTE} -eq "1" ]]; then
if [[ ! -f ${TESTLOG} ]]; then
echo "cannot find ${TESTLOG}"
else
cp ${TESTLOG} ${TESTORIG}
fi
continue
fi
# run the test;
# we use `dune exec` so that `dune`
# can build the test and its dependencies
# if it has not been done yet
dune exec --no-print-directory ${TESTEXE} > ${TESTLOG}
# diff test output with the expected and print `PASSED/FAILED` message
if diff -u ${TESTORIG} ${TESTLOG} > ${TESTDIFF}; then
echo "${TEST}: PASSED"
rm -f ${TESTDIFF}
else
echo "${TEST}: FAILED (see ${TESTDIFF})"
fi
done