-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·104 lines (81 loc) · 2.6 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·104 lines (81 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env bash
# No not run this script directly, use make test instead.
BINARY=$(dirname "$0")/tur
for INPUT_FILE in "$(dirname "$0")"/examples/simpleTests/*.in "$(dirname "$0")"/examples/*.in ; do
MACHINE_FILE=$(sed -E 's/(.*)\.in/\1.tm/' <<< "$INPUT_FILE")
OPTIMIZED_MACHINE_FILE=$(sed -E 's/(.*)\.in/\1.O.tm/' <<< "$INPUT_FILE")
OUTPUT_FILE=$(sed -E 's/(.*)\.in/\1.out/' <<< "$INPUT_FILE")
LINES_COUNT=$(wc -l < "$INPUT_FILE")
printf 'Machines: %s, %s\n' "$MACHINE_FILE" "$OPTIMIZED_MACHINE_FILE" >&2
if [ \! -f "$INPUT_FILE" ] ; then
echo "Input file isn’t a regular file." >&2
exit 1
fi
if [ \! -r "$INPUT_FILE" ] ; then
echo "Input file cannot be read." >&2
exit 1
fi
if [ \! -e "$OUTPUT_FILE" ] ; then
echo "Output file doesn’t exist." >&2
exit 1
fi
if [ \! -f "$OUTPUT_FILE" ] ; then
echo "Output file isn’t a regular file." >&2
exit 1
fi
if [ \! -r "$OUTPUT_FILE" ] ; then
echo "Output file cannot be read." >&2
exit 1
fi
if [ \! -e "$MACHINE_FILE" ] ; then
echo "Machine file doesn’t exist." >&2
exit 1
fi
if [ \! -f "$MACHINE_FILE" ] ; then
echo "Machine file isn’t a regular file." >&2
exit 1
fi
if [ \! -r "$MACHINE_FILE" ] ; then
echo "Machine file cannot be read." >&2
exit 1
fi
if [ \! -e "$OPTIMIZED_MACHINE_FILE" ] ; then
echo "Optimized machine file doesn’t exist." >&2
exit 1
fi
if [ \! -f "$OPTIMIZED_MACHINE_FILE" ] ; then
echo "Optimized machine file isn’t a regular file." >&2
exit 1
fi
if [ \! -r "$OPTIMIZED_MACHINE_FILE" ] ; then
echo "Optimized machine file cannot be read." >&2
exit 1
fi
if (($(wc -l < "$OUTPUT_FILE")!=LINES_COUNT)) ; then
echo "Input and output lines don’t match." >&2
exit 1
fi
for ((X = 1; X <= LINES_COUNT; X++)) ; do
INPUT=$(head -n "$X" "$INPUT_FILE" | tail -n 1)
REF_OUTPUT=$(head -n "$X" "$OUTPUT_FILE" | tail -n 1)
OUTPUT=$("$BINARY" -rn --no-color "$MACHINE_FILE" 2> /dev/null <<< "$INPUT")
if (($?!=0)) ; then
printf 'Unoptimized machine:\nInput: %s\nInvalid output.\n' "$INPUT" >&2
exit 2
fi
if [ "$OUTPUT" != "$REF_OUTPUT" ] ; then
printf 'Unoptimized machine:\nInput: %s\nReference output: %s\nOutput: %s\n' "$INPUT" "$REF_OUTPUT" "$OUTPUT" >&2
exit 2
fi
OUTPUT=$("$BINARY" -rn --no-color "$OPTIMIZED_MACHINE_FILE" 2> /dev/null <<< "$INPUT")
if (($?!=0)) ; then
printf 'Optimized machine:\nInput: %s\nInvalid output.\n' "$INPUT" >&2
exit 2
fi
if [ "$OUTPUT" != "$REF_OUTPUT" ] ; then
printf 'Optimized machine:\nInput: %s\nReference output: %s\nOutput: %s\n' "$INPUT" "$REF_OUTPUT" "$OUTPUT" >&2
exit 2
fi
done
echo "OK" >&2
done