• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3if [ -z "$srcdir" -o -z "$abs_builddir" ]; then
4    echo ""
5    echo "Warning: you're invoking the script manually and things may fail."
6    echo "Attempting to determine/set srcdir and abs_builddir variables."
7    echo ""
8
9    # Should point to `dirname Makefile.glsl.am`
10    srcdir=./../../../
11    cd `dirname "$0"`
12    # Should point to `dirname Makefile` equivalent to the above.
13    abs_builddir=`pwd`/../../../
14fi
15
16testdir="$srcdir/glsl/glcpp/tests"
17glcpp_test="$srcdir/glsl/glcpp/tests/glcpp-test.sh"
18
19total=0
20pass=0
21
22# This supports a pipe that doesn't destroy the exit status of first command
23#
24# http://unix.stackexchange.com/questions/14270/get-exit-status-of-process-thats-piped-to-another
25stdintoexitstatus() {
26    read exitstatus
27    return $exitstatus
28}
29
30run_test ()
31{
32    cmd="$1"
33
34    total=$((total+1))
35
36    if [ "$VERBOSE" = "yes" ]; then
37	if $cmd; then
38	    echo "PASS"
39	    pass=$((pass+1))
40	else
41	    echo "FAIL"
42	fi
43    else
44	# This is "$cmd | tail -2" but with the exit status of "$cmd" not "tail -2"
45	if (((($cmd; echo $? >&3) | tail -2 | head -1 >&4) 3>&1) | stdintoexitstatus) 4>&1; then
46	    echo "PASS"
47	    pass=$((pass+1))
48	else
49	    echo "FAIL"
50	fi
51    fi
52}
53
54usage ()
55{
56	cat <<EOF
57Usage: `basename "$0"` [options...]
58
59Run the entire glcpp-test suite several times, each time with each source
60file transformed to use a non-standard line-termination character. Each
61entire run with a different line-termination character is considered a
62single test.
63
64Valid options include:
65
66	-v|--verbose	Print all output from the various sub-tests
67EOF
68}
69
70# Parse command-line options
71for option; do
72    case "${option}" in
73	-v|--verbose)
74	    VERBOSE=yes;
75	    ;;
76	*)
77	    echo "Unrecognized option: $option" >&2
78	    echo >&2
79	    usage
80	    exit 1
81	    ;;
82	esac
83done
84
85# All tests depend on the .out files being present. So first do a
86# normal run of the test suite, (silently) just to create the .out
87# files as a side effect.
88rm -rf ./subtest-lf
89mkdir subtest-lf
90for file in "$testdir"/*.c; do
91    base=$(basename "$file")
92    cp "$file" subtest-lf
93done
94
95${glcpp_test} --testdir=subtest-lf >/dev/null 2>&1
96
97echo "===== Testing with \\\\r line terminators (old Mac format) ====="
98
99# Prepare test files with '\r' instead of '\n'
100rm -rf ./subtest-cr
101mkdir subtest-cr
102for file in "$testdir"/*.c; do
103    base=$(basename "$file")
104    tr "\n" "\r" < "$file" > subtest-cr/"$base"
105    cp $abs_builddir/glsl/glcpp/tests/subtest-lf/"$base".out subtest-cr/"$base".expected
106done
107
108run_test "${glcpp_test} --testdir=subtest-cr"
109
110echo "===== Testing with \\\\r\\\\n line terminators (DOS format) ====="
111
112# Prepare test files with '\r\n' instead of '\n'
113rm -rf ./subtest-cr-lf
114mkdir subtest-cr-lf
115for file in "$testdir"/*.c; do
116    base=$(basename "$file")
117    sed -e 's/$/
118/' < "$file" > subtest-cr-lf/"$base"
119    cp $abs_builddir/glsl/glcpp/tests/subtest-lf/"$base".out subtest-cr-lf/"$base".expected
120done
121
122run_test "${glcpp_test} --testdir=subtest-cr-lf"
123
124echo "===== Testing with \\\\n\\\\r (bizarre, but allowed by GLSL spec.) ====="
125
126# Prepare test files with '\n\r' instead of '\n'
127rm -rf ./subtest-lf-cr
128mkdir subtest-lf-cr
129for file in "$testdir"/*.c; do
130    base=$(basename "$file")
131    sed -e 's/$/
132/' < "$file" | tr "\n\r" "\r\n" > subtest-lf-cr/"$base"
133    cp $abs_builddir/glsl/glcpp/tests/subtest-lf/"$base".out subtest-lf-cr/"$base".expected
134done
135
136run_test "${glcpp_test} --testdir=subtest-lf-cr"
137
138if [ $total -eq 0 ]; then
139    echo "Could not find any tests."
140    exit 1
141fi
142
143echo ""
144echo "$pass/$total tests returned correct results"
145echo ""
146
147if [ "$pass" = "$total" ]; then
148    exit 0
149else
150    exit 1
151fi
152