2
2
3
3
let count=0
4
4
5
- # If the first argument is "set", the script will replace all the expected
5
+ # If the first argument is "set", the script will replace all the expected
6
6
# answers by the response of the server. It is useful when you need to
7
7
# initialize a set of tests.
8
8
9
+ # If the environment variable $USE_CLIENT_IMAGE is set to "true", then
10
+ # the script will use both images learn-ocaml and learn-ocaml-client,
11
+ # instead of the mere learn-ocaml image. It is useful for testing
12
+ # cross-version compatibility.
13
+
9
14
SETTER=0
10
15
if [ " $1 " == " set" ]; then SETTER=1; fi
11
16
17
+ use_client_image () {
18
+ if [ " $USE_CLIENT_IMAGE " = " true" ]; then
19
+ return 0
20
+ else
21
+ return 1
22
+ fi
23
+ }
24
+
12
25
# print in green $1
13
26
green () {
14
27
echo -e " \e[32m$1 \e[0m"
@@ -19,6 +32,12 @@ red () {
19
32
echo -e " \e[31m$1 \e[0m"
20
33
}
21
34
35
+ if use_client_image; then
36
+ green " Running tests with BOTH images (learn-ocaml, learn-ocaml-client)"
37
+ else
38
+ green " Running tests with single image learn-ocaml"
39
+ fi
40
+
22
41
# run a server in a docker container
23
42
run_server () {
24
43
SYNC=" $( pwd) " /" $dir " /sync
@@ -28,7 +47,7 @@ run_server () {
28
47
chmod o+w " $dir " /sync
29
48
30
49
# Run the server in background
31
- SERVERID=$( docker run --entrypoint ' ' -d \
50
+ SERVERID=$( docker run --entrypoint ' ' -d -p 8080:8080 \
32
51
-v " $( pwd) " /" $dir " :/home/learn-ocaml/actual \
33
52
-v " $SYNC " :/sync -v " $REPO " :/repository \
34
53
learn-ocaml /bin/sh \
@@ -50,6 +69,25 @@ learn-ocaml --sync-dir=/sync --repo=/repository build serve")
50
69
docker rm " $SERVERID " > /dev/null
51
70
exit 1
52
71
fi
72
+
73
+ if use_client_image; then
74
+ # Run the client in background
75
+ CLIENTID=$( docker run --entrypoint ' ' -d -it --name=client \
76
+ -add-host host.docker.internal:host-gateway \
77
+ -v " $( pwd) " /" $dir " :/home/learn-ocaml/actual \
78
+ learn-ocaml-client /bin/sh)
79
+
80
+ # Wait for the client to be initialized
81
+ sleep 2
82
+ if [ " $( docker ps -q -f name=client) " == " " ]; then
83
+ red " PROBLEM, client is not running.\n"
84
+
85
+ red " LOGS:"
86
+ docker logs " $CLIENTID "
87
+ docker rm " $CLIENTID " > /dev/null
88
+ exit 1
89
+ fi
90
+ fi
53
91
}
54
92
55
93
clean () {
@@ -58,6 +96,11 @@ clean () {
58
96
59
97
docker kill " $SERVERID " > /dev/null
60
98
docker rm " $SERVERID " > /dev/null
99
+
100
+ if use_client_image; then
101
+ docker kill " $CLIENTID " > /dev/null
102
+ docker rm " $CLIENTID " > /dev/null
103
+ fi
61
104
}
62
105
63
106
clean_fail () {
@@ -69,9 +112,13 @@ handle_file () {
69
112
subdir=" $1 "
70
113
tosend=" $( basename " $2 " ) "
71
114
# Grade file
72
- docker exec -i " $SERVERID " \
73
- learn-ocaml-client grade --json --id=" $subdir " \
74
- /home/learn-ocaml/actual/" $subdir " /" $tosend " > res.json 2> stderr.txt
115
+ args=(learn-ocaml-client grade --json --id=" $subdir "
116
+ /home/learn-ocaml/actual/" $subdir " /" $tosend " )
117
+ if use_client_image; then
118
+ docker exec -i " $CLIENTID " " ${args[@]} " > res.json 2> stderr.txt
119
+ else
120
+ docker exec -i " $SERVERID " " ${args[@]} " > res.json 2> stderr.txt
121
+ fi
75
122
if [ $? -ne 0 ]; then
76
123
red " NOT OK: $dir /$tosend "
77
124
cat stderr.txt
@@ -102,9 +149,13 @@ handle_subdir () {
102
149
subdir=" $( basename " $1 " ) "
103
150
pushd " $1 " > /dev/null
104
151
105
- # init config
106
- docker exec -i " $SERVERID " \
107
- learn-ocaml-client init --server=http://localhost:8080 --token=" $token "
152
+ # init config
153
+ args=(learn-ocaml-client init --token=" $token " )
154
+ if use_client_image; then
155
+ docker exec -i " $CLIENTID " " ${args[@]} " --server=" http://host.docker.internal:8080"
156
+ else
157
+ docker exec -i " $SERVERID " " ${args[@]} " --server=" http://localhost:8080"
158
+ fi
108
159
# For each solution
109
160
for tosend in $( find . -name " *.ml" -type f -printf " %f\n" )
110
161
do
0 commit comments