I need a automated method to compare my C++ standard output to the 'expected output' test case files.
In the past I used a shell script that would execute my program by passing input, then comparing the output with grep to plain text. The problem now is that my output spans multiple lines and has much more test cases, making it much easier to compare expected output to a text file.
The test script I used in the past:
./a.out < tests/test01.txt | grep 'EXPECTED OUTPUT EXAMPLE' &> /dev/null
if [ $? == 0 ]; then
echo "ERROR CODE 1.1: OK"
echo "ERROR CODE 1.1: BAD"
At least if you have Gnu diff (as it comes with Linux), which allows to use the special filename
- to denote stdin, you could do
./a.out < tests/test01.txt | diff -- - golden_file.txt
to see the differences between the output of a.out and the contents of golden_file.txt. Of course, variations of this approach are possible. Have a look at the options available for
diff, in particular
Another possibility is to use
cmp instead of