| 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. |
| epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 45 | skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 46 | |
| epoger@google.com | 46a4596 | 2012-07-12 18:16:02 +0000 | [diff] [blame^] | 47 | # Same as above, except: |
| 48 | # - return the number of mismatching file pairs |
| 49 | # - list filenames with each result type to stdout |
| 50 | # - don't generate HTML output files |
| 51 | skdiff_test "--failonmismatches --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 52 | |
| 53 | # Run skdiff over just the files that have identical bits, to validate any |
| 54 | # behavior/return value differences in this case. |
| epoger@google.com | 46a4596 | 2012-07-12 18:16:02 +0000 | [diff] [blame^] | 55 | skdiff_test "--failonmismatches --nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 56 | |
| 57 | # Run skdiff over just the files that have identical bits or identical pixels, |
| 58 | # to validate any behavior/return value differences in this case. |
| epoger@google.com | 46a4596 | 2012-07-12 18:16:02 +0000 | [diff] [blame^] | 59 | skdiff_test "--failonmismatches --nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels" |
| epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 60 | |
| epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 61 | echo "All tests passed." |