test/.gitignore: Add testprogs/test_simple
[jansson.git] / test / test-api
1 #!/bin/sh
2 #
3 # Copyright (c) 2009 Petri Lehtinen <petri@digip.org>
4 #
5 # Jansson is free software; you can redistribute it and/or modify
6 # it under the terms of the MIT license. See LICENSE for details.
7
8 VALGRIND_CMDLINE="valgrind --leak-check=full --show-reachable=yes --track-origins=yes -q"
9 LOGDIR="testlogs/api"
10 N=`find testprogs -type f -executable | wc -l`
11
12 echo "testprogs: $N tests"
13
14 rm -rf $LOGDIR
15 mkdir -p $LOGDIR
16
17 if [ -n "$VALGRIND" ]; then
18     runner="$VALGRIND_CMDLINE "
19 fi
20
21 i=1
22 failed=
23 for prog in testprogs/*; do
24     [ -x $prog ] || continue
25     t=`basename $prog`
26     logbase="testlogs/api/`printf '%02d-%s' $i $t`"
27     if ! $runner./$prog >$logbase.stdout 2>$logbase.stderr; then
28         echo >&2
29         echo "### $prog failed:" >&2
30         cat $logbase.stderr
31         exit 1
32     fi
33     if [ -n "$VALGRIND" ]; then
34         # Check for Valgrind error output. The valgrind option
35         # --error-exitcode is not enough because Valgrind doesn't
36         # think unfreed allocs are errors.
37         if grep -E -q '^==[0-9]+== ' $logbase.stderr; then
38             echo "### $prog failed:" >&2
39             echo "valgrind detected an error" >&2
40             echo "for details, see test/$logbase.stderr" >&2
41             exit 1
42         fi
43     fi
44     echo -n '.'
45 done
46 echo