epoger@google.com | a413a53 | 2012-11-12 18:04:51 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Self-tests for gm, based on tools/tests/run.sh |
| 4 | |
| 5 | # cd into .../trunk so all the paths will work |
| 6 | cd $(dirname $0)/../.. |
| 7 | |
| 8 | # TODO(epoger): make it look in Release and/or Debug |
| 9 | GM_BINARY=out/Debug/gm |
| 10 | |
| 11 | # Compare contents of all files within directories $1 and $2, |
| 12 | # EXCEPT for any dotfiles. |
| 13 | # If there are any differences, a description is written to stdout and |
| 14 | # we exit with a nonzero return value. |
| 15 | # Otherwise, we write nothing to stdout and return. |
| 16 | function compare_directories { |
| 17 | if [ $# != 2 ]; then |
| 18 | echo "compare_directories requires exactly 2 parameters, got $#" |
| 19 | exit 1 |
| 20 | fi |
| 21 | diff -r --exclude=.* $1 $2 |
| 22 | if [ $? != 0 ]; then |
| 23 | echo "failed in: compare_directories $1 $2" |
| 24 | exit 1 |
| 25 | fi |
| 26 | } |
| 27 | |
| 28 | # Run gm... |
| 29 | # - with the arguments in $1 |
| 30 | # - writing resulting images into $2/output-actual/images |
| 31 | # - writing stdout into $2/output-actual/stdout |
| 32 | # - writing return value into $2/output-actual/return_value |
| 33 | # Then compare all of those against $2/output-expected . |
| 34 | function gm_test { |
| 35 | if [ $# != 2 ]; then |
| 36 | echo "gm_test requires exactly 2 parameters, got $#" |
| 37 | exit 1 |
| 38 | fi |
| 39 | GM_ARGS="$1" |
| 40 | ACTUAL_OUTPUT_DIR="$2/output-actual" |
| 41 | EXPECTED_OUTPUT_DIR="$2/output-expected" |
| 42 | |
| 43 | rm -rf $ACTUAL_OUTPUT_DIR |
| 44 | mkdir -p $ACTUAL_OUTPUT_DIR |
| 45 | COMMAND="$GM_BINARY $GM_ARGS -w $ACTUAL_OUTPUT_DIR/images" |
| 46 | echo "$COMMAND" >$ACTUAL_OUTPUT_DIR/command_line |
| 47 | $COMMAND &>$ACTUAL_OUTPUT_DIR/stdout |
| 48 | echo $? >$ACTUAL_OUTPUT_DIR/return_value |
| 49 | |
| 50 | compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR |
| 51 | } |
| 52 | |
| 53 | GM_TESTDIR=gm/tests |
| 54 | GM_INPUTS=$GM_TESTDIR/inputs |
| 55 | GM_OUTPUTS=$GM_TESTDIR/outputs |
| 56 | |
| 57 | gm_test "--hierarchy --match dashing --config 4444 -r $GM_INPUTS/dashing-correct-images" "$GM_OUTPUTS/dashing-compared-against-correct" |
| 58 | |
| 59 | # In this case, dashing.png has different pixels, but dashing2.png differs only in PNG encoding (identical pixels) |
| 60 | gm_test "--hierarchy --match dashing --config 4444 -r $GM_INPUTS/dashing-incorrect-images" "$GM_OUTPUTS/dashing-compared-against-incorrect" |
| 61 | |
| 62 | echo "All tests passed." |