summaryrefslogtreecommitdiffstats
path: root/tests/setup
blob: 935ab038c58cc06d7a16012bfbdd163bd75db55c (plain)
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
#!/bin/sh

# This is meant to be included by each test's shell script driver.

if [ -n "$TRACE_TESTS" ]; then
    set -x
fi

set -eu

JQTESTDIR=$(cd "$(dirname "$0")" && pwd)
JQBASEDIR=$JQTESTDIR/..
JQ=${JQ:-$JQBASEDIR/jq}

# Some tests have locale-dependent output; use C locale.  Fixes #3038
LC_ALL=C
export LC_ALL

if [ -z "${NO_VALGRIND-}" ] && which valgrind > /dev/null; then
    VALGRIND="valgrind --error-exitcode=1 --leak-check=full \
                       --suppressions=$JQTESTDIR/onig.supp \
                       --suppressions=$JQTESTDIR/local.supp"
    VG_EXIT0=--error-exitcode=0
    Q=-q
else
    VALGRIND=
    VG_EXIT0=
    Q=
fi

mods=$JQTESTDIR/modules

clean=true
d=
clean () {
    if ! $clean; then
        echo "See temp files in $d!"
    elif [ -n "$d" ]; then
        rm -rf "$d"
    fi
}
trap clean EXIT
d=$(mktemp -d -t jqXXXXXX || true)
if [ -z "$d" ]; then
    echo "Your OS does not support mktemp(1) -d" 1>&2
    exit 1
fi