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