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