Imported Upstream version 1.49.1
[platform/upstream/gobject-introspection.git] / tests / gi-tester
1 #!/usr/bin/env bash
2
3 targetname=$1
4
5 # Note the target name for the documentation targets (-C, -Python, -Gjs)
6 # incorrectly include a relative path to the srcdir, strip that off for usage
7 # in directory diffs.
8 targetbase=${targetname##*/}
9
10 case $targetname in
11 *.gir)
12     len=${#targetname}
13     limit=$(expr $len - 4)
14     diff -u -U 10 ${srcdir}/${targetname:0:${limit}}-expected.gir ${builddir}/${targetname}
15     exit $?
16     ;;
17 *.typelib)
18     # Do nothing for typelibs, this just ensures they build as part of the tests
19     exit 0
20     ;;
21 *-C)
22     diff -r -u -w -I '^\s*$' -U 10 ${srcdir}/${targetbase}-expected ${builddir}/${targetbase}
23     exit $?
24     ;;
25 *-Python)
26     diff -r -u -w -I '^\s*$' -U 10 ${srcdir}/${targetbase}-expected ${builddir}/${targetbase}
27     exit $?
28     ;;
29 *-Gjs)
30     diff -r -u -w -I '^\s*$' -U 10 ${srcdir}/${targetbase}-expected ${builddir}/${targetbase}
31     exit $?
32     ;;
33 *-sections.txt)
34     diff -u -w -I '^\s*$' -U 10 ${srcdir}/${targetname::-4}-expected.txt ${builddir}/${targetname}
35     exit $?
36     ;;
37 *.py)
38     if [[ -z "${TESTARGS}" ]]; then
39         # Run as regular Python file if TESTARGS is empty
40         PYTHONPATH=${top_builddir}:${top_srcdir} ${PYTHON} ${targetname}
41         exit $?
42     else
43         # Run as Python unittest module with TESTARGS concatenated to the basename of target.
44         # Ensure we are in the directory containing the python module first.
45         export PYTHONPATH=$(readlink -f ${top_builddir}):$(readlink -f ${top_srcdir})
46         modulename=$(basename "${targetbase}" .py)
47         (cd $(dirname ${targetname}) &&  ${PYTHON} -m unittest -v "${modulename}.${TESTARGS}")
48         exit $?
49     fi
50     ;;
51 *)
52     echo $"Usage: [TESTARGS=<args>] gi-tester <targetname>"
53     exit 1
54     ;;
55 esac