blob: 768358c8eb0f0dc3a6981e51c42edbc2443b2a81 (
plain) (
blame)
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
|
# EUnit plugin.
EUNIT_TARGETS = $(call list_targets,eunit)
.PHONY: eunit $(EUNIT_TARGETS)
eunit: $(EUNIT_TARGETS)
eunit-all: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Check that EUnit detects no tests"
$t $(MAKE) -C $(APP) eunit | grep -c "There were no tests to run." | grep -q 1
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/src/$(APP).erl
$i "Build the project cleanly"
$t $(MAKE) -C $(APP) clean $v
$t $(MAKE) -C $(APP) $v
$i "Check that no EUnit test cases were exported"
$t $(ERL) -pa $(APP)/ebin -eval 'code:load_file($(APP)), false = erlang:function_exported($(APP), ok_test, 0), halt()'
$i "Check that EUnit runs tests"
$t $(MAKE) -C $(APP) eunit | grep -c "Test passed." | grep -q 1
$i "Add a failing test to the module"
$t printf "%s\n" \
"-ifdef(TEST)." \
"bad_test() -> throw(fail)." \
"-endif." >> $(APP)/src/$(APP).erl
$i "Check that EUnit errors out"
$t ! $(MAKE) -C $(APP) eunit $v
eunit-apps-include-lib: init
$i "Bootstrap a new OTP library named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
$i "Create new libraries the_app and test_helpers"
$t $(MAKE) -C $(APP) new-lib in=the_app $v
$t $(MAKE) -C $(APP) new-lib in=test_helpers $v
$i "Generate .erl file"
$t echo '-module(the). -export([thing/0]). thing() -> true.' > $(APP)/apps/the_app/src/the.erl
$t mkdir -p $(APP)/apps/the_app/test
$i "Generate test .erl file with helper include_lib()"
$t echo '-module(the_test).' > $(APP)/apps/the_app/test/the_test.erl
$t echo '-include_lib("eunit/include/eunit.hrl").' >> $(APP)/apps/the_app/test/the_test.erl
$t echo '-include_lib("test_helpers/include/test_helpers.hrl").' >> $(APP)/apps/the_app/test/the_test.erl
$t echo 'thing_test() -> ?assertEqual(true, the:thing()).' >> $(APP)/apps/the_app/test/the_test.erl
$t mkdir -p $(APP)/apps/test_helpers/include
$t echo '%% test_helpers' > $(APP)/apps/test_helpers/include/test_helpers.hrl
$i "Build the application"
$t $(MAKE) -C $(APP) $v
$i "Run eunit"
$t $(MAKE) -C $(APP) eunit $v
$i "Distclean the application"
$t $(MAKE) -C $(APP) distclean $v
$i "Run eunit on a subdirectory"
$t $(MAKE) -C $(APP)/apps/the_app eunit $v
$i "Distclean the application"
$t $(MAKE) -C $(APP) distclean $v
eunit-apps-include-lib-deps: init
$i "Bootstrap a new OTP library named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
$i "Create new library the_app"
$t $(MAKE) -C $(APP) new-lib in=the_app $v
$i "Add Cowlib to the list of dependencies of the_app"
$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\ndep_cowlib_commit = master\n"}' $(APP)/apps/the_app/Makefile
$i "Generate .erl file that uses include_lib()"
$t echo '-module(the). -include_lib("cowlib/include/cow_parse.hrl"). -export([thing/0]). thing() -> true.' > $(APP)/apps/the_app/src/the.erl
$i "Run eunit"
$t $(MAKE) -C $(APP) eunit $v
eunit-apps-one-app-tested: init
$i "Bootstrap a new OTP library named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
$i "Create a new application named my_app"
$t $(MAKE) -C $(APP) new-app in=my_app $v
$i "Create a new library named my_lib"
$t $(MAKE) -C $(APP) new-lib in=my_lib $v
$i "Generate a module containing EUnit tests in my_app"
$t printf "%s\n" \
"-module(my_app)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/apps/my_app/src/my_app.erl
$i "Generate a module containing EUnit tests in my_lib"
$t printf "%s\n" \
"-module(my_lib)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/apps/my_lib/src/my_lib.erl
$i "Run EUnit on my_app only"
$t $(MAKE) -C $(APP)/apps/my_app eunit | grep -c "Test passed." | grep -q 1
eunit-apps-only: init
$i "Create a multi application repository with no root application"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t echo "include erlang.mk" > $(APP)/Makefile
$i "Create a new application named my_app"
$t $(MAKE) -C $(APP) new-app in=my_app $v
$i "Create a new library named my_lib"
$t $(MAKE) -C $(APP) new-lib in=my_lib $v
$i "Check that EUnit detects no tests"
$t $(MAKE) -C $(APP) eunit | grep -c "There were no tests to run." | grep -q 2
$i "Generate a module containing EUnit tests in my_app"
$t printf "%s\n" \
"-module(my_app)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/apps/my_app/src/my_app.erl
$i "Generate a module containing EUnit tests in my_lib"
$t printf "%s\n" \
"-module(my_lib)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/apps/my_lib/src/my_lib.erl
$i "Check that EUnit runs tests"
$t $(MAKE) -C $(APP) eunit | grep -c "Test passed." | grep -q 2
eunit-apps-only-error: init
$i "Create a multi application repository with no root application"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t echo "include erlang.mk" > $(APP)/Makefile
$i "Create a new application named my_app1"
$t $(MAKE) -C $(APP) new-app in=my_app1 $v
$i "Create a new application named my_app2"
$t $(MAKE) -C $(APP) new-app in=my_app2 $v
$i "Create a new library named my_lib"
$t $(MAKE) -C $(APP) new-lib in=my_lib $v
$i "Check that EUnit detects no tests"
$t $(MAKE) -C $(APP) eunit | grep -c "There were no tests to run." | grep -q 3
$i "Generate a module containing broken EUnit tests in my_app1"
$t printf "%s\n" \
"-module(my_app1)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"bad_test() -> ?assert(0 =:= 1)." \
"-endif." > $(APP)/apps/my_app1/src/my_app1.erl
$i "Generate a module containing EUnit good tests in my_app2"
$t printf "%s\n" \
"-module(my_app2)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/apps/my_app2/src/my_app2.erl
$i "Generate a module containing EUnit tests in my_lib"
$t printf "%s\n" \
"-module(my_lib)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/apps/my_lib/src/my_lib.erl
$i "Check exit code of EUnit for the module with broken test should be non-zero"
$t ! $(MAKE) -C $(APP)/apps/my_app1 eunit $v
$i "Check exit code of EUnit for the whole project with broken test should be non-zero"
$t ! $(MAKE) -C $(APP) eunit $v
eunit-check: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/src/$(APP).erl
$i "Check that EUnit runs on 'make check'"
$t $(MAKE) -C $(APP) check | grep -c "Test passed." | grep -q 1
eunit-erl-opts: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Set EUNIT_ERL_OPTS in the Makefile"
$t perl -ni.bak -e 'print;if ($$.==1) {print "EUNIT_ERL_OPTS = -eval \"erlang:display(hello).\" \n"}' $(APP)/Makefile
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/src/$(APP).erl
$i "Check that EUnit uses EUNIT_ERL_OPTS"
$t $(MAKE) -C $(APP) eunit | grep -c "hello" | grep -q 1
eunit-fun: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"bad_test() -> throw(fail)." \
"-endif." > $(APP)/src/$(APP).erl
$i "Check that we can run EUnit on a specific test"
$t $(MAKE) -C $(APP) eunit t=$(APP):ok_test $v
eunit-mod: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/src/$(APP).erl
$i "Generate a module containing failing EUnit tests"
$t printf "%s\n" \
"-module($(APP)_fail)." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"bad_test() -> throw(fail)." \
"-endif." > $(APP)/src/$(APP)_fail.erl
$i "Check that we can run EUnit on a specific module"
$t $(MAKE) -C $(APP) eunit t=$(APP) $v
eunit-priv: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ?assert(is_list(code:priv_dir($(APP))) =:= true)." \
"-endif." > $(APP)/src/$(APP).erl
$i "Check that EUnit can resolve the priv_dir"
$t $(MAKE) -C $(APP) tests | grep -c "Test passed." | grep -q 1
eunit-test-dir: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"log_test() -> file:write_file(\"eunit.log\", \"$(APP)\n\", [append])." \
"-endif." > $(APP)/src/$(APP).erl
$i "Generate a module containing EUnit tests in TEST_DIR"
$t mkdir $(APP)/test
$t printf "%s\n" \
"-module($(APP)_tests)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"log_test() -> file:write_file(\"eunit.log\", \"$(APP)_tests\n\", [append])." > $(APP)/test/$(APP)_tests.erl
$i "Check that EUnit runs both tests"
$t $(MAKE) -C $(APP) eunit | grep -c "2 tests passed." | grep -q 1
$i "Check that tests were both run only once"
$t printf "%s\n" $(APP) $(APP)_tests | cmp $(APP)/eunit.log -
eunit-tests: init
$i "Bootstrap a new OTP application named $(APP)"
$t mkdir $(APP)/
$t cp ../erlang.mk $(APP)/
$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
$i "Generate a module containing EUnit tests"
$t printf "%s\n" \
"-module($(APP))." \
"-ifdef(TEST)." \
"-include_lib(\"eunit/include/eunit.hrl\")." \
"ok_test() -> ok." \
"-endif." > $(APP)/src/$(APP).erl
$i "Check that EUnit runs on 'make tests'"
$t $(MAKE) -C $(APP) tests | grep -c "Test passed." | grep -q 1
|