You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
box-o-sand/oldstuff/lcthw-remnants/test_ex24_iofunctions.sh

57 lines
1.0 KiB

#!/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