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