2086c82297e775cc8968160ec540b274f24bd079
[jansson.git] / test / run-test
1 VALGRIND_CMDLINE="valgrind --leak-check=full --show-reachable=yes --track-origins=yes -q"
2
3 run_testprog() {
4     local prog=$1
5     local prefix=$2
6     if [ -n "$VALGRIND" ]; then
7         local runner="$VALGRIND_CMDLINE "
8     fi
9
10     case "$prog" in
11         load_file_dump_file)
12             $runner./$prog \
13                 $prefix.in \
14                 $prefix.$prog.stdout \
15                 2>$prefix.$prog.stderr
16             ;;
17         *)
18             $runner./$prog \
19                 <$prefix.in \
20                 >$prefix.$prog.stdout \
21                 2>$prefix.$prog.stderr
22             ;;
23     esac
24
25     if [ -n "$VALGRIND" ]; then
26         # Check for Valgrind error output. The valgrind option
27         # --error-exitcode is not enough because Valgrind doesn't
28         # think unfreed allocs are errors.
29         if grep -E -q '^==[0-9]+== ' $prefix.$prog.stderr; then
30             echo "### $prefix ($prog) failed:" >&2
31             echo "valgrind detected an error" >&2
32             echo "for details, see test/$prefix.$prog.stderr" >&2
33             exit 1
34         fi
35     fi
36 }
37
38 rm -rf testlogs
39
40 for testfile in $TESTFILES; do
41     tmpdir="testlogs/`basename $testfile`"
42     mkdir -p $tmpdir
43     ${srcdir}/split-testfile.py $testfile $tmpdir | while read name; do
44         run_test loadf_dumpf $tmpdir/$name
45         run_test loads_dumps $tmpdir/$name
46         run_test load_file_dump_file $tmpdir/$name
47         echo -n '.'
48     done || exit 1
49     echo
50 done