forked from stuartaroth/programmersguidetothegalaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_all_examples.sh
executable file
·334 lines (257 loc) · 9.76 KB
/
run_all_examples.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# Tests if we can run each test case
command_exists () {
type "$1" &> /dev/null ;
}
examples_log=$(pwd)"/examples.log"
examples=(
arrays_lists
arrays_lists_iteration
arrays_lists_manipulation
command_line_arguments
falsy_values
extension_methods
functions
hash_maps
hash_maps_iteration
hello_world
ifs
interpolation
lambdas
loops
simple_class
ternary_operators
variables
variadic_functions
);
# Attempt go examples
if command_exists go; then
echo "Running go examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && go fmt example.go && go run example.go >> "$examples_log" ) || echo "Error running $example_dir example for go!"
done
else
echo "Install go before running the go tests";
fi
if command_exists java && command_exists javac; then
echo "Running java examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && javac Example.java && java Example >> "$examples_log" ) || echo "Error running $example_dir example for java!"
done
else
echo "Install java before running the java tests";
fi
if command_exists perl; then
echo "Running perl examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && perl example.pl >> "$examples_log" ) || echo "Error running $example_dir example for perl!"
done
else
echo "Install perl before running the perl tests";
fi
if command_exists python; then
echo "Running python examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && python example.py >> "$examples_log" ) || echo "Error running $example_dir example for python!"
done
else
echo "Install python before running the python tests";
fi
if command_exists ruby; then
echo "Running ruby examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && ruby example.rb >> "$examples_log" ) || echo "Error running $example_dir example for ruby!"
done
else
echo "Install ruby before running the ruby tests";
fi
if command_exists scala; then
echo "Running scala examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && scala Example.scala >> "$examples_log" ) || echo "Error running $example_dir example for scala!"
done
else
echo "Install scala before running the scala tests";
fi
if command_exists tsc; then
echo "Running TypeScript examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && tsc Example.ts >> "$examples_log" ) || echo "Error running $example_dir example for TypeScript!"
done
else
echo "Install TypeScript before running the TypeScript tests";
fi
if command_exists node; then
echo "Running Node examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && node example.js >> "$examples_log" ) || echo "Error running $example_dir example for Node!"
done
echo "Running Javascript examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && node exampleJs.js >> "$examples_log" ) || echo "Error running $example_dir example for Javascript!"
done
else
echo "Install TypeScript before running the TypeScript tests";
fi
if command_exists dart; then
echo "Running dart examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && dart example.dart >> "$examples_log" ) || echo "Error running $example_dir example for dart!"
done
else
echo "Install dart before running the dart tests";
fi
if command_exists java && command_exists kotlinc; then
echo "Running kotlin examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && kotlinc example.kt -include-runtime -d example.jar && java -jar example.jar >> "$examples_log" ) || echo "Error running $example_dir example for kotlin!"
done
else
echo "Install kotlin before running the kotlin tests";
fi
if command_exists php; then
echo "Running php examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && php example.php >> "$examples_log" ) || echo "Error running $example_dir example for php!"
done
else
echo "Install dart before running the php tests";
fi
if command_exists mcs && command_exists mono; then
echo "Running C# examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && mcs Example.cs && mono Example.exe >> "$examples_log" ) || echo "Error running $example_dir example for C#!"
done
else
echo "Install Mono before running the C# tests";
fi
if command_exists swift; then
echo "Running Swift examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && swift Example.swift >> "$examples_log" ) || echo "Error running $example_dir example for Swift!"
done
else
echo "Install swift before running the Swift tests";
fi
if command_exists coffee && command_exists node; then
echo "Running CoffeeScript examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && coffee --compile exampleCoffee.coffee && node exampleCoffee.js >> "$examples_log" ) || echo "Error running $example_dir example for CoffeeScript!"
done
else
echo "Install coffee before running the CoffeeScript tests";
fi
if command_exists nim; then
echo "Running Nim examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && nim compile --run exampleNim.nim >> "$examples_log" ) || echo "Error running $example_dir example for Nim!"
done
else
echo "Install nim before running the Nim tests";
fi
if command_exists lein; then
echo "Running Clojure examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && lein exec example.clj >> "$examples_log" ) || echo "Error running $example_dir example for Clojure!"
done
else
echo "Install lein before running the Clojure tests";
fi
if command_exists groovy; then
echo "Running Groovy examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && groovy example.groovy >> "$examples_log" ) || echo "Error running $example_dir example for Groovy!"
done
else
echo "Install groovy before running the Groovy tests";
fi
if command_exists rustc; then
echo "Running Rust examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && rustc -o rust_example example.rs && ./rust_example >> "$examples_log" ) || echo "Error running $example_dir example for Rust!"
done
else
echo "Install rust before running the Rust tests";
fi
if command_exists g++; then
echo "Running C++ examples";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && g++ -std=c++11 -o cpp_example example.cpp && ./cpp_example >> "$examples_log" ) || echo "Error running $example_dir example for C++!"
done
else
echo "Install g++ before running the C++ tests";
fi
if command_exists ecl; then
echo "Running Common Lisp examples with ECL";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && ecl -norc -shell example.lisp >> "$examples_log" ) || echo "Error running $example_dir example for Common Lisp with ECL!"
done
elif command_exists clisp; then
echo "Running Common Lisp examples with CLISP";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && clisp -q example.lisp >> "$examples_log" ) || echo "Error running $example_dir example for Common Lisp with CLISP!"
done
elif command_exists ccl; then
echo "Running Common Lisp examples with CCL";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && ccl -nQ -l example.lisp -e '(quit)' >> "$examples_log" ) || echo "Error running $example_dir example for Common Lisp with CCL!"
done
elif command_exists sbcl; then
echo "Running Common Lisp examples with SBCL";
((max_test=${#examples[@]}))
for ((i = 1; i < max_test; i++)); do
example_dir="${examples[$i]}"
(cd "$example_dir" && sbcl --script example.lisp >> "$examples_log" ) || echo "Error running $example_dir example for Common Lisp with SBCL!"
done
else
echo "Install one of Clozure Common Lisp, Steel Bank Common Lisp, CLISP or Embeddable Common Lisp before running the Common Lisp tests";
fi