-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrun_tests.sh
More file actions
executable file
·130 lines (112 loc) · 3.75 KB
/
Copy pathrun_tests.sh
File metadata and controls
executable file
·130 lines (112 loc) · 3.75 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/bash
# Usage: run_tests.sh <path-to-kriol-binary> <project-root>
set -e
KRIOL="$1"
ROOT="$2"
if [ -z "$KRIOL" ] || [ -z "$ROOT" ]; then
echo "Usage: run_tests.sh <kriol-binary> <project-root>"
exit 1
fi
echo -e "\n~~ Running tests ~~\n"
pass=0; fail=0
failed_tests=""
record_failure() {
fail=$((fail+1))
failed_tests="${failed_tests}\n - $1"
}
stdin_for() {
local source="$1"
local fixture="${source}.stdin"
if [ -f "$fixture" ]; then
printf '%s' "$fixture"
else
printf '%s' /dev/null
fi
}
# ---- examples/*.kr --------------------------------------------------------
for f in "$ROOT"/examples/*.kriol; do
printf " %-44s" "$f"
tmpbin=$(mktemp /tmp/kriol_XXXX)
stdin_file=$(stdin_for "$f")
if "$KRIOL" "$f" -o "$tmpbin" 2>/dev/null && \
timeout 5 "$tmpbin" < "$stdin_file" > /dev/null 2>&1; then
echo " PASS"; pass=$((pass+1))
else
echo " FAIL"; record_failure "$f"
fi
rm -f "$tmpbin"
done
# ---- tests/pass/*.kr -------------------------------------------------------
if [ -d "$ROOT/tests/pass" ]; then
for f in "$ROOT"/tests/pass/*.kr; do
[ -f "$f" ] || continue
printf " %-44s" "$f"
tmpbin=$(mktemp /tmp/kriol_XXXX)
stdin_file=$(stdin_for "$f")
if "$KRIOL" "$f" -o "$tmpbin" 2>/dev/null && \
timeout 5 "$tmpbin" < "$stdin_file" > /dev/null 2>&1; then
echo " PASS"; pass=$((pass+1))
else
echo " FAIL"; record_failure "$f"
fi
rm -f "$tmpbin"
done
fi
# ---- command-line source text ---------------------------------------------
printf " %-44s" "inline source text"
tmpbin=$(mktemp /tmp/kriol_text_XXXX)
if "$KRIOL" --text 'fn inisiu() { mostran("Kuale, Mundu!"); }' -o "$tmpbin" 2>/dev/null && \
[ "$(timeout 5 "$tmpbin")" = "Kuale, Mundu!" ]; then
echo " PASS"; pass=$((pass+1))
else
echo " FAIL"; record_failure "inline source text"
fi
rm -f "$tmpbin"
# ---- tests/fail/*.kr -------------------------------------------------------
if [ -d "$ROOT/tests/fail" ]; then
for f in "$ROOT"/tests/fail/*.kr; do
[ -f "$f" ] || continue
printf " %-44s" "$f"
tmpbin=$(mktemp /tmp/kriol_fail_bin_XXXX)
if "$KRIOL" "$f" -o "$tmpbin" > /dev/null 2>&1; then
echo " FAIL (should have been rejected)"
record_failure "$f"
else
echo " PASS (rejected)"; pass=$((pass+1))
fi
rm -f "$tmpbin"
done
fi
# ---- wasm32-wasi compile checks --------------------------------------------
if "$KRIOL" --help 2>&1 | grep -Fq "wasm32-wasi"; then
printf " %-44s" "wasm32-wasi hello_world"
tmpwasm=$(mktemp /tmp/kriol_wasm_XXXX.wasm)
if "$KRIOL" "$ROOT/examples/hello_world.kriol" --target wasm32-wasi -o "$tmpwasm" 2>/dev/null; then
if command -v file >/dev/null 2>&1; then
if file "$tmpwasm" | grep -Fq "WebAssembly"; then
echo " PASS"; pass=$((pass+1))
else
echo " FAIL (not a WebAssembly module)"
record_failure "wasm32-wasi hello_world"
fi
else
echo " PASS"; pass=$((pass+1))
fi
else
echo " FAIL"; record_failure "wasm32-wasi hello_world"
fi
rm -f "$tmpwasm"
printf " %-44s" "wasm32-wasi f-string runtime"
tmpwasm=$(mktemp /tmp/kriol_wasm_fstr_gc_XXXX.wasm)
if "$KRIOL" "$ROOT/tests/pass/mostra_interpolation.kr" --target wasm32-wasi -o "$tmpwasm" 2>/dev/null; then
echo " PASS"; pass=$((pass+1))
else
echo " FAIL"; record_failure "wasm32-wasi f-string runtime"
fi
rm -f "$tmpwasm"
fi
echo -e "\n $pass/$((pass+fail)) passed\n"
if [ $fail -ne 0 ]; then
echo -e "Failed tests:$failed_tests\n"
fi
[ $fail -eq 0 ]