Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
#!/bin/bash
2
 
3
#
4
# Name: testCases.sh
5
# Version: $Id: testCases.sh,v 1.2 2006-10-29 12:09:41 lukasfeiler Exp $
6
#
7
 
8
printUsage()
9
{
10
    echo "testCases.sh [-C] [-f FIRST_CASE] [-c CASES] [-u BASE_URL] [-L CASES_LOCATION]" >&2
11
    echo " -C                   Clean up old files first" >&2
12
    echo " -f FIRST_CASE        Case number to start with; default is 1" >&2
13
    echo " -c CASES             Number of cases; default is 5" >&2
14
    echo " -u BASE_URL          The URL of the cases directory; default" >&2
15
    echo "                      is http://localhost/Query2XML/cases" >&2
16
    echo " -L CASES_LOCATION    The path to all case directories; default" >&2
17
    echo "                      is ../cases." >&2
18
    echo "" >&2
19
    echo "This script tests all eight cases by running all of them and" >&2
20
    echo "comparing their output to the XML files in the specified" >&2
21
    echo 'case directory. $BASE_URL/case$i/case$i.php is requested for' >&2
22
    echo "this purpose." >&2
23
}
24
 
25
CASE_COUNT=8
26
FIRST_CASE=1
27
BASE_URL="http://localhost/Query2XML/cases"
28
CASES_LOCATION="../cases"
29
while getopts ":Cf:c:u:L:" opt; do
30
    case $opt in
31
        C ) CLEANUP=true ;;
32
        f ) FIRST_CASE=$OPTARG
33
            CASE_COUNT=1;;
34
        c ) CASE_COUNT=$OPTARG ;;
35
        u ) BASE_URL=$OPTARG ;;
36
        L ) CASES_LOCATION=$OPTARG ;;
37
        ? ) printUsage
38
            exit 1 ;;
39
    esac
40
done
41
 
42
CASES_DIR=`(cd $CASES_LOCATION; pwd)`
43
TMP_FILE=$CASES_DIR/test.tmp
44
 
45
if [ "$CLEANUP" = "true" ] ; then
46
    echo -n "Cleanung up ... "
47
    i=1
48
    while [ $i -lt $CASE_COUNT ] ; do
49
        [ $i -lt 10 ] && i="0$i"
50
        rm -f case$i.xml
51
        rm -f case$i.xml.diff
52
        i=$((i + 1))
53
    done
54
    echo OK
55
fi
56
 
57
if [ "`find . -maxdepth 1 -name 'case[0-9]*.*'`" != "" ] ; then
58
  echo "The following old case[0-9]*.* files need to be removed first:"
59
  find . -name 'case[0-9]*.*'
60
  exit 1
61
fi
62
 
63
 
64
i=$FIRST_CASE
65
MAX=$(($FIRST_CASE + $CASE_COUNT))
66
ERRORS=0
67
while [ $i -lt $MAX ] ; do
68
    [ $i -lt 10 ] && i="0$i"
69
    echo -n "Testing Case $i...   "
70
    wget -O case$i.xml $BASE_URL/case$i/case$i.php >$TMP_FILE 2>&1;ret=$?
71
    if [ $ret -ne 0 ] ; then
72
        echo "Could not download $BASE_URL/case$i/case$i.php:"
73
        cat $TMP_FILE
74
        rm -f $TMP_FILE
75
        exit 1
76
    fi
77
    rm -f $TMP_FILE
78
 
79
    echo "download OK"
80
    echo -n " diffing case$i.xml...         "
81
    diff -u case$i.xml $CASES_DIR/case$i/case$i.xml > case$i.xml.diff 2>&1;ret=$?
82
    if [ $ret -eq 0 ] ; then
83
        echo "OK"
84
        rm -f case$i.xml case$i.xml.diff
85
    else
86
        echo "ERROR: diff returned $ret: see case$i.xml.diff"
87
        ERRORS=$((ERRORS + 1))
88
    fi
89
 
90
    i=${i##0}
91
    i=$((i + 1))
92
done
93
 
94
rm -f $TMP_FILE
95
 
96
 
97
echo -n "Summary: "
98
if [ $ERRORS -eq 0 ] ; then
99
    echo "all OK"
100
else
101
    echo "$ERRORS errors"
102
fi