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 8if [ ! -z "$srcdir" ]; then 9 testdir="$srcdir/glsl/glcpp/tests" 10 glcpp_test="$srcdir/glsl/glcpp/tests/glcpp-test" 11else 12 testdir=. 13 glcpp_test=./glcpp-test 14fi 15 16total=0 17pass=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 22stdintoexitstatus() { 23 read exitstatus 24 return $exitstatus 25} 26 27run_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 51usage () 52{ 53 cat <<EOF 54Usage: glcpp-cr-lf [options...] 55 56Run the entire glcpp-test suite several times, each time with each source 57file transformed to use a non-standard line-termination character. Each 58entire run with a different line-termination character is considered a 59single test. 60 61Valid options include: 62 63 -v|--verbose Print all output from the various sub-tests 64EOF 65} 66 67# Parse command-line options 68for 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 80done 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. 85rm -rf ./subtest-lf 86mkdir subtest-lf 87for file in "$testdir"/*.c; do 88 base=$(basename "$file") 89 cp "$file" subtest-lf 90done 91 92${glcpp_test} --testdir=subtest-lf >/dev/null 2>&1 93 94echo "===== Testing with \\\\r line terminators (old Mac format) =====" 95 96# Prepare test files with '\r' instead of '\n' 97rm -rf ./subtest-cr 98mkdir subtest-cr 99for 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 103done 104 105run_test "${glcpp_test} --testdir=subtest-cr" 106 107echo "===== Testing with \\\\r\\\\n line terminators (DOS format) =====" 108 109# Prepare test files with '\r\n' instead of '\n' 110rm -rf ./subtest-cr-lf 111mkdir subtest-cr-lf 112for file in "$testdir"/*.c; do 113 base=$(basename "$file") 114 sed -e 's/$/ 115/' < "$file" > subtest-cr-lf/"$base" 116 cp `pwd`/glsl/glcpp/tests/subtest-lf/"$base".out subtest-cr-lf/"$base".expected 117done 118 119run_test "${glcpp_test} --testdir=subtest-cr-lf" 120 121echo "===== Testing with \\\\n\\\\r (bizarre, but allowed by GLSL spec.) =====" 122 123# Prepare test files with '\n\r' instead of '\n' 124rm -rf ./subtest-lf-cr 125mkdir subtest-lf-cr 126for file in "$testdir"/*.c; do 127 base=$(basename "$file") 128 sed -e 's/$/ 129/' < "$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 131done 132 133run_test "${glcpp_test} --testdir=subtest-lf-cr" 134 135echo "" 136echo "$pass/$total tests returned correct results" 137echo "" 138 139if [ "$pass" = "$total" ]; then 140 exit 0 141else 142 exit 1 143fi 144