blob: f7d4bbf56cafec6b2ea90345a2a4b349bbd49d12 [file] [log] [blame]
Chris Lattner0f342da2002-02-01 04:24:47 +00001#!/bin/sh
2#
3# TestRunner.sh - This script is used to run arbitrary unit tests. Unit
4# tests must contain the command used to run them in the input file, starting
5# immediately after a "RUN:" string.
6#
7# This runner recognizes and replaces the following strings in the command:
Chris Lattner9600e8d2003-05-14 18:39:57 +00008#
9# %s - Replaced with the input name of the program, or the program to
10# execute, as appropriate.
Chris Lattner0f342da2002-02-01 04:24:47 +000011#
12
Chris Lattner9600e8d2003-05-14 18:39:57 +000013FILENAME=$1
14SUBST=$1
15OUTPUT=$FILENAME.out
16
17if test $# != 1; then
18 # If more than one parameter is passed in, there must be three parameters:
19 # The filename to read from (already processed), the command used to execute,
20 # and the file to output to.
21 SUBST=$2
22 OUTPUT=$3
23fi
24
25SCRIPT=Output/$OUTPUT.script
26grep 'RUN:' $FILENAME | sed "s|^.*RUN:\(.*\)$|\1|g;s|%s|$SUBST|g" > $SCRIPT
Chris Lattner0f342da2002-02-01 04:24:47 +000027
Chris Lattner004b0532002-02-11 23:32:43 +000028
Chris Lattner9600e8d2003-05-14 18:39:57 +000029/bin/sh $SCRIPT > $OUTPUT 2>&1 || (
30 echo "******************** TEST '$FILENAME' FAILED! ********************"
Chris Lattner004b0532002-02-11 23:32:43 +000031 echo "Command: "
Chris Lattner9600e8d2003-05-14 18:39:57 +000032 cat $SCRIPT
Chris Lattner0f342da2002-02-01 04:24:47 +000033 echo "Output:"
34 cat $OUTPUT
35 rm $OUTPUT
Chris Lattner9600e8d2003-05-14 18:39:57 +000036 echo "******************** TEST '$FILENAME' FAILED! ********************"
Chris Lattner0f342da2002-02-01 04:24:47 +000037)
38