From e12e99c4fea06eaa13e4d08f4d9001b7f815fe2b Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 17 Mar 2019 01:23:28 -0400 Subject: tests/*.sh: Move to tests/lib/ --- (limited to 'tests/lib/ob_parse_control.sh') diff --git a/tests/lib/ob_parse_control.sh b/tests/lib/ob_parse_control.sh new file mode 100755 index 0000000..921d99e --- /dev/null +++ b/tests/lib/ob_parse_control.sh @@ -0,0 +1,113 @@ +# 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 . + +set -eu + +. "${TOP_SRCDIR}/tests/aux/tap-functions.sh" +. "${TOP_BUILDDIR}/lib/libopkbuild.${SHSOEXT}.${LIBOPKBUILD_SHSOVERSION}" + +LF=' +' +CONTROL="$(cat <<-'EOF' + Maintainer: "J. Random Hacker" + 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() +{ + 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" ' + + 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 -- cgit v0.9.1