-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.sh
executable file
·86 lines (71 loc) · 2.03 KB
/
run_tests.sh
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
#!/usr/bin/env bash
# Note: this script need to be in the parent folder, not in tests/
# because it runs a container with $PWD as bind-mount, and relies on
# both tests/learn-ocaml-tests.el and learn-ocaml.el
# It reads the environment variable $USE_PASSWD (see below).
# These files contain some useful/hidden info for ERT tests.
confirm="$PWD/confirm.txt"
teacher="$PWD/teacher.txt"
# This file contains the Server Container ID (gen by ./run_test_backend.sh)
fcid="$PWD/learn-ocaml-server.pid"
# This file contains the Emacs Container ID (gen by ./stop_emacs_image.sh)
feid="$PWD/learn-ocaml-emacs.pid"
# Print $1 in green
green () {
echo -e "\\e[32m$1\\e[0m"
}
# Print $1 in red
red () {
echo -e "\\e[31m$1\\e[0m"
}
green "Beforehand: USE_PASSWD=$USE_PASSWD"
# Default mode
: "${USE_PASSWD:=false}"
# Do "export USE_PASSWD=…" before running the script to override
green "Henceforth: USE_PASSWD=$USE_PASSWD\\n"
read_cid () {
if [ -f "$fcid" ]; then
cid=$(<"$fcid")
else
red >&2 "Error: file '$fcid' does not exist."
exit 1
fi
}
read_eid () {
if [ -f "$feid" ]; then
eid=$(<"$feid")
else
red >&2 "Error: file '$feid' does not exist."
exit 1
fi
}
assert () {
if [ $# -ne 1 ]; then
red "ERROR, assert expects a single arg (the code to run)"
exit 1
fi
sudo docker exec -i "$eid" /bin/sh -c "
set -ex
$1
"
ret=$?
if [ "$ret" -ne 0 ]; then
red "FAILURE, this shell command returned exit status $ret:
\$ sudo docker exec -i $eid /bin/sh -c '$1'\\n"
exit $ret
fi
}
read_cid
read_eid
assert "emacs --version"
assert "emacs --batch --eval '(pp (+ 2 2))'"
echo
assert "learn-ocaml-client --version"
# The following tests run smoothly in both "token" & "passwd" context:
assert "make test -C /build/tests/001-common"
# The following tests for low-level functions run in only one context:
if [ "$USE_PASSWD" = "true" ]; then
assert "make test -C /build/tests/003-use-passwd"
else
assert "make test -C /build/tests/002-use-token"
fi