summaryrefslogtreecommitdiff
blob: 8164e39d7252f57a60834c6f07a498c9e1fb429b (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
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
#!/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}" || die

	for pkg in foo-0.1.0 bar-0.1.0; do
		mkdir -p "${EPREFIX}$(get_erl_libs)/${pkg}/include" || die
	done

	cat <<EOF >"${S}/typical.config" || die
%%% Comment

{erl_opts, [debug_info, {src_dirs, ["src"]},
			{i, "include"},
			{i, "deps/foo/include"},
			{i, "../foo/include"}]}.

{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF

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

{erl_opts, [debug_info, {src_dirs, ["src"]},
			{i, "include"},
			{i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"},
			{i, "../foo/include"}]}.

{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF

	cat <<EOF >"${S}/inc_one_line.config" || die
%%% Comment

{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "deps/foo/include"}, {i, "../foo/include"}]}.

{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF

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

{erl_opts, [debug_info, {src_dirs, ["src"]}, {i, "include"}, {i, "${EPREFIX}$(get_erl_libs)/foo-0.1.0/include"}, {i, "../foo/include"}]}.

{port_env, [{"CFLAGS", "\$CFLAGS"}, {"LDFLAGS", "\$LDFLAGS"}]}.
EOF
}

test_typical_config() {
	local diff_rc
	local unit_rc

	# Prepare
	cd "${S}" || die
	cp typical.config rebar.config || die

	# Run unit
	(rebar_fix_include_path foo)
	unit_rc=$?

	# Test result
	diff rebar.config typical.config.expected
	diff_rc=$?

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

test_typical_config_with_different_name() {
	local diff_rc
	local unit_rc

	# Prepare
	cd "${S}" || die
	cp typical.config other.config || die

	# Run unit
	(rebar_fix_include_path foo other.config)
	unit_rc=$?

	# Test result
	diff other.config typical.config.expected
	diff_rc=$?

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

test_multiple_versions() {
	local diff_rc
	local unit_rc

	# Prepare
	cd "${S}" || die
	cp typical.config rebar.config || die
	mkdir -p "${EPREFIX}$(get_erl_libs)/foo-1.0.0/include" || die

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

	# Test result
	diff rebar.config typical.config
	diff_rc=$?

	# Clean up
	rm -r "${EPREFIX}$(get_erl_libs)/foo-1.0.0" || die

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

test_not_found() {
	local diff_rc
	local unit_rc

	# Prepare
	cd "${S}" || die
	cp typical.config rebar.config || die

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

	# Test result
	diff rebar.config typical.config
	diff_rc=$?

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

test_includes_in_one_line() {
	local diff_rc
	local unit_rc

	# Prepare
	cd "${S}" || die
	cp inc_one_line.config rebar.config || die

	# Run unit
	(rebar_fix_include_path foo)
	unit_rc=$?

	# Test result
	diff rebar.config inc_one_line.config.expected
	diff_rc=$?

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

setup

tbegin "rebar_fix_include_path deals with typical config"
test_typical_config
tend $?

tbegin "rebar_fix_include_path deals with typical config with different name"
test_typical_config_with_different_name
tend $?

tbegin "rebar_fix_include_path fails on multiple versions of dependency"
test_multiple_versions
tend $?

tbegin "rebar_fix_include_path fails if dependency is not found"
test_not_found
tend $?

tbegin "rebar_fix_include_path deals with all includes in one line"
test_includes_in_one_line
tend $?

texit