blob: f6dbe27ca8c81669db65611d773c324bb37d0a19 [file] [log] [blame]
epoger@google.coma2b793c2012-05-15 14:58:53 +00001#!/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
8SKDIFF_BINARY=out/Debug/skdiff
9
epoger@google.coma4443522012-05-17 17:12:38 +000010# 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.coma2b793c2012-05-15 14:58:53 +000015function 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.coma4443522012-05-17 17:12:38 +000023# 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.
26function skdiff_test {
27 SKDIFF_ARGS="$1"
28 ACTUAL_OUTPUT_DIR="$2/output-actual"
29 EXPECTED_OUTPUT_DIR="$2/output-expected"
epoger@google.coma2b793c2012-05-15 14:58:53 +000030
epoger@google.coma4443522012-05-17 17:12:38 +000031 rm -rf $ACTUAL_OUTPUT_DIR
32 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com90cb9b32012-05-18 18:25:26 +000033 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.coma4443522012-05-17 17:12:38 +000038 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
39}
40
41SKDIFF_TESTDIR=tools/tests/skdiff
epoger@google.com8e4e51d2012-05-30 19:12:45 +000042
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.coma4443522012-05-17 17:12:38 +000046skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000047
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.com90cb9b32012-05-18 18:25:26 +000050skdiff_test "--nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000051
52# Run skdiff over just the files that have identical bits, to validate any
53# behavior/return value differences in this case.
54skdiff_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.
58skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"
59
epoger@google.coma2b793c2012-05-15 14:58:53 +000060echo "All tests passed."