blob: 3e3619147fabb85348278eb3c3420b468b3c5d06 [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
epoger@google.coma413a532012-11-12 18:04:51 +00005
6# cd into .../trunk so all the paths will work
7cd $(dirname $0)/../..
epoger@google.coma2b793c2012-05-15 14:58:53 +00008
9# TODO: make it look in Release and/or Debug
10SKDIFF_BINARY=out/Debug/skdiff
11
epoger@google.coma4443522012-05-17 17:12:38 +000012# 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.coma2b793c2012-05-15 14:58:53 +000017function compare_directories {
epoger@google.coma413a532012-11-12 18:04:51 +000018 if [ $# != 2 ]; then
19 echo "compare_directories requires exactly 2 parameters, got $#"
20 exit 1
21 fi
epoger@google.coma2b793c2012-05-15 14:58:53 +000022 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.coma4443522012-05-17 17:12:38 +000029# 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.
32function skdiff_test {
epoger@google.coma413a532012-11-12 18:04:51 +000033 if [ $# != 2 ]; then
34 echo "skdiff_test requires exactly 2 parameters, got $#"
35 exit 1
36 fi
epoger@google.coma4443522012-05-17 17:12:38 +000037 SKDIFF_ARGS="$1"
38 ACTUAL_OUTPUT_DIR="$2/output-actual"
39 EXPECTED_OUTPUT_DIR="$2/output-expected"
epoger@google.coma2b793c2012-05-15 14:58:53 +000040
epoger@google.coma4443522012-05-17 17:12:38 +000041 rm -rf $ACTUAL_OUTPUT_DIR
42 mkdir -p $ACTUAL_OUTPUT_DIR
epoger@google.com90cb9b32012-05-18 18:25:26 +000043 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.coma4443522012-05-17 17:12:38 +000048 compare_directories $EXPECTED_OUTPUT_DIR $ACTUAL_OUTPUT_DIR
49}
50
51SKDIFF_TESTDIR=tools/tests/skdiff
epoger@google.com8e4e51d2012-05-30 19:12:45 +000052
epoger@google.comdfbf24e2012-07-13 21:22:02 +000053# Run skdiff over a variety of file pair types: identical bits, identical pixels, missing from
54# baseDir, etc.
epoger@google.coma4443522012-05-17 17:12:38 +000055skdiff_test "$SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test1"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000056
epoger@google.comdfbf24e2012-07-13 21:22:02 +000057# 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.com46a45962012-07-12 18:16:02 +000060# - list filenames with each result type to stdout
61# - don't generate HTML output files
epoger@google.comdfbf24e2012-07-13 21:22:02 +000062skdiff_test "--failonresult DifferentPixels --failonresult DifferentSizes --failonresult DifferentOther --failonresult Unknown --listfilenames --nodiffs $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/test2"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000063
epoger@google.comdfbf24e2012-07-13 21:22:02 +000064# Run skdiff over just the files that have identical bits.
65skdiff_test "--nodiffs --match identical-bits $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000066
epoger@google.comdfbf24e2012-07-13 21:22:02 +000067# Run skdiff over just the files that have identical bits or identical pixels.
68skdiff_test "--nodiffs --match identical-bits --match identical-pixels $SKDIFF_TESTDIR/baseDir $SKDIFF_TESTDIR/comparisonDir" "$SKDIFF_TESTDIR/identical-bits-or-pixels"
epoger@google.com8e4e51d2012-05-30 19:12:45 +000069
epoger@google.coma2b793c2012-05-15 14:58:53 +000070echo "All tests passed."