box-o-sand/lcthw-remnants/test_ex24_iofunctions.sh

57 lines
1.0 KiB
Bash
Raw Normal View History

#!/bin/bash
EXIT_CODE=0
run_test()
{
echo -n " $1"
out_tmp="$(mktemp)"
./ex24_iofunctions$1 < "$2" > "$out_tmp"
diff_out="$(mktemp)"
diff -u "$3" "$out_tmp" > "$diff_out"
diff_count="$(cat "$diff_out" | wc -l)"
if [[ "$?" == "0" ]] && [[ "$diff_count" == "0" ]]
then
echo " ... OK"
else
echo " ... FAIL"
echo " diff count => $diff_count"
cat "$diff_out"
EXIT_CODE=1
fi
rm -f "$2" "$out_tmp" "$diff_out"
}
tmp_01="$(mktemp)"
cat > "$tmp_01" <<EOF
2 8 n
EOF
expected_01="$(mktemp)"
cat > "$expected_01" <<EOF
Reading from stdin: <a:number> <b:number> <c:letter>
> Read in: a=2 b=8 c=n
EOF
tmp_02="$(mktemp)"
tmp_02in="$(mktemp)"
cat > "$tmp_02in" <<EOF
1 4 a
EOF
cat > "$tmp_02" <<EOF
$tmp_02in
EOF
expected_02="$(mktemp)"
cat > "$expected_02" <<EOF
Provide filename from which to inputs
> Reading from file: <a:number> <b:number> <c:letter>
Read in: a=1 b=4 c=a
EOF
run_test '01' "$tmp_01" "$expected_01"
run_test '02' "$tmp_02" "$expected_02"
exit $EXIT_CODE