summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/local.mk11
-rwxr-xr-xtests/parse_control.sh166
2 files changed, 177 insertions, 0 deletions
diff --git a/tests/local.mk b/tests/local.mk
index 9be9cc7..934259e 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -1,5 +1,6 @@
check_PROGRAMS = \
tests/parse_control.basic \
+ tests/parse_control \
tests/resolve_deps.basic \
tests/arch_is_concerned \
tests/plat_is_concerned \
@@ -19,6 +20,16 @@ tests_parse_control_basic_SOURCES = \
tests_parse_control_basic_LDADD = $(tests_parse_control_basic_SOURCES:.sh=.sho)
CLEANFILES += $(tests_parse_control_basic_LDADD)
+tests_parse_control_SOURCES = \
+ tests/parse_control.sh \
+ tests/aux/common.sh \
+ tests/aux/tap-functions.sh \
+ src/locale.sh \
+ src/output.sh \
+ src/control.sh
+tests_parse_control_LDADD = $(tests_parse_control_SOURCES:.sh=.sho)
+CLEANFILES += $(tests_parse_control_LDADD)
+
tests_resolve_deps_basic_SOURCES = \
tests/resolve_deps.basic.sh \
tests/aux/common.sh \
diff --git a/tests/parse_control.sh b/tests/parse_control.sh
new file mode 100755
index 0000000..caf0a29
--- /dev/null
+++ b/tests/parse_control.sh
@@ -0,0 +1,166 @@
+# parse_control() tests
+#
+# Copyright (C) 2019 Patrick McDermott
+#
+# This file is part of the ProteanOS Development Kit.
+#
+# The ProteanOS Development Kit 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.
+#
+# The ProteanOS Development Kit 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 the ProteanOS Development Kit. If not, see
+# <http://www.gnu.org/licenses/>.
+
+LF='
+'
+CONTROL="$(cat <<-'EOF'
+ Package: foo
+ Version: 1.0
+ Description: Frobnicator of Objects
+ This is a frobnicator of objects. Conveniently, it also bit-bangs all
+ registers.
+
+ Package: bar
+ Version: 2.0
+ Description: Bit-bang All Registers
+ This is a frobnicator of objects. Conveniently, it also bit-bangs all
+ registers.
+ EOF
+ )"
+
+field=0
+para=0
+
+field_1()
+{
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'package field name' "${name}" 'Package'
+ is 'package field value' "${value}" 'foo'
+
+ return 0
+}
+
+field_2()
+{
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'version field name' "${name}" 'Version'
+ is 'version field value' "${value}" '1.0'
+
+ return 0
+}
+
+field_3()
+{
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'description field name' "${name}" 'Description'
+ is_diff 'description field value' "${value}" "$(cat <<-'EOF'
+ Frobnicator of Objects
+ This is a frobnicator of objects. Conveniently, it also bit-bangs all
+ registers.
+ EOF
+ )"
+
+ return 0
+}
+
+field_4()
+{
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'package field name' "${name}" 'Package'
+ is 'package field value' "${value}" 'bar'
+
+ return 0
+}
+
+field_5()
+{
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'version field name' "${name}" 'Version'
+ is 'version field value' "${value}" '2.0'
+
+ return 0
+}
+
+field_6()
+{
+ local name="${1}"
+ local value="${2}"
+ shift 2
+
+ is 'description field name' "${name}" 'Description'
+ is_diff 'description field value' "${value}" "$(cat <<-'EOF'
+ Bit-bang All Registers
+ This is a frobnicator of objects. Conveniently, it also bit-bangs all
+ registers.
+ EOF
+ )"
+
+ return 0
+}
+
+field_7()
+{
+ bailout_ 'too many fields'
+}
+
+field_cb()
+{
+ field=$((${field} + 1))
+ "field_${field}" "${@}"
+}
+
+para_1()
+{
+ is 'number of parsed fields' "${field}" 3
+}
+
+para_2()
+{
+ is 'number of parsed fields' "${field}" 6
+}
+
+para_3()
+{
+ bailout_ 'too many paragraphs'
+}
+
+para_cb()
+{
+ para=$((${para} + 1))
+ "para_${para}" "${@}"
+}
+
+main()
+{
+ plan_ 15
+
+ parse_control - field_cb para_cb 'Package' <<-EOF
+ ${CONTROL}
+ EOF
+
+ is 'number of parsed paragraphs' "${para}" 2
+
+ return 0
+}