File: run_compilation_failure_tests.sh

package info (click to toggle)
mapbox-variant 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,648 kB
  • sloc: cpp: 31,068; ansic: 959; python: 424; makefile: 145; objc: 59; sh: 36
file content (49 lines) | stat: -rwxr-xr-x 1,157 bytes parent folder | download | duplicates (6)
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
48
49
#!/bin/sh
#
#  Try to compile all programs in the test/compilation_failure directory.
#  Compilation must fail and the error message must match the pattern in the
#  corresponding .pattern file.
#

DIR="test/compilation_failure"
CXX=${CXX:-clang++}

if [ `uname -s` = "Darwin" ]; then
    CXXFLAGS="$CXXFLAGS -stdlib=libc++"
fi

error_msg() {
    if [ ! -z "$1" ]; then
	printf 'output was:\n=======\n%s\n=======\n' "$1"
    fi
}

exit_code=0
for test_code in $DIR/*.cpp; do
    name=`basename $test_code .cpp`

    result=`${CXX} -std=c++11 -c -o /dev/null -I./include ${CXXFLAGS} ${test_code} 2>&1`
    status=$?

    if [ $status = 1 ]; then
	expected=`sed -n -e '/@EXPECTED/s/.*: \+//p' ${test_code}`
	if echo $result | grep -q "$expected"; then
	    echo "$name [OK]"
	else
	    echo "$name [FAILED - wrong error message]"
	    echo "Expected error message: $expected"
	    error_msg "$result"
	    exit_code=1
	fi
    elif [ $status = 0 ]; then
	echo "$name [FAILED - compile was successful]"
	error_msg "$result"
	exit_code=1
    else
	echo "$name [FAILED - unknown error in compile]"
	error_msg "$result"
	exit_code=1
    fi
done

exit ${exit_code}