Gentoo Archives: gentoo-dev

From: aidecoe@g.o
To: gentoo-dev@l.g.o
Cc: "Amadeusz Żołnowski" <aidecoe@g.o>
Subject: [gentoo-dev] [PATCH 2/2] Add tests for rebar.eclass
Date: Sat, 21 May 2016 23:23:35
Message-Id: 1463872971-18833-1-git-send-email-aidecoe@gentoo.org
In Reply to: [gentoo-dev] [PATCH] rebar.eclass: Build Erlang/OTP projects using dev-util/rebar by aidecoe@gentoo.org
1 From: Amadeusz Żołnowski <aidecoe@g.o>
2
3 ---
4 eclass/tests/rebar_fix_include_path.sh | 159 +++++++++++++++++++++++++++++++++
5 eclass/tests/rebar_remove_deps.sh | 99 ++++++++++++++++++++
6 eclass/tests/rebar_set_vsn.sh | 115 ++++++++++++++++++++++++
7 3 files changed, 373 insertions(+)
8 create mode 100755 eclass/tests/rebar_fix_include_path.sh
9 create mode 100755 eclass/tests/rebar_remove_deps.sh
10 create mode 100755 eclass/tests/rebar_set_vsn.sh
11
12 diff --git a/eclass/tests/rebar_fix_include_path.sh b/eclass/tests/rebar_fix_include_path.sh
13 new file mode 100755
14 index 0000000..9047f8d
15 --- /dev/null
16 +++ b/eclass/tests/rebar_fix_include_path.sh
17 @@ -0,0 +1,159 @@
18 +#!/bin/bash
19 +# Copyright 1999-2016 Gentoo Foundation
20 +# Distributed under the terms of the GNU General Public License v2
21 +# $Id$
22 +
23 +source tests-common.sh
24 +
25 +EAPI=6
26 +
27 +inherit rebar
28 +
29 +EPREFIX="${tmpdir}/fakeroot"
30 +S="${WORKDIR}/${P}"
31 +
32 +setup() {
33 + mkdir -p "${S}" || die
34 +
35 + for pkg in foo-0.1.0 bar-0.1.0; do
36 + mkdir -p "${EPREFIX}$(get_erl_libs)/${pkg}/include" || die
37 + done
38 +
39 + cat <<EOF >"${S}/typical.config" || die
40 +%%% Comment
41 +
42 +{erl_opts, [debug_info, {src_dirs, ["src"]},
43 + {i, "include"},
44 + {i, "deps/foo/include"},
45 + {i, "../foo/include"}]}.
46 +
47 +{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
48 +EOF
49 +
50 + cat <<EOF >"${S}/typical.config.expected" || die
51 +%%% Comment
52 +
53 +{erl_opts, [debug_info, {src_dirs, ["src"]},
54 + {i, "include"},
55 + {i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"},
56 + {i, "../foo/include"}]}.
57 +
58 +{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
59 +EOF
60 +
61 + cat <<EOF >"${S}/inc_one_line.config" || die
62 +%%% Comment
63 +
64 +{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "deps/foo/include"}, {i, "../foo/include"}]}.
65 +
66 +{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
67 +EOF
68 +
69 + cat <<EOF >"${S}/inc_one_line.config.expected" || die
70 +%%% Comment
71 +
72 +{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"}, {i, "../foo/include"}]}.
73 +
74 +{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
75 +EOF
76 +}
77 +
78 +test_typical_config() {
79 + local diff_rc
80 + local unit_rc
81 +
82 + # Prepare
83 + cd "${S}" || die
84 + cp typical.config rebar.config || die
85 +
86 + # Run unit
87 + (rebar_fix_include_path foo)
88 + unit_rc=$?
89 +
90 + # Test result
91 + diff rebar.config typical.config.expected
92 + diff_rc=$?
93 +
94 + [[ ${unit_rc}${diff_rc} = 00 ]]
95 +}
96 +
97 +test_multiple_versions() {
98 + local diff_rc
99 + local unit_rc
100 +
101 + # Prepare
102 + cd "${S}" || die
103 + cp typical.config rebar.config || die
104 + mkdir -p "${EPREFIX}$(get_erl_libs)/foo-1.0.0/include" || die
105 +
106 + # Run unit
107 + (rebar_fix_include_path foo 2>/dev/null)
108 + unit_rc=$?
109 +
110 + # Test result
111 + diff rebar.config typical.config
112 + diff_rc=$?
113 +
114 + # Clean up
115 + rm -r "${EPREFIX}$(get_erl_libs)/foo-1.0.0" || die
116 +
117 + [[ ${unit_rc}${diff_rc} = 10 ]]
118 +}
119 +
120 +test_not_found() {
121 + local diff_rc
122 + local unit_rc
123 +
124 + # Prepare
125 + cd "${S}" || die
126 + cp typical.config rebar.config || die
127 +
128 + # Run unit
129 + (rebar_fix_include_path fo 2>/dev/null)
130 + unit_rc=$?
131 +
132 + # Test result
133 + diff rebar.config typical.config
134 + diff_rc=$?
135 +
136 + [[ ${unit_rc}${diff_rc} = 10 ]]
137 +}
138 +
139 +test_includes_in_one_line() {
140 + local diff_rc
141 + local unit_rc
142 +
143 + # Prepare
144 + cd "${S}" || die
145 + cp inc_one_line.config rebar.config || die
146 +
147 + # Run unit
148 + (rebar_fix_include_path foo)
149 + unit_rc=$?
150 +
151 + # Test result
152 + diff rebar.config inc_one_line.config.expected
153 + diff_rc=$?
154 +
155 + [[ ${unit_rc}${diff_rc} = 00 ]]
156 +}
157 +
158 +setup
159 +
160 +tbegin "rebar_fix_include_path deals with typical config"
161 +test_typical_config
162 +tend $?
163 +
164 +tbegin "rebar_fix_include_path fails on multiple versions of dependency"
165 +test_multiple_versions
166 +tend $?
167 +
168 +tbegin "rebar_fix_include_path fails if dependency is not found"
169 +test_not_found
170 +tend $?
171 +
172 +tbegin "rebar_fix_include_path deals with all includes in one line"
173 +test_includes_in_one_line
174 +tend $?
175 +
176 +texit
177 diff --git a/eclass/tests/rebar_remove_deps.sh b/eclass/tests/rebar_remove_deps.sh
178 new file mode 100755
179 index 0000000..05207a7
180 --- /dev/null
181 +++ b/eclass/tests/rebar_remove_deps.sh
182 @@ -0,0 +1,99 @@
183 +#!/bin/bash
184 +# Copyright 1999-2016 Gentoo Foundation
185 +# Distributed under the terms of the GNU General Public License v2
186 +# $Id$
187 +
188 +source tests-common.sh
189 +
190 +EAPI=6
191 +
192 +inherit rebar
193 +
194 +EPREFIX="${tmpdir}/fakeroot"
195 +S="${WORKDIR}/${P}"
196 +
197 +setup() {
198 + mkdir -p "${S}" || die
199 +
200 + cat <<EOF >"${S}/rebar.config.expected" || die
201 +%%% Comment
202 +
203 +{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
204 +
205 +{deps, []}.
206 +
207 +{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
208 +EOF
209 +
210 + cat <<EOF >"${S}/typical.config" || die
211 +%%% Comment
212 +
213 +{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
214 +
215 +{deps, [{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.3"}}},
216 + {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.3"}}},
217 + {p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.3"}}}]}.
218 +
219 +{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
220 +EOF
221 +
222 + cat <<EOF >"${S}/deps_one_line.config" || die
223 +%%% Comment
224 +
225 +{port_specs, [{"priv/lib/esip_drv.so", ["c_src/esip_codec.c"]}]}.
226 +
227 +{deps, [{stun, ".*", {git, "https://github.com/processone/stun", {tag, "1.0.3"}}}, {fast_tls, ".*", {git, "https://github.com/processone/fast_tls", {tag, "1.0.3"}}}, {p1_utils, ".*", {git, "https://github.com/processone/p1_utils", {tag, "1.0.3"}}}]}.
228 +
229 +{clean_files, ["c_src/esip_codec.gcda", "c_src/esip_codec.gcno"]}.
230 +EOF
231 +}
232 +
233 +test_typical_config() {
234 + local diff_rc
235 + local unit_rc
236 +
237 + # Prepare
238 + cd "${S}" || die
239 + cp typical.config rebar.config || die
240 +
241 + # Run unit
242 + (rebar_remove_deps)
243 + unit_rc=$?
244 +
245 + # Test result
246 + diff rebar.config rebar.config.expected
247 + diff_rc=$?
248 +
249 + [[ ${unit_rc}${diff_rc} = 00 ]]
250 +}
251 +
252 +test_deps_in_one_line() {
253 + local diff_rc
254 + local unit_rc
255 +
256 + # Prepare
257 + cd "${S}" || die
258 + cp deps_one_line.config rebar.config || die
259 +
260 + # Run unit
261 + (rebar_remove_deps)
262 + unit_rc=$?
263 +
264 + # Test result
265 + diff rebar.config rebar.config.expected
266 + diff_rc=$?
267 +
268 + [[ ${unit_rc}${diff_rc} = 00 ]]
269 +}
270 +
271 +setup
272 +
273 +tbegin "rebar_remove_deps deals with typical config"
274 +test_typical_config
275 +tend $?
276 +
277 +tbegin "rebar_remove_deps deals with all deps in one line"
278 +test_deps_in_one_line
279 +tend $?
280 +
281 +texit
282 diff --git a/eclass/tests/rebar_set_vsn.sh b/eclass/tests/rebar_set_vsn.sh
283 new file mode 100755
284 index 0000000..2a9f5bc
285 --- /dev/null
286 +++ b/eclass/tests/rebar_set_vsn.sh
287 @@ -0,0 +1,115 @@
288 +#!/bin/bash
289 +# Copyright 1999-2016 Gentoo Foundation
290 +# Distributed under the terms of the GNU General Public License v2
291 +# $Id$
292 +
293 +source tests-common.sh
294 +
295 +EAPI=6
296 +
297 +inherit rebar
298 +
299 +EPREFIX="${tmpdir}/fakeroot"
300 +S="${WORKDIR}/${P}"
301 +
302 +setup() {
303 + mkdir -p "${S}/src" || die
304 +
305 + cat <<EOF >"${S}/app.src.expected" || die
306 +%%% Comment
307 +
308 +{application, esip,
309 + [{description, "ProcessOne SIP server component in Erlang"},
310 + {vsn, "0"},
311 + {modules, []},
312 + {registered, []},
313 +EOF
314 +
315 + cat <<EOF >"${S}/app.src" || die
316 +%%% Comment
317 +
318 +{application, esip,
319 + [{description, "ProcessOne SIP server component in Erlang"},
320 + {vsn, git},
321 + {modules, []},
322 + {registered, []},
323 +EOF
324 +}
325 +
326 +test_typical_app_src() {
327 + local diff_rc
328 + local unit_rc
329 +
330 + # Prepare
331 + cd "${S}" || die
332 + cp app.src "src/${PN}.app.src" || die
333 +
334 + # Run unit
335 + (rebar_set_vsn)
336 + unit_rc=$?
337 +
338 + # Test result
339 + diff "src/${PN}.app.src" app.src.expected
340 + diff_rc=$?
341 +
342 + [[ ${unit_rc}${diff_rc} = 00 ]]
343 +}
344 +
345 +test_app_src_missing() {
346 + local unit_rc
347 +
348 + # Prepare
349 + cd "${S}" || die
350 + rm -f "src/${PN}.app.src" || die
351 +
352 + # Run unit
353 + (rebar_set_vsn 2>/dev/null)
354 + unit_rc=$?
355 +
356 + [[ ${unit_rc} = 1 ]]
357 +}
358 +
359 +test_set_custom_version() {
360 + local diff_rc
361 + local unit_rc
362 +
363 + # Prepare
364 + cd "${S}" || die
365 + cp app.src "src/${PN}.app.src" || die
366 + cat <<EOF >"${S}/custom_app.src.expected" || die
367 +%%% Comment
368 +
369 +{application, esip,
370 + [{description, "ProcessOne SIP server component in Erlang"},
371 + {vsn, "1.2.3"},
372 + {modules, []},
373 + {registered, []},
374 +EOF
375 +
376 + # Run unit
377 + (rebar_set_vsn 1.2.3)
378 + unit_rc=$?
379 +
380 + # Test result
381 + diff "src/${PN}.app.src" custom_app.src.expected
382 + diff_rc=$?
383 +
384 + [[ ${unit_rc}${diff_rc} = 00 ]]
385 +}
386 +
387 +
388 +setup
389 +
390 +tbegin "rebar_set_vsn deals with typical app.src"
391 +test_typical_app_src
392 +tend $?
393 +
394 +tbegin "rebar_set_vsn fails when app.src is missing"
395 +test_app_src_missing
396 +tend $?
397 +
398 +tbegin "rebar_set_vsn sets custom version in app.src"
399 +test_set_custom_version
400 +tend $?
401 +
402 +texit
403 --
404 2.8.2