Shell script- regression testing [Archive] - C Board

PDA

View Full Version : Shell script- regression testing


kiss2rvp
05-19-2002, 02:28 AM
I'm a beginner at shell scripts and i want to build a suite of tests so that all of the tests that have been executed on my program in the past can be executed on it again to check against bugs in a program.

So basically the shell script runs a program with given inputs and compares the output with some expected output.

I want the shell script to execute all tests instead of typing a command like this every time...
./this_program < input-1 > actual-output-1
diff actual-output-1 expected-output-1

Im thinking of using loops to interate over each case of a lot of inputs (input-1, input-2,...) and a lot of expected outputs (expected-output-1, expected-output-2,...) and I want it to be able to take the name of the program to invoke, the number of tests, and the directory that the tests they are in so i can test any program easily......I just don't know how to start the actual coding and the structure of it and use the name of the program etc..

Can anyone please help???

Salem
05-19-2002, 04:15 AM
Rather than counting 1,2,3 etc, just assume that all the files in a directory are test files and test result files.

By using known file suffixes, you can easily tell them apart, and also derive one from the other.


prog=`pwd`/$1
dir=$2

cd $2

# for each .txt input file, there is a .res file
# containing the expected results
for i in *.txt; do
res=`basename $i .txt`.res
$prog < $i > tmp
diff $res tmp
done