Brian Silverman | 70325d6 | 2015-09-20 17:00:43 -0400 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2008, Google Inc. |
| 4 | # All rights reserved. |
| 5 | # |
| 6 | # Redistribution and use in source and binary forms, with or without |
| 7 | # modification, are permitted provided that the following conditions are |
| 8 | # met: |
| 9 | # |
| 10 | # * Redistributions of source code must retain the above copyright |
| 11 | # notice, this list of conditions and the following disclaimer. |
| 12 | # * Redistributions in binary form must reproduce the above |
| 13 | # copyright notice, this list of conditions and the following disclaimer |
| 14 | # in the documentation and/or other materials provided with the |
| 15 | # distribution. |
| 16 | # * Neither the name of Google Inc. nor the names of its |
| 17 | # contributors may be used to endorse or promote products derived from |
| 18 | # this software without specific prior written permission. |
| 19 | # |
| 20 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | # --- |
| 32 | # |
| 33 | # Author: falmeida@google.com (Filipe Almeida) |
| 34 | |
| 35 | die() { |
| 36 | echo "Test failed: $@" 1>&2 |
| 37 | exit 1 |
| 38 | } |
| 39 | TEST_SRCDIR=${1:-$TEST_SRCDIR} |
| 40 | TOOLS_DIR="$TEST_SRCDIR/src/htmlparser" |
| 41 | TESTDATA_DIR="$TEST_SRCDIR/src/tests/htmlparser_testdata" |
| 42 | |
| 43 | # Find input files |
| 44 | INPUT_FILE="$TESTDATA_DIR/sample_fsm.config" |
| 45 | OUTPUT_FILE="$TESTDATA_DIR/sample_fsm.c" |
| 46 | GENERATE_FSM="$TOOLS_DIR/generate_fsm.py" |
| 47 | |
| 48 | EXPECTED="`cat $OUTPUT_FILE`" |
| 49 | if [ -z "$EXPECTED" ]; then die "Error reading $OUTPUT_FILE"; fi |
| 50 | |
| 51 | # Let's make sure the script works with python2.2 and above |
| 52 | for PYTHON in "" "python2.2" "python2.3" "python2.4" "python2.5" "python2.6"; do |
| 53 | # Skip the versions of python that are not installed. |
| 54 | if [ -n "$PYTHON" ]; then |
| 55 | $PYTHON -h >/dev/null 2>/dev/null || continue |
| 56 | else # use the python that's in the shebang line |
| 57 | SHEBANG_PYTHON=`head -n1 "$GENERATE_FSM" | tr -d '#!'` |
| 58 | # SHEBANG_PYTHON could be something like "env python" so don't quotify it |
| 59 | $SHEBANG_PYTHON -h >/dev/null 2>/dev/null || continue |
| 60 | fi |
| 61 | echo "-- Running $PYTHON $GENERATE_FSM $INPUT_FILE" |
| 62 | # The tr is to get rid of windows-style line endings (\r) |
| 63 | GENERATED="`$PYTHON $GENERATE_FSM $INPUT_FILE | tr -d '\015'`" |
| 64 | if [ -z "$GENERATED" ]; then die "Error running $GENERATE_FSM"; fi |
| 65 | |
| 66 | if [ "$EXPECTED" != "$GENERATED" ]; then |
| 67 | echo "Test failed ($PYTHON $GENERATE_FSM $INPUT_FILE)" 1>&2 |
| 68 | echo "-- EXPECTED --" 1>&2 |
| 69 | echo "$EXPECTED" 1>&2 |
| 70 | echo "-- GENERATED --" 1>&2 |
| 71 | echo "$GENERATED" 1>&2 |
| 72 | echo "--" |
| 73 | exit 1 |
| 74 | fi |
| 75 | done |
| 76 | |
| 77 | echo "PASS" |