summaryrefslogtreecommitdiffstats
path: root/tests/lib/ob_parse_control.sh
blob: 06c32e2f1a4a18200db35c6d3849b0674d663a5e (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
# Tests for ob_parse_control()
#
# Copyright (C) 2018, 2019 Patrick McDermott
#
# This file is part of opkbuild.
#
# opkbuild is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# opkbuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with opkbuild.  If not, see <http://www.gnu.org/licenses/>.

set -eu

. "${TOP_SRCDIR}/tests/aux/tap-functions.sh"
. "${TOP_SRCDIR}/tests/aux/common.sh"
. "${TOP_BUILDDIR}/lib/libopkbuild.${SHSOEXT}.${LIBOPKBUILD_SHSOVERSION}"

LF='
'
CONTROL="$(cat <<-'EOF'
	Maintainer: "J. Random Hacker" <jrandom@example.com>
	Build-Depends: opkhelper-3.0,
	 libfoo-dev,
	  libbar-dev,
	Homepage: http://www.example.com/
	EOF
	)"

plan_ 7

field=0

field_1()
{
	local name="${1}"
	local value="${2}"
	local user_data="${3}"
	shift 3

	is 'maintainer field name' "${name}" 'Maintainer'
	is 'maintainer field value' "${value}" \
		'"J. Random Hacker" <jrandom@example.com>'

	return 0
}

field_2()
{
	local name="${1}"
	local value="${2}"
	local user_data="${3}"
	shift 3

	is 'build-depends field name' "${name}" 'Build-Depends'
	is 'build-depends field value' "${value}" \
		"opkhelper-3.0,${LF}libfoo-dev,${LF} libbar-dev,"

	return 0
}

field_3()
{
	local name="${1}"
	local value="${2}"
	local user_data="${3}"
	shift 3

	is 'homepage field name' "${name}" 'Homepage'
	is 'homepage field value' "${value}" 'http://www.example.com/'

	return 0
}

field_4()
{
	: This should not be reached.
}

field_cb()
{
	field=$((${field} + 1))
	"field_${field}" "${@}"
}

ob_parse_control - field_cb '' 'Maintainer' 'Build-Depends Homepage' <<-EOF
	${CONTROL}
	EOF

is 'number of parsed fields' "${field}" 3