File: runtest

package info (click to toggle)
xmlformat 1.04-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,012 kB
  • sloc: xml: 2,289; perl: 996; ruby: 831; makefile: 109; sh: 65
file content (87 lines) | stat: -rwxr-xr-x 1,717 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /bin/sh

# runtest - run an xmlformat test

# Test scripts are located in ./tests, and are run by naming the basename
# of the input XML file. For example, to run the test for tests/abc.xml,
# invoke "runtest abc".

# The test name "all" runs all tests.

# -p = use ./xmlformat.pl rather than xmlformat.rb
# -r = use ./xmlformat.rb (which is the default anyway)
# -u = update the expected-result file from the actual output file
# -v = verbose

VERBOSE=0
UPDATE=0
CMD=./xmlformat.rb

while [ $# -gt 0 ]; do
	case $1 in
		-p)
			CMD=./xmlformat.pl
			shift
			;;
		-r)
			CMD=./xmlformat.rb
			shift
			;;
		-u)
			UPDATE=1
			shift
			;;
		-v)
			VERBOSE=1
			shift
			;;
		-*)
			echo "Unknown option: $1" 1>&2
			exit 1
			;;
		*)
			break
			;;
	esac
done

if [ $# -eq 0 ]; then
	echo "$0 [-p] [-r] [-u] [-v] test-name" 1>&2
	exit 1
fi

if [ $# -eq 1 -a "x$1" = "xall" ]; then
	if [ $VERBOSE -ne 0 ]; then
		echo "run all tests..." 1>&2
	fi
	TESTS=`(cd tests;ls *.xml|sed -e 's/\.xml//')`
else
	TESTS="$@"
fi

for testname in $TESTS; do
	BASE=tests/$testname
	if [ ! -f $BASE.xml ]; then
		echo "No file $BASE.xml found" 1>&2
		exit 1
	fi
	# use test-specific config file if one exists (else use default)
	# (reset file for each test)
	CONFIG_FILE=
	if [ -f $BASE.conf ]; then
		CONFIG_FILE="--config-file $BASE.conf"
	fi
	# generate output
	if [ $VERBOSE -ne 0 ]; then
		echo "$CMD $CONFIG_FILE $BASE.xml > $BASE.out" 1>&2
	fi
	$CMD $CONFIG_FILE $BASE.xml > $BASE.out
	# if in update mode, update .res file with .out file
	# else compare output to expected result
	if [ $UPDATE -eq 1 ]; then
		echo "Updating $BASE.res from $BASE.out" 1>&2
		cp $BASE.out $BASE.res
	else
		diff -u $BASE.res $BASE.out
	fi
done