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 |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame^] | 5 | |
| 6 | # cd into .../trunk so all the paths will work |
| 7 | cd $(dirname $0)/../.. |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 8 | |
| 9 | # TODO: make it look in Release and/or Debug |
| 10 | SKDIFF_BINARY=out/Debug/skdiff |
| 11 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 12 | # Compare contents of all files within directories $1 and $2, |
| 13 | # EXCEPT for any dotfiles. |
| 14 | # If there are any differences, a description is written to stdout and |
| 15 | # we exit with a nonzero return value. |
| 16 | # Otherwise, we write nothing to stdout and return. |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 17 | function compare_directories { |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame^] | 18 | if [ $# != 2 ]; then |
| 19 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 20 | exit 1 |
| 21 | fi |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 22 | diff --exclude=.* $1 $2 |
| 23 | if [ $? != 0 ]; then |
| 24 | echo "failed in: compare_directories $1 $2" |
| 25 | exit 1 |
| 26 | fi |
| 27 | } |
| 28 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 29 | # Run skdiff with arguments in $1 (plus implicit final argument causing skdiff |
| 30 | # to write its output, if any, to directory $2/output-actual). |
| 31 | # Then compare its results against those in $2/output-expected. |
| 32 | function skdiff_test { |
epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame^] | 33 | if [ $# != 2 ]; then |
| 34 | echo "skdiff_test requires exactly 2 parameters, got $#" |
| 35 | exit 1 |
| 36 | fi |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 37 | SKDIFF_ARGS="$1" |
| 38 | ACTUAL_OUTPUT_DIR="$2/output-actual" |
| 39 | EXPECTED_OUTPUT_DIR="$2/output-expected" |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 40 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 41 | rm -rf $ACTUAL_OUTPUT_DIR |
| 42 | mkdir -p $ACTUAL_OUTPUT_DIR |
epoger@google.com | 90cb9b3 | 2012-05-18 18:25:26 +0000 | [diff] [blame] | 43 | COMMAND="$SKDIFF_BINARY $SKDIFF_ARGS $ACTUAL_OUTPUT_DIR" |
| 44 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| 45 | $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout |
| 46 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 47 | |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 48 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 49 | } |
| 50 | |
| 51 | SKDIFF_TESTDIR=tools/tests/skdiff |
epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 52 | |
epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 53 | # Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from |
| 54 | # baseDir, etc. |
epoger@google.com | a444352 | 2012-05-17 17:12:38 +0000 | [diff] [blame] | 55 | skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1" |
epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 56 | |
epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 57 | # Run skdiff over the same set of files, but with arguments as used by our buildbots: |
| 58 | # - return the number of mismatching file pairs (but ignore any files missing from either |
| 59 | # baseDir or comparisonDir) |
epoger@google.com | 46a4596 | 2012-07-12 18:16:02 +0000 | [diff] [blame] | 60 | # - list filenames with each result type to stdout |
| 61 | # - don't generate HTML output files |
epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 62 | skdiff_test "--failonresult DifferentPixels --failonresult DifferentSizes --failonresult DifferentOther --failonresult Unknown --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2" |
epoger@google.com | 8e4e51d | 2012-05-30 19:12:45 +0000 | [diff] [blame] | 63 | |
epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 64 | # Run skdiff over just the files that have identical bits. |
| 65 | skdiff_test "--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] | 66 | |
epoger@google.com | dfbf24e | 2012-07-13 21:22:02 +0000 | [diff] [blame] | 67 | # Run skdiff over just the files that have identical bits or identical pixels. |
| 68 | skdiff_test "--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] | 69 | |
epoger@google.com | a2b793c | 2012-05-15 14:58:53 +0000 | [diff] [blame] | 70 | echo "All tests passed." |