-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_example.sh
More file actions
executable file
·62 lines (57 loc) · 2.49 KB
/
test_example.sh
File metadata and controls
executable file
·62 lines (57 loc) · 2.49 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
#!/bin/bash
# Usage: ./test_example.sh <impl> <mode> <example> [target]
# Impl: jjpy, jjswift
# Mode: run, compile, asm, exec, build, transpile
# Examples:
# ./test_example.sh jjpy run numbers
# ./test_example.sh jjswift exec enums c
# ./test_example.sh jjpy exec fizzbuzz swift
IMPL="${1:-jjpy}"
MODE="${2:-run}"
EXAMPLE="${3:-numbers}"
TARGET="${4:-c}"
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
echo "Testing: $EXAMPLE | impl: $IMPL | mode: $MODE"
[ "$MODE" = "exec" ] || [ "$MODE" = "build" ] || [ "$MODE" = "transpile" ] && echo "Target: $TARGET"
echo "=========================================="
run_test() {
case "$IMPL" in
jjpy)
cd "$SCRIPT_DIR/jibjab/jjpy" || exit 1
case "$MODE" in
run) python3 jj.py run "../examples/$EXAMPLE.jj" ;;
compile) python3 jj.py compile "../examples/$EXAMPLE.jj" "/tmp/${EXAMPLE}_py" && "/tmp/${EXAMPLE}_py" ;;
asm) python3 jj.py asm "../examples/$EXAMPLE.jj" "/tmp/${EXAMPLE}_py_asm" && "/tmp/${EXAMPLE}_py_asm" ;;
exec) python3 jj.py exec "../examples/$EXAMPLE.jj" "$TARGET" ;;
build) python3 jj.py build "../examples/$EXAMPLE.jj" "$TARGET" "/tmp/${EXAMPLE}_${TARGET}" ;;
transpile) python3 jj.py transpile "../examples/$EXAMPLE.jj" "$TARGET" ;;
esac
;;
jjswift)
cd "$SCRIPT_DIR/jibjab/jjswift" || exit 1
JJSWIFT=".build/debug/jjswift"
case "$MODE" in
run) "$JJSWIFT" run "../examples/$EXAMPLE.jj" ;;
compile) "$JJSWIFT" compile "../examples/$EXAMPLE.jj" "/tmp/${EXAMPLE}_swift" && "/tmp/${EXAMPLE}_swift" ;;
asm) "$JJSWIFT" asm "../examples/$EXAMPLE.jj" "/tmp/${EXAMPLE}_swift_asm" && "/tmp/${EXAMPLE}_swift_asm" ;;
exec) "$JJSWIFT" exec "../examples/$EXAMPLE.jj" "$TARGET" ;;
build) "$JJSWIFT" build "../examples/$EXAMPLE.jj" "$TARGET" "/tmp/${EXAMPLE}_${TARGET}" ;;
transpile) "$JJSWIFT" transpile "../examples/$EXAMPLE.jj" "$TARGET" ;;
esac
;;
*)
echo "Unknown impl: $IMPL (use jjpy or jjswift)"
return 1
;;
esac
}
if run_test 2>&1; then
echo ""
echo "=========================================="
echo "PASS: $EXAMPLE ($IMPL $MODE $TARGET)"
else
echo ""
echo "=========================================="
echo "FAIL: $EXAMPLE ($IMPL $MODE $TARGET)"
exit 1
fi