-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·62 lines (50 loc) · 1.46 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·62 lines (50 loc) · 1.46 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
#!/usr/bin/env bash
ILO="./build/ilo"
echo "[INFO] $(sha1sum $ILO)"
for file in $(find tests/*.ilo -maxdepth 1 -not -type d); do
# Compile
echo -n "[TEST] $(sha1sum $file).. "
$ILO --verify-memory $file > test.asm
nasm -felf64 test.asm -o test.o
ld -o test test.o
# Get metadata
DESCRIPTION="$(grep '^# Description:' $file | cut -d: -f2-)"
ARGS="$(grep '^# Args:' $file | cut -d: -f2-)"
EXPECTED_EXIT_CODE="$(
printf "%b" "$(grep '^# Exit code:' $file | cut -d: -f2-)"
)"
EXPECTED_STDOUT="$(
printf "%b" "$(grep '^# Stdout:' $file | cut -d: -f2-)"
)"
EXPECTED_STDERR="$(
printf "%b" "$(grep '^# Stderr:' $file | cut -d: -f2-)"
)"
# Run test
EXIT_CODE="$(./test $ARGS > /dev/null 2>&1; echo $?)"
STDOUT="$(./test $ARGS 2>/dev/null)"
STDERR="$(./test $ARGS 2>&1 1>/dev/null)"
# Verify results
SUCCESS=1
if [ "$EXIT_CODE" != "$EXPECTED_EXIT_CODE" ]; then
echo "[FAIL] Test: $DESCRIPTION. Exit code: $EXIT_CODE (not $EXPECTED_EXIT_CODE)"
SUCCESS=0
fi
if [ "$STDOUT" != "$EXPECTED_STDOUT" ]; then
echo "[FAIL] Test: $DESCRIPTION. Stdout: $STDOUT (not $EXPECTED_STDOUT)"
SUCCESS=0
fi
if [ "$STDERR" != "$EXPECTED_STDERR" ]; then
echo "[FAIL] Test: $DESCRIPTION. Stderr: $STDERR (not $EXPECTED_STDERR)"
SUCCESS=0
fi
if [[ "$SUCCESS" -eq 1 ]]; then
echo "OK"
fi
# Cleanup
rm test test.o test.asm
if [[ "$SUCCESS" -eq 0 ]]; then
echo "Test failed!"
exit 1
fi
done
echo "All tests OK!"