a couple of handy parts for unit testing.
[feisty_meow.git] / scripts / unit_test / verify_correct_input.sh
1 #/bin/bash
2
3 # a simple component of unit testing which verifies that the input matches the output.
4
5 # the single parameter to the script is a file that contains the correct answer.
6
7 source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
8
9 answer_file="$1"; shift
10
11 if [ -z "$answer_file" -o ! -f "$answer_file" ]; then
12   echo This script needs a parameter which is a valid file filled with the
13   echo correct version of the input.
14   exit 1
15 fi
16
17 input_save_file="$(mktemp "$TMP/zz_verify_input.XXXXXX")"
18
19 while read line; do
20   echo $line >>"$input_save_file"
21 done
22
23 diff -q "$input_save_file" "$answer_file"
24 if [ $? -ne 0 ]; then
25   sep 76
26   echo "The provided input differs from the correct answer!"
27   echo -e "\nAnswer file has:\n=============="
28   cat "$answer_file"
29   echo -e "==============\nBut the input data has:\n=============="
30   cat "$input_save_file"
31   echo -e "=============="
32   sep 76
33   false  # set bad exit value.
34 fi
35
36 exit $?
37