| 1 | #!/bin/sh | 
| 2 |  | 
| 3 | if [ "$#" = 0 ]; then | 
| 4 | getopt=./getopt | 
| 5 | elif [ "$#" = 1 ]; then | 
| 6 | getopt="$1" | 
| 7 | else | 
| 8 | echo "Syntax: $0 [ PATH_TO_GETOPT ]" 2>&1 | 
| 9 | exit 2 | 
| 10 | fi | 
| 11 |  | 
| 12 | # Reset the environment | 
| 13 | LC_ALL="C" | 
| 14 | unset LANG | 
| 15 | unset LC_CTYPE | 
| 16 | unset LC_COLLATE | 
| 17 | unset LC_MESSAGES | 
| 18 | unset POSIXLY_CORRECT | 
| 19 | unset GETOPT_COMPATIBLE | 
| 20 | cd `dirname $0` | 
| 21 |  | 
| 22 | for testcmd in tests/*.cmd; do | 
| 23 | test_failed=0 | 
| 24 | rm -f test-stdout test-stderr test-stdout-expected test-stderr-expected | 
| 25 |  | 
| 26 | testfile=`basename "$testcmd" .cmd` | 
| 27 |  | 
| 28 | echo "Next test: $testfile" | 
| 29 | "tests/${testfile}.cmd" "$getopt" > test-stdout 2>test-stderr | 
| 30 | exitcode="$?" | 
| 31 |  | 
| 32 | if [ "$exitcode" != "`cat tests/${testfile}.exitcode`" ]; then | 
| 33 | echo "TEST FAILED: expected exit code `cat tests/${testfile}.exitcode`, got $exitcode" | 
| 34 | test_failed=1 | 
| 35 | else | 
| 36 | echo "Received expected exit code" | 
| 37 | fi | 
| 38 |  | 
| 39 | cat tests/${testfile}.stdout | sed "s,\$0,$getopt,g" > test-stdout-expected | 
| 40 | if ! cmp -s test-stdout test-stdout-expected ; then | 
| 41 | echo "TEST FAILED: unexpected stdout output, diff follows:" | 
| 42 | diff test-stdout test-stdout-expected | 
| 43 | test_failed=1 | 
| 44 | else | 
| 45 | echo "Received expected stdout output" | 
| 46 | fi | 
| 47 |  | 
| 48 | cat tests/${testfile}.stderr | sed "s,\$0,$getopt,g" > test-stderr-expected | 
| 49 | if ! cmp -s test-stderr test-stderr-expected ; then | 
| 50 | echo "TEST FAILED: unexpected stdout output, diff follows:" | 
| 51 | diff test-stderr test-stderr-expected | 
| 52 | test_failed=1 | 
| 53 | else | 
| 54 | echo "Received expected stderr output" | 
| 55 | fi | 
| 56 | echo | 
| 57 |  | 
| 58 | if [ "$test_failed" = 1 ]; then | 
| 59 | failed_tests="$failed_tests $testfile" | 
| 60 | fi | 
| 61 | rm -f test-stdout test-stderr test-stdout-expected test-stderr-expected | 
| 62 | echo | 
| 63 | done | 
| 64 |  | 
| 65 | if [ -z "$failed_tests" ]; then | 
| 66 | echo "ALL TESTS SUCCEEDED" | 
| 67 | exit 0 | 
| 68 | else | 
| 69 | echo "SOME TESTS FAILED: $failed_tests" | 
| 70 | exit 1 | 
| 71 | fi |