summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-01-05 09:37:03 (EST)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-01-05 09:37:03 (EST)
commit146d06fbe738cf9adaabc2f00f4101d5b074af56 (patch)
tree135f5112d5e21c060052e23390d5273530d92def /tests
parent9e8d063448603922bcbd5b64cf45b5473bd1455e (diff)
tests/ob_parse_control.sh: New test file
Diffstat (limited to 'tests')
-rw-r--r--tests/local.mk3
-rwxr-xr-xtests/ob_parse_control.sh97
2 files changed, 99 insertions, 1 deletions
diff --git a/tests/local.mk b/tests/local.mk
index 0dfa4a0..56c7468 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -4,7 +4,8 @@ TESTS = \
%reldir%/ob_reduce_deps.sh \
%reldir%/ob_arch_is_concerned.sh \
%reldir%/ob_plat_is_concerned.sh \
- %reldir%/ob_parse_changelog.sh
+ %reldir%/ob_parse_changelog.sh \
+ %reldir%/ob_parse_control.sh
TEST_EXTENSIONS = .sh
SH_LOG_DRIVER = \
AM_TAP_AWK='$(AWK)' \
diff --git a/tests/ob_parse_control.sh b/tests/ob_parse_control.sh
new file mode 100755
index 0000000..90bcb0e
--- /dev/null
+++ b/tests/ob_parse_control.sh
@@ -0,0 +1,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/>.
+
+. "${TOP_SRCDIR}/tests/aux/tap-functions.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
+
+is()
+{
+ local description="${1}"
+ local got="${2}"
+ local expected="${3}"
+ shift 3
+
+ if [ "x${got}" = "x${expected}" ]; then
+ ok_ -- "${description}"
+ else
+ not_ok_ -- "${description}"
+ diag_ " Failed test '${description}'"
+ diag_ " got: '${got}'"
+ diag_ " expected: '${expected}'"
+ fi
+}
+
+field_1()
+{
+ is 'maintainer field name' "${OB_CONTROL_NAME}" 'Maintainer'
+ is 'maintainer field value' "${OB_CONTROL_VALUE}" \
+ '"J. Random Hacker" <jrandom@example.com>'
+
+ return 0
+}
+
+field_2()
+{
+ is 'build-depends field name' "${OB_CONTROL_NAME}" 'Build-Depends'
+ is 'build-depends field value' "${OB_CONTROL_VALUE}" \
+ "opkhelper-3.0,${LF}libfoo-dev,${LF} libbar-dev,"
+
+ return 0
+}
+
+field_3()
+{
+ is 'homepage field name' "${OB_CONTROL_NAME}" 'Homepage'
+ is 'homepage field value' "${OB_CONTROL_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