summaryrefslogtreecommitdiff
blob: 315d8a76ec4b16e7f1ba7b917ae64165c81cb563 (plain)
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
#!/bin/bash
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

source tests-common.sh

EAPI=6

inherit rebar

EPREFIX="${tmpdir}/fakeroot"
S="${WORKDIR}/${P}"

setup() {
	mkdir -p "${S}/src" || die

	cat <<EOF >"${S}/app.src.expected" || die
%%% Comment

{application, esip,
 [{description, "ProcessOne SIP server component in Erlang"},
  {vsn, "0"},
  {modules, []},
  {registered, []},
EOF

	cat <<EOF >"${S}/app.src" || die
%%% Comment

{application, esip,
 [{description, "ProcessOne SIP server component in Erlang"},
  {vsn, git},
  {modules, []},
  {registered, []},
EOF
}

test_typical_app_src() {
	local diff_rc
	local unit_rc

	# Prepare
	cd "${S}" || die
	cp app.src "src/${PN}.app.src" || die

	# Run unit
	(rebar_set_vsn)
	unit_rc=$?

	# Test result
	diff "src/${PN}.app.src" app.src.expected
	diff_rc=$?

	[[ ${unit_rc}${diff_rc} = 00 ]]
}

test_app_src_missing() {
	local unit_rc

	# Prepare
	cd "${S}" || die
	rm -f "src/${PN}.app.src" || die

	# Run unit
	(rebar_set_vsn 2>/dev/null)
	unit_rc=$?

	[[ ${unit_rc} = 1 ]]
}

test_set_custom_version() {
	local diff_rc
	local unit_rc

	# Prepare
	cd "${S}" || die
	cp app.src "src/${PN}.app.src" || die
	cat <<EOF >"${S}/custom_app.src.expected" || die
%%% Comment

{application, esip,
 [{description, "ProcessOne SIP server component in Erlang"},
  {vsn, "1.2.3"},
  {modules, []},
  {registered, []},
EOF

	# Run unit
	(rebar_set_vsn 1.2.3)
	unit_rc=$?

	# Test result
	diff "src/${PN}.app.src" custom_app.src.expected
	diff_rc=$?

	[[ ${unit_rc}${diff_rc} = 00 ]]
}


setup

tbegin "rebar_set_vsn deals with typical app.src"
test_typical_app_src
tend $?

tbegin "rebar_set_vsn fails when app.src is missing"
test_app_src_missing
tend $?

tbegin "rebar_set_vsn sets custom version in app.src"
test_set_custom_version
tend $?

texit