Home | History | Annotate | Download | only in tests
      1 #!/bin/sh
      2 
      3 if [ -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`/../../../
     14 fi
     15 
     16 testdir="$srcdir/glsl/glcpp/tests"
     17 glcpp_test="$srcdir/glsl/glcpp/tests/glcpp-test.sh"
     18 
     19 total=0
     20 pass=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
     25 stdintoexitstatus() {
     26     read exitstatus
     27     return $exitstatus
     28 }
     29 
     30 run_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 
     54 usage ()
     55 {
     56 	cat <<EOF
     57 Usage: `basename "$0"` [options...]
     58 
     59 Run the entire glcpp-test suite several times, each time with each source
     60 file transformed to use a non-standard line-termination character. Each
     61 entire run with a different line-termination character is considered a
     62 single test.
     63 
     64 Valid options include:
     65 
     66 	-v|--verbose	Print all output from the various sub-tests
     67 EOF
     68 }
     69 
     70 # Parse command-line options
     71 for 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
     83 done
     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.
     88 rm -rf ./subtest-lf
     89 mkdir subtest-lf
     90 for file in "$testdir"/*.c; do
     91     base=$(basename "$file")
     92     cp "$file" subtest-lf
     93 done
     94 
     95 ${glcpp_test} --testdir=subtest-lf >/dev/null 2>&1
     96 
     97 echo "===== Testing with \\\\r line terminators (old Mac format) ====="
     98 
     99 # Prepare test files with '\r' instead of '\n'
    100 rm -rf ./subtest-cr
    101 mkdir subtest-cr
    102 for 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
    106 done
    107 
    108 run_test "${glcpp_test} --testdir=subtest-cr"
    109 
    110 echo "===== Testing with \\\\r\\\\n line terminators (DOS format) ====="
    111 
    112 # Prepare test files with '\r\n' instead of '\n'
    113 rm -rf ./subtest-cr-lf
    114 mkdir subtest-cr-lf
    115 for file in "$testdir"/*.c; do
    116     base=$(basename "$file")
    117     sed -e 's/$/
/' < "$file" > subtest-cr-lf/"$base"
    119     cp $abs_builddir/glsl/glcpp/tests/subtest-lf/"$base".out subtest-cr-lf/"$base".expected
    120 done
    121 
    122 run_test "${glcpp_test} --testdir=subtest-cr-lf"
    123 
    124 echo "===== Testing with \\\\n\\\\r (bizarre, but allowed by GLSL spec.) ====="
    125 
    126 # Prepare test files with '\n\r' instead of '\n'
    127 rm -rf ./subtest-lf-cr
    128 mkdir subtest-lf-cr
    129 for file in "$testdir"/*.c; do
    130     base=$(basename "$file")
    131     sed -e 's/$/
/' < "$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
    134 done
    135 
    136 run_test "${glcpp_test} --testdir=subtest-lf-cr"
    137 
    138 if [ $total -eq 0 ]; then
    139     echo "Could not find any tests."
    140     exit 1
    141 fi
    142 
    143 echo ""
    144 echo "$pass/$total tests returned correct results"
    145 echo ""
    146 
    147 if [ "$pass" = "$total" ]; then
    148     exit 0
    149 else
    150     exit 1
    151 fi
    152