epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Tests for our tools. |
| 4 | # TODO: for now, it only tests skdiff |
| 5 | # TODO: for now, assumes that it is being run from .../trunk |
| 6 | |
| 7 | # TODO: make it look in Release and/or Debug |
| 8 | SKDIFF_BINARY=out/Debug/skdiff |
| 9 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 10 | # Compare contents of all files within directories $1 and $2, |
| 11 | # EXCEPT for any dotfiles. |
| 12 | # If there are any differences, a description is written to stdout and |
| 13 | # we exit with a nonzero return value. |
| 14 | # Otherwise, we write nothing to stdout and return. |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 15 | function compare_directories { |
| 16 | diff --exclude=.* $1 $2 |
| 17 | if [ $? != 0 ]; then |
| 18 | echo "failed in: compare_directories $1 $2" |
| 19 | exit 1 |
| 20 | fi |
| 21 | } |
| 22 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 23 | # Run skdiff with arguments in $1 (plus implicit final argument causing skdiff |
| 24 | # to write its output, if any, to directory $2/output-actual). |
| 25 | # Then compare its results against those in $2/output-expected. |
| 26 | function skdiff_test { |
| 27 | SKDIFF_ARGS="$1" |
| 28 | ACTUAL_OUTPUT_DIR="$2/output-actual" |
| 29 | EXPECTED_OUTPUT_DIR="$2/output-expected" |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 30 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 31 | rm -rf $ACTUAL_OUTPUT_DIR |
| 32 | mkdir -p $ACTUAL_OUTPUT_DIR |
epoger@google.com | 90cb9b3 | 2012-05-18 18:25:26 +0000 | [diff] [blame] | 33 | COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR" |
| 34 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| 35 | $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout |
| 36 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 37 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 38 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 39 | } |
| 40 | |
| 41 | SKDIFF_TESTDIR=tools/tests/skdiff |
epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame^] | 42 | |
| 43 | # Run skdiff over a variety of file pair types: identical bits, identical |
| 44 | # pixels, missing from baseDir, etc. |
| 45 | # TODO: In the near future, skdiff will return a nonzero exit code in this case. |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 46 | skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1" |
epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame^] | 47 | |
| 48 | # Same as above but without generating HTML output files. |
| 49 | # TODO: In the near future, skdiff will return a nonzero exit code in this case. |
epoger@google.com | 90cb9b3 | 2012-05-18 18:25:26 +0000 | [diff] [blame] | 50 | skdiff_test "--nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2" |
epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame^] | 51 | |
| 52 | # Run skdiff over just the files that have identical bits, to validate any |
| 53 | # behavior/return value differences in this case. |
| 54 | skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits" |
| 55 | |
| 56 | # Run skdiff over just the files that have identical bits or identical pixels, |
| 57 | # to validate any behavior/return value differences in this case. |
| 58 | skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels" |
| 59 | |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 60 | echo "All tests passed." |