parent
b5b0213c5d
commit
2e0a5d5c99
@ -0,0 +1,19 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "dbg.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
int a, b, rc;
|
||||||
|
char c;
|
||||||
|
printf("Reading from stdin: <a:number> <b:number> <c:letter>\n> ");
|
||||||
|
rc = fscanf(stdin, "%d %d %c", &a, &b, &c);
|
||||||
|
check(rc == 3, "Failed to read from stdin.");
|
||||||
|
|
||||||
|
printf("Read in: a=%d b=%d c=%c\n", a, b, c);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
return 1;
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
#!/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
|
Loading…
Reference in new issue