aboutsummaryrefslogtreecommitdiffstats
path: root/test/plugin_cover.mk
blob: a5ed2954738a77329eb2f17cc271854fb1a1e372 (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
# Common Test plugin.

COVER_TARGETS = $(call list_targets,cover)

.PHONY: cover $(COVER_TARGETS)

cover: $(COVER_TARGETS)

cover-ct: build clean

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v

	$i "Generate a Common Test suite"
	$t mkdir $(APP)/test
	$t printf "%s\n" \
		"-module($(APP)_SUITE)." \
		"-export([all/0, ok/1])." \
		"all() -> [ok]." \
		"ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl

	$i "Run Common Test with code coverage enabled"
	$t $(MAKE) -C $(APP) ct COVER=1 $v

	$i "Check that the generated files exist"
	$t test -f $(APP)/cover/ct.coverdata
	$t test -f $(APP)/test/ct.cover.spec

	$i "Check that the generated files are removed on clean"
	$t $(MAKE) -C $(APP) clean $v
	$t test ! -e $(APP)/cover/ct.coverdata
	$t test ! -e $(APP)/test/ct.cover.spec

cover-custom-dir: build clean

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v

	$i "Set COVER_DATA_DIR in the Makefile"
	$t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DATA_DIR = custom_dir\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 "Generate a Common Test suite"
	$t mkdir $(APP)/test
	$t printf "%s\n" \
		"-module($(APP)_SUITE)." \
		"-export([all/0, ok/1])." \
		"all() -> [ok]." \
		"ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl

	$i "Run Common Test with code coverage enabled"
	$t $(MAKE) -C $(APP) ct COVER=1 $v

	$i "Run EUnit with code coverage enabled"
	$t $(MAKE) -C $(APP) eunit COVER=1 $v

	$i "Check that the generated file exists"
	$t test -f $(APP)/custom_dir/ct.coverdata
	$t test -f $(APP)/custom_dir/eunit.coverdata

	$i "Merge coverdata files into all.coverdata"
	$t $(MAKE) -C $(APP) all.coverdata $v
	$t test -f $(APP)/custom_dir/all.coverdata

	$i "Check that the generated file is removed on clean"
	$t $(MAKE) -C $(APP) clean $v
	$t test ! -e $(APP)/custom_dir/eunit.coverdata
	$t test ! -e $(APP)/custom_dir/ct.coverdata
	$t test ! -e $(APP)/custom_dir/all.coverdata

	$i "Check that the custom dir is removed on distclean"
	$t $(MAKE) -C $(APP) distclean $v
	$t test ! -e $(APP)/custom_dir/

	$i "Check that the custom dir is not removed if not empty"
	$t mkdir $(APP)/custom_dir
	$t touch $(APP)/custom_dir/file
	$t $(MAKE) -C $(APP) distclean $v
	$t test -f $(APP)/custom_dir/file

cover-eunit: build clean

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $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 "Run EUnit with code coverage enabled"
	$t $(MAKE) -C $(APP) eunit COVER=1 $v

	$i "Check that the generated file exists"
	$t test -f $(APP)/cover/eunit.coverdata

	$i "Check that the generated file is removed on clean"
	$t $(MAKE) -C $(APP) clean $v
	$t test ! -e $(APP)/cover/eunit.coverdata

cover-eunit-apps-only: build clean

	$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 "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 "Run EUnit with code coverage enabled"
	$t $(MAKE) -C $(APP) eunit COVER=1 $v

	$i "Check that no file was generated in the top-level directory"
	$t ! test -f $(APP)/cover/eunit.coverdata

	$i "Check that the generated file exists"
	$t test -f $(APP)/apps/my_app/cover/eunit.coverdata

cover-proper: build clean

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v

	$i "Add PropEr to the list of dependencies"
	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = proper\n"}' $(APP)/Makefile

	$i "Generate a module containing Proper properties"
	$t printf "%s\n" \
		"-module($(APP))." \
		"-ifdef(TEST)." \
		"-include_lib(\"proper/include/proper.hrl\")." \
		"prop_foo() -> ?FORALL(_, any(), true)." \
		"-endif." > $(APP)/src/$(APP).erl

	$i "Run PropEr with code coverage enabled"
	$t $(MAKE) -C $(APP) proper COVER=1 $v

	$i "Check that the generated file exists"
	$t test -f $(APP)/cover/proper.coverdata

	$i "Check that the generated file is removed on clean"
	$t $(MAKE) -C $(APP) clean $v
	$t test ! -e $(APP)/cover/proper.coverdata

cover-report-and-merge: build clean

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v

	$i "Generate a Common Test suite"
	$t mkdir $(APP)/test
	$t printf "%s\n" \
		"-module($(APP)_SUITE)." \
		"-export([all/0, ok/1])." \
		"all() -> [ok]." \
		"ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl

	$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 "Run tests with code coverage enabled"
	$t $(MAKE) -C $(APP) tests COVER=1 $v

	$i "Check that the generated files exist"
	$t test -f $(APP)/cover/$(APP).COVER.html
	$t test -f $(APP)/cover/index.html
	$t test -f $(APP)/cover/ct.coverdata
	$t test -f $(APP)/cover/eunit.coverdata
	$t test -f $(APP)/test/ct.cover.spec

	$i "Merge coverdata files into all.coverdata"
	$t $(MAKE) -C $(APP) all.coverdata $v
	$t test -f $(APP)/cover/all.coverdata

	$i "Check that the generated files are removed on clean"
	$t $(MAKE) -C $(APP) clean $v
	$t test ! -e $(APP)/cover/all.coverdata
	$t test ! -e $(APP)/cover/ct.coverdata
	$t test ! -e $(APP)/cover/eunit.coverdata
	$t test ! -e $(APP)/test/ct.cover.spec

	$i "Check that the cover report is removed on distclean"
	$t $(MAKE) -C $(APP) distclean $v
	$t test ! -e $(APP)/cover/

cover-triq: build clean

	$i "Bootstrap a new OTP application named $(APP)"
	$t mkdir $(APP)/
	$t cp ../erlang.mk $(APP)/
	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v

	$i "Add Triq to the list of dependencies"
	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = triq\n"}' $(APP)/Makefile

	$i "Generate a module containing Triq properties"
	$t printf "%s\n" \
		"-module($(APP))." \
		"-ifdef(TEST)." \
		"-include_lib(\"triq/include/triq.hrl\")." \
		"prop_foo() -> ?FORALL(_, any(), true)." \
		"-endif." > $(APP)/src/$(APP).erl

	$i "Run Triq with code coverage enabled"
	$t $(MAKE) -C $(APP) triq COVER=1 $v

	$i "Check that the generated file exists"
	$t test -f $(APP)/cover/triq.coverdata

	$i "Check that the generated file is removed on clean"
	$t $(MAKE) -C $(APP) clean $v
	$t test ! -e $(APP)/cover/triq.coverdata