diff options
author | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-04-22 01:48:57 (EDT) |
---|---|---|
committer | Patrick McDermott <patrick.mcdermott@libiquity.com> | 2019-04-22 01:48:57 (EDT) |
commit | d841dc0bfb1d18a2f85f76096d4aebc4d772b88e (patch) | |
tree | d3c59eed4e2af1a88b7a6cc7c06f1eee6c4e6110 /tests | |
parent | 44e452fb3c8cc7a093d72fbc280be3973e627a62 (diff) | |
parent | 76885ce7f12b98f0700a3a0535e06425bc1a9aa5 (diff) |
Merge branch 'feature/tap-tests'
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/arch_is_concerned.sh | 187 | ||||
-rw-r--r-- | tests/aux/common.sh | 71 | ||||
-rw-r--r-- | tests/aux/tap-functions.sh | 229 | ||||
-rw-r--r-- | tests/common.sh | 110 | ||||
-rw-r--r-- | tests/local.mk | 29 | ||||
-rwxr-xr-x | tests/match_arch.sh | 71 | ||||
-rwxr-xr-x | tests/match_plat.sh | 63 | ||||
-rw-r--r-- | tests/parse_control.common.sh | 12 | ||||
-rwxr-xr-x | tests/plat_is_concerned.sh | 135 | ||||
-rwxr-xr-x | tests/reduce_deps.sh | 148 | ||||
-rwxr-xr-x | tests/resolve_deps.basic.sh | 9 |
11 files changed, 664 insertions, 400 deletions
diff --git a/tests/arch_is_concerned.sh b/tests/arch_is_concerned.sh index 837d3be..7614dad 100755 --- a/tests/arch_is_concerned.sh +++ b/tests/arch_is_concerned.sh @@ -1,6 +1,6 @@ # arch_is_concerned() tests # -# Copyright (C) 2014 Patrick "P. J." McDermott +# Copyright (C) 2014, 2018, 2019 Patrick McDermott # # This file is part of the ProteanOS Development Kit. # @@ -18,68 +18,157 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -do_test() -{ - local host_arch="${1}" - local arches="${2}" - local result="${3}" - - if arch_is_concerned "${host_arch}" "${arches}"; then - if ! ${result}; then - printf 'False positive:\n' - printf ' Host architecture: "%s"\n' "${host_arch}" - printf ' Package architectures: "%s"\n' "${arches}" - tests_es=1 - fi - else - if ${result}; then - printf 'False negative:\n' - printf ' Host architecture: "%s"\n' "${host_arch}" - printf ' Package architectures: "%s"\n' "${arches}" - tests_es=1 - fi - fi -} - main() { - local arches= + plan_ 24 # Architecture: all - arches='all' - do_test 'amd64-linux-glibc' "${arches}" false - do_test 'i686-linux-glibc' "${arches}" false - do_test 'all' "${arches}" true + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES NOT MATCH ARCH "all"' -- \ + not arch_is_concerned \ + 'amd64-linux-glibc' \ + 'all' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES NOT MATCH ARCH "all"' -- \ + not arch_is_concerned \ + 'i686-linux-glibc' \ + 'all' + command_ok_ \ + 'HOST "all" DOES MATCH ARCH "all"' -- \ + arch_is_concerned \ + 'all' \ + 'all' # Architecture: any - arches='any' - do_test 'amd64-linux-glibc' "${arches}" true - do_test 'i686-linux-glibc' "${arches}" true - do_test 'all' "${arches}" false + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES MATCH ARCH "any"' -- \ + arch_is_concerned \ + 'amd64-linux-glibc' \ + 'any' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES MATCH ARCH "any"' -- \ + arch_is_concerned \ + 'i686-linux-glibc' \ + 'any' + command_ok_ \ + 'HOST "all" DOES NOT MATCH ARCH "any"' -- \ + not arch_is_concerned \ + 'all' \ + 'any' # Architecture: amd64-linux-glibc - arches='amd64-linux-glibc' - do_test 'amd64-linux-glibc' "${arches}" true - do_test 'i686-linux-glibc' "${arches}" false - do_test 'all' "${arches}" false + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES MATCH ARCH '$(: \ + )'"amd64-linux-glibc"' -- \ + arch_is_concerned \ + 'amd64-linux-glibc' \ + 'amd64-linux-glibc' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES NOT MATCH ARCH '$(: \ + )'"amd64-linux-glibc"' -- \ + not arch_is_concerned \ + 'i686-linux-glibc' \ + 'amd64-linux-glibc' + command_ok_ \ + 'HOST "all" DOES NOT MATCH ARCH "amd64-linux-glibc"' -- \ + not arch_is_concerned \ + 'all' \ + 'amd64-linux-glibc' # Architecture: !amd64-linux-glibc - arches='!amd64-linux-glibc' - do_test 'amd64-linux-glibc' "${arches}" false - do_test 'i686-linux-glibc' "${arches}" true - do_test 'all' "${arches}" false + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES NOT MATCH ARCH '$(: \ + )'"!amd64-linux-glibc"' -- \ + not arch_is_concerned \ + 'amd64-linux-glibc' \ + '!amd64-linux-glibc' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES MATCH ARCH '$(: \ + )'"!amd64-linux-glibc"' -- \ + arch_is_concerned \ + 'i686-linux-glibc' \ + '!amd64-linux-glibc' + command_ok_ \ + 'HOST "all" DOES NOT MATCH ARCH "!amd64-linux-glibc"' -- \ + not arch_is_concerned \ + 'all' \ + '!amd64-linux-glibc' # Architecture: amd64-linux-glibc cortexa8-linux-glibc - arches='amd64-linux-glibc cortexa8-linux-glibc' - do_test 'amd64-linux-glibc' "${arches}" true - do_test 'i686-linux-glibc' "${arches}" false - do_test 'all' "${arches}" false + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES MATCH ARCH '$(: \ + )'"amd64-linux-glibc cortexa8-linux-glibc"' -- \ + arch_is_concerned \ + 'amd64-linux-glibc' \ + 'amd64-linux-glibc cortexa8-linux-glibc' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES MATCH ARCH '$(: \ + )'"amd64-linux-glibc cortexa8-linux-glibc"' -- \ + not arch_is_concerned \ + 'i686-linux-glibc' \ + 'amd64-linux-glibc cortexa8-linux-glibc' + command_ok_ \ + 'HOST "all" DOES MATCH ARCH '$(: \ + )'"amd64-linux-glibc cortexa8-linux-glibc"' -- \ + not arch_is_concerned \ + 'all' \ + 'amd64-linux-glibc cortexa8-linux-glibc' # Architecture: amd64-linux-glibc all - arches='amd64-linux-glibc all' - do_test 'amd64-linux-glibc' "${arches}" true - do_test 'i686-linux-glibc' "${arches}" false - do_test 'all' "${arches}" true + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES MATCH ARCH '$(: \ + )'"amd64-linux-glibc all"' -- \ + arch_is_concerned \ + 'amd64-linux-glibc' \ + 'amd64-linux-glibc all' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES NOT MATCH ARCH '$(: \ + )'"amd64-linux-glibc all"' --\ + not arch_is_concerned \ + 'i686-linux-glibc' \ + 'amd64-linux-glibc all' + command_ok_ \ + 'HOST "all" DOES MATCH ARCH "amd64-linux-glibc all"' -- \ + arch_is_concerned \ + 'all' \ + 'amd64-linux-glibc all' + + # Architecture: amd64-any-any + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES NOT MATCH ARCH "amd64-any-any"' -- \ + arch_is_concerned \ + 'amd64-linux-glibc' \ + 'amd64-any-any' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES MATCH ARCH "amd64-any-any"' -- \ + not arch_is_concerned \ + 'i686-linux-glibc' \ + 'amd64-any-any' + command_ok_ \ + 'HOST "all" DOES NOT MATCH ARCH "amd64-any-any"' -- \ + not arch_is_concerned \ + 'all' \ + 'amd64-any-any' + + # Architecture: cortexa8-any-any i686-any-any + command_ok_ \ + 'HOST "amd64-linux-glibc" DOES NOT MATCH ARCH '$(: \ + )'"cortexa8-any-any i686-any-any"' -- \ + not arch_is_concerned \ + 'amd64-linux-glibc' \ + 'cortexa8-any-any i686-any-any' + command_ok_ \ + 'HOST "i686-linux-glibc" DOES MATCH ARCH '$(: \ + )'"cortexa8-any-any i686-any-any"' -- \ + arch_is_concerned \ + 'i686-linux-glibc' \ + 'cortexa8-any-any i686-any-any' + command_ok_ \ + 'HOST "all" DOES NOT MATCH ARCH '$(: \ + )'"cortexa8-any-any i686-any-any"' -- \ + not arch_is_concerned \ + 'all' \ + 'cortexa8-any-any i686-any-any' return 0 } diff --git a/tests/aux/common.sh b/tests/aux/common.sh new file mode 100644 index 0000000..27db133 --- /dev/null +++ b/tests/aux/common.sh @@ -0,0 +1,71 @@ +# Common testsuite functions +# +# 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=' +' + +# is_diff() is based on cmd_is() from opkbuild 4.0.2, with test results passed +# by argument and context added to the diagnostic output. +is_diff() +{ + local description="${1}" + local got="${2}" + local exp="${3}" + shift 3 + local ok= + local diag= + local eof= + + ok=true + diag='' + exec 3<<-EOF + ${got} + EOF + exec 4<<-EOF + ${exp} + EOF + while :; do + eof=0 + read -r got 0<&3 || eof=$((${eof} + 1)) + read -r exp 0<&4 || eof=$((${eof} + 2)) + [ ${eof} -eq 3 ] && break + if [ x"${got}" = x"${exp}" ]; then + diag="${diag} '${got}'${LF}" + else + ok=false + diag="${diag} got: '${got}'${LF}" + diag="${diag} expected: '${exp}'${LF}" + fi + done + exec 3<&- + exec 4<&- + + if ${ok}; then + ok_ -- "${description}" + else + not_ok_ -- "${description}" + diag_ " Failed test '${description}'" + while IFS='' read -r diag; do + diag_ "${diag}" + done <<-EOF + ${diag} + EOF + fi +} diff --git a/tests/aux/tap-functions.sh b/tests/aux/tap-functions.sh new file mode 100644 index 0000000..dd634b3 --- /dev/null +++ b/tests/aux/tap-functions.sh @@ -0,0 +1,229 @@ +# -*- shell-script -*- +# +# Copyright (C) 2011-2018 Free Software Foundation, Inc. +# +# This program 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 2, or (at your option) +# any later version. +# +# This program 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 this program. If not, see <https://www.gnu.org/licenses/>. + +# Helper functions used by TAP-producing tests of the Automake testsuite. + +# +# IMPORTANT: All the functions defined in this file can *not* be used +# from within a subshell, unless explicitly noted otherwise. +# + +# The counts of the TAP test results seen so far: total count and +# per-result counts. +tap_count_=0 +tap_pass_count_=0 +tap_skip_count_=0 +tap_fail_count_=0 +tap_xfail_count_=0 +tap_xpass_count_=0 + +# not COMMAND [ARGS...] +# --------------------- +# Run the given command and invert its exit status. +not () { ! "$@"; } + +# plan_ [unknown|later|lazy|now|NUMBER-OF-PLANNED-TESTS] +# ------------------------------------------------------ +# Print a TAP plan for the given number of tests. This must be called +# before reporting any test result. If called with the special argument +# "unknown" or "later", it will do nothing, expecting the calling script +# to declare the plan later. If called with the special argument "lazy" +# or "now", it will print a TAP plan that accounts for the number of tests +# seen so far. +plan_ () +{ + if test $# -eq 0; then + bailout_ "plan_: missing argument" + elif test $# -ge 2; then + bailout_ "plan_: too many arguments" + elif test x"$planned_" != x"none" && test x"$planned_" != x"later"; then + bailout_ "plan_: called to many times" + elif test x"$1" = x"unknown" || test x"$1" = x"later"; then + # This means we want to get back later to declaring the TAP plan. + planned_=later + return 0 + elif test x"$1" = x"lazy" || test x"$1" = x"now"; then + planned_=$tap_count_ # Number of test results seen so far. + elif test $1 -ge 0; then + planned_=$1 + else + bailout_ "plan_: invalid argument '$1'" + fi + echo "1..$planned_" +} +planned_=none + +# diag_ [EXPLANATION] +# ------------------ +# Report the given text as TAP diagnostic. Assumes the string denoting +# TAP diagnostic lines is stored in the '$diag_string_' variable; this is +# done to allow better interplay with TAP drivers that allow such a string +# to be configured. +diag_ () +{ + test $# -eq 0 || echo "$diag_string_ $*" +} + +# Used by the 'diag_' function above. User-overridable. +diag_string_="#" + +# warn_ [EXPLANATION] +# ------------------ +# Give a warning (using TAP diagnostic). +warn_ () +{ + case $# in + 0) diag_ "WARNING: (unknown warning)";; + *) diag_ "WARNING: $*";; + esac +} + +# result_ RESULT [-D DIRECTIVE] [-r REASON] [--] [DESCRIPTION...] +# --------------------------------------------------------------- +# Report a test case with the given RESULT (valid values are "ok" and +# "not ok") and the given DESCRIPTION (if any). If DIRECTIVE is given +# and non-empty (valid values being "TODO" and "SKIP"), it will be +# reported too, with the REASON (if given) appended. +result_ () +{ + test $# -gt 0 || bailout_ "result_: missing argument" + tap_result_=$1; shift + case $tap_result_ in + "ok"|"not ok") ;; + *) bailout_ "result_: invalid result '$tap_result'" ;; + esac + tap_directive_= tap_reason_= + while test $# -gt 0; do + case $1 in + -D|--directive) tap_directive_=$2; shift;; + -r|--reason) tap_reason_=$2; shift;; + --) shift; break;; + -*) bailout_ "result_: invalid option '$1'";; + *) break;; + esac + shift + done + case $tap_directive_ in + ""|TODO|SKIP) ;; + *) bailout_ "result_: invalid directive '$directive_'" ;; + esac + tap_count_=$(($tap_count_ + 1)) + case $tap_result_,$tap_directive_ in + ok,) # Passed. + tap_pass_count_=$(($tap_pass_count_ + 1)) ;; + not\ ok,TODO) # Expected failure. + tap_xfail_count_=$(($tap_xfail_count_ + 1)) ;; + not\ ok,*) # Failed. + tap_fail_count_=$(($tap_fail_count_ + 1)) ;; + ok,TODO) # Unexpected pass. + tap_xpass_count_=$(($tap_xpass_count_ + 1)) ;; + ok,SKIP) # Skipped. + tap_skip_count_=$(($tap_skip_count_ + 1)) ;; + *) # Can't happen. + bailout_ "internal error in 'result_'" ;; + esac + tap_text_="$tap_result_ $tap_count_" + if test x"$*" != x; then + tap_text_="$tap_text_ - $*" + fi + if test x"$tap_directive_" != x; then + tap_text_="$tap_text_ # $tap_directive_"${tap_reason_:+" $tap_reason_"} + fi + printf '%s\n' "$tap_text_" +} + +# Shorthands for common usages of 'result_'. +ok_ () { result_ 'ok' ${1+"$@"}; } +not_ok_ () { result_ 'not ok' ${1+"$@"}; } +skip_ () { result_ 'ok' -D SKIP ${1+"$@"}; } + +# skip_row_ COUNT [-r REASON] [--] [DESCRIPTION...] +# ------------------------------------------------- +# Report a COUNT of skipped test, with the given reason and descriptions +# (if any). Useful to avoid cascade failures in case a fair number of +# tests depend on an earlier one that failed. +skip_row_ () +{ + skip_count_=$1; shift + for i_ in $(seq_ $skip_count_); do skip_ ${1+"$@"}; done +} + +# skip_all_ [REASON ...] +# ---------------------- +# Skip all the tests in a test script. Must be used before calling 'plan_' +# or reporting any test result. Can't be used from within a subshell. +skip_all_ () +{ + echo "1..0 # SKIP" ${1+"$@"} + planned_=0 + exit 0 +} + +# bailout_ [REASON ...] +# --------------------- +# Stop the execution of the current test suite right now, due to an +# unrecoverable error. Can be called at any point, but cannot be used +# from within a subshell. +bailout_ () +{ + echo 'Bail out!' ${1+"$@"} + exit 99 +} + +# fatal_ [REASON ...] +# ------------------- +# Same as 'bailout_'; for compatibility with 'plain-functions.sh'. +fatal_ () +{ + bailout_ ${1+"$@"} +} + +# framework_failure_ [REASON ...] +# ------------------------------- +# Stop the execution of the current test suite right now, due to an +# unrecoverable error in the set-up of the test case. Can be called +# at any point, but cannot be used from within a subshell. +framework_failure_ () +{ + bailout_ "set-up failure"${1+": $*"} +} + +# command_ok_ TEST-DESCRIPTION [OPTIONS..] [--] CMD [ARGS...] +# ----------------------------------------------------------- +# Helper subroutine for when a TAP result must be determined by the +# outcome of a command. +command_ok_ () +{ + tap_directive_= tap_reason_= + test $# -gt 0 || bailout_ "command_ok_: missing argument" + tap_description_=$1; shift + while test $# -gt 0; do + case $1 in + -D|--directive) tap_directive_=$2; shift;; + -r|--reason) tap_reason_=$2; shift;; + --) shift; break;; + -*) bailout_ "command_ok_: invalid option '$1'";; + *) break;; + esac + shift + done + tap_result_="ok"; "$@" || tap_result_="not ok" + result_ "$tap_result_" -D "$tap_directive_" -r "$tap_reason_" \ + -- "$tap_description_" +} + +: diff --git a/tests/common.sh b/tests/common.sh deleted file mode 100644 index 293dc7d..0000000 --- a/tests/common.sh +++ /dev/null @@ -1,110 +0,0 @@ -# Common testsuite functions -# -# Copyright (C) 2013, 2014 Patrick "P. J." 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/>. - -tests_es=0 -atexit() -{ - local es=${?} - - if [ ${es} -ne 0 ]; then - exit ${es} - else - exit ${tests_es} - fi -} -trap atexit EXIT - -in_place=true -builddir='.' - -assert() -{ - if ! eval "${@}"; then - warn 'Assertion failed: %s\n' "${*}" - tests_es=1 - fi -} - -if [ "x${COLOR_TEST_LOGS:-no}" = 'xno' ]; then - red= grn= lgn= blu= mgn= std= -else - red='[0;31m' # Red. - grn='[0;32m' # Green. - lgn='[1;32m' # Light green. - blu='[1;34m' # Blue. - mgn='[0;35m' # Magenta. - std='[m' # No color. -fi - -test_diff() -{ - local good_results="${1}" - local test_results="${2}" - local line_no= - local errors= - local good_line= - local test_line= - local line= - - printf 'Diff:\n' - exec 3<<-EOF - ${good_results} - EOF - exec 4<<-EOF - ${test_results} - EOF - line_no=0 - while :; do - line_no=$(($line_no + 1)) - errors=0 - read -r good_line <&3 || errors=$(($errors + 1)) - read -r test_line <&4 || errors=$(($errors + 1)) - [ ${errors} -eq 2 ] && break - if [ "x${good_line}" = "x${test_line}" ]; then - printf '%3d %s\n' ${line_no} "${good_line}" - else - printf '%3d %s-%s%s\n' ${line_no} "${red}" \ - "${good_line}" "${std}" - printf '%3d %s+%s%s\n' ${line_no} "${grn}" \ - "${test_line}" "${std}" - tests_es=1 - fi - done - exec 3<&- - exec 4<&- - - printf '\nExpected results:\n' - line_no=0 - while read -r line; do - line_no=$(($line_no + 1)) - printf '%3d %s\n' ${line_no} "${line}" - done <<-EOF - ${good_results} - EOF - printf '\nTest results:\n' - line_no=0 - while read -r line; do - line_no=$(($line_no + 1)) - printf '%3d %s\n' ${line_no} "${line}" - done <<-EOF - ${test_results} - EOF - printf '\n' -} diff --git a/tests/local.mk b/tests/local.mk index 6eb9878..42ac039 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -1,8 +1,6 @@ check_PROGRAMS = \ tests/parse_control.basic \ tests/resolve_deps.basic \ - tests/match_arch \ - tests/match_plat \ tests/arch_is_concerned \ tests/plat_is_concerned \ tests/reduce_deps @@ -12,7 +10,9 @@ TESTS = $(check_PROGRAMS) tests_parse_control_basic_SOURCES = \ tests/parse_control.basic.sh \ tests/parse_control.common.sh \ - tests/common.sh \ + tests/aux/common.sh \ + tests/aux/tap-functions.sh \ + src/locale.sh \ src/output.sh \ src/control.sh tests_parse_control_basic_LDADD = $(tests_parse_control_basic_SOURCES:.sh=.sho) @@ -20,42 +20,29 @@ CLEANFILES += $(tests_parse_control_basic_LDADD) tests_resolve_deps_basic_SOURCES = \ tests/resolve_deps.basic.sh \ - tests/common.sh \ + tests/aux/common.sh \ + tests/aux/tap-functions.sh \ src/deps.sh tests_resolve_deps_basic_LDADD = $(tests_resolve_deps_basic_SOURCES:.sh=.sho) CLEANFILES += $(tests_resolve_deps_basic_LDADD) -tests_match_arch_SOURCES = \ - tests/match_arch.sh \ - tests/common.sh \ - src/archplat.sh -tests_match_arch_LDADD = $(tests_match_arch_SOURCES:.sh=.sho) -CLEANFILES += $(tests_match_arch_LDADD) - -tests_match_plat_SOURCES = \ - tests/match_plat.sh \ - tests/common.sh \ - src/archplat.sh -tests_match_plat_LDADD = $(tests_match_plat_SOURCES:.sh=.sho) -CLEANFILES += $(tests_match_plat_LDADD) - tests_arch_is_concerned_SOURCES = \ tests/arch_is_concerned.sh \ - tests/common.sh \ + tests/aux/tap-functions.sh \ src/archplat.sh tests_arch_is_concerned_LDADD = $(tests_arch_is_concerned_SOURCES:.sh=.sho) CLEANFILES += $(tests_arch_is_concerned_LDADD) tests_plat_is_concerned_SOURCES = \ tests/plat_is_concerned.sh \ - tests/common.sh \ + tests/aux/tap-functions.sh \ src/archplat.sh tests_plat_is_concerned_LDADD = $(tests_plat_is_concerned_SOURCES:.sh=.sho) CLEANFILES += $(tests_plat_is_concerned_LDADD) tests_reduce_deps_SOURCES = \ tests/reduce_deps.sh \ - tests/common.sh \ + tests/aux/tap-functions.sh \ src/deps.sh \ src/archplat.sh tests_reduce_deps_LDADD = $(tests_reduce_deps_SOURCES:.sh=.sho) diff --git a/tests/match_arch.sh b/tests/match_arch.sh deleted file mode 100755 index 2d3693b..0000000 --- a/tests/match_arch.sh +++ /dev/null @@ -1,71 +0,0 @@ -# match_arch() tests -# -# Copyright (C) 2014 Patrick "P. J." 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/>. - -do_test() -{ - local arch="${1}" - local arch_field="${2}" - local result="${3}" - - if match_arch "${arch}" "${arch_field}"; then - if [ "x${result}" = 'xfalse' ]; then - printf 'False positive:\n' - printf ' arch: %s\n arch_field: %s\n' \ - "${arch}" "${arch_field}" - tests_es=1 - fi - else - if [ "x${result}" = 'xtrue' ]; then - printf 'False negative:\n' - printf ' arch: %s\n arch_field: %s\n' \ - "${arch}" "${arch_field}" - tests_es=1 - fi - fi -} - -main() -{ - do_test all 'all' true - - do_test foo-bar-baz 'any' true - - do_test foo-bar-baz 'any all' true - - do_test all 'any all' true - - do_test foo-bar-baz 'foo-bar-baz' true - - do_test foo-bar-baz 'foo-any-any' true - - do_test foo-bar-baz 'foo-bar-qux' false - - do_test foo-bar-baz 'any-qux-any any-bar-any' true - - do_test foo-bar-baz 'any-qux-any any-quux-any' false - - do_test all 'any' false - - do_test any 'all' false - - do_test all 'foo-any-any' false - - return 0 -} diff --git a/tests/match_plat.sh b/tests/match_plat.sh deleted file mode 100755 index 039f76a..0000000 --- a/tests/match_plat.sh +++ /dev/null @@ -1,63 +0,0 @@ -# match_plat() tests -# -# Copyright (C) 2014 Patrick "P. J." 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/>. - -do_test() -{ - local plat="${1}" - local plat_field="${2}" - local result="${3}" - - if match_plat "${plat}" "${plat_field}"; then - if [ "x${result}" = 'xfalse' ]; then - printf 'False positive:\n' - printf ' plat: %s\n plat_field: %s\n' \ - "${plat}" "${plat_field}" - tests_es=1 - fi - else - if [ "x${result}" = 'xtrue' ]; then - printf 'False negative:\n' - printf ' plat: %s\n plat_field: %s\n' \ - "${plat}" "${plat_field}" - tests_es=1 - fi - fi -} - -main() -{ - do_test all 'all' true - - do_test dev 'any' true - - do_test dev 'any all' true - - do_test all 'any all' true - - do_test dev 'dev' true - - do_test dev 'ao751h' false - - do_test all 'any' false - - do_test any 'all' false - - return 0 -} diff --git a/tests/parse_control.common.sh b/tests/parse_control.common.sh index 9eee27b..c084cee 100644 --- a/tests/parse_control.common.sh +++ b/tests/parse_control.common.sh @@ -1,6 +1,6 @@ # Common parse_control() tests functions # -# Copyright (C) 2014 Patrick "P. J." McDermott +# Copyright (C) 2014 Patrick McDermott # # This file is part of the ProteanOS Development Kit. # @@ -18,8 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -load_locale - HT=' ' LF=' ' @@ -38,13 +36,19 @@ para() main() { + plan_ 1 + + in_place=true + builddir='.' + load_locale + parse_control - field para "${req_fields}" <<-EOF ${packages} EOF printf 'Required fields: %s\n\n' "${req_fields}" - test_diff "${results}" "${test_results}" + is_diff 'parse_control() paragraphs' "${results}" "${test_results}" return 0 } diff --git a/tests/plat_is_concerned.sh b/tests/plat_is_concerned.sh index 120aa5a..0905a22 100755 --- a/tests/plat_is_concerned.sh +++ b/tests/plat_is_concerned.sh @@ -1,6 +1,6 @@ # plat_is_concerned() tests # -# Copyright (C) 2014 Patrick "P. J." McDermott +# Copyright (C) 2014, 2018, 2019 Patrick McDermott # # This file is part of the ProteanOS Development Kit. # @@ -18,60 +18,111 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -do_test() -{ - local host_plat="${1}" - local plats="${2}" - local result="${3}" - - if plat_is_concerned "${host_plat}" "${plats}"; then - if ! ${result}; then - printf 'False positive:\n' - printf ' Host platform: "%s"\n' "${host_plat}" - printf ' Package platforms: "%s"\n' "${plats}" - tests_es=1 - fi - else - if ${result}; then - printf 'False negative:\n' - printf ' Host platform: "%s"\n' "${host_plat}" - printf ' Package platforms: "%s"\n' "${plats}" - tests_es=1 - fi - fi -} - main() { + plan_ 18 + # Platform: all - do_test dev 'all' false - do_test ao751h 'all' false - do_test all 'all' true + command_ok_ \ + 'HOST "dev" DOES NOT MATCH PLAT "all"' -- \ + not plat_is_concerned \ + 'dev' \ + 'all' + command_ok_ \ + 'HOST "ao751h" DOES NOT MATCH PLAT "all"' -- \ + not plat_is_concerned \ + 'ao751h' \ + 'all' + command_ok_ \ + 'HOST "all" DOES MATCH PLAT "all"' -- \ + plat_is_concerned \ + 'all' \ + 'all' # Platform: any - do_test dev 'any' true - do_test ao751h 'any' true - do_test all 'any' false + command_ok_ \ + 'HOST "dev" DOES MATCH PLAT "any"' -- \ + plat_is_concerned \ + 'dev' \ + 'any' + command_ok_ \ + 'HOST "ao751h" DOES MATCH PLAT "any"' -- \ + plat_is_concerned \ + 'ao751h' \ + 'any' + command_ok_ \ + 'HOST "all" DOES NOT MATCH PLAT "any"' -- \ + not plat_is_concerned \ + 'all' \ + 'any' # Platform: dev - do_test dev 'dev' true - do_test ao751h 'dev' false - do_test all 'dev' false + command_ok_ \ + 'HOST "dev" DOES MATCH PLAT "dev"' -- \ + plat_is_concerned \ + 'dev' \ + 'dev' + command_ok_ \ + 'HOST "ao751h" DOES NOT MATCH PLAT "dev"' -- \ + not plat_is_concerned \ + 'ao751h' \ + 'dev' + command_ok_ \ + 'HOST "all" DOES NOT MATCH PLAT "dev"' -- \ + not plat_is_concerned \ + 'all' \ + 'dev' # Platform: !dev - do_test dev '!dev' false - do_test ao751h '!dev' true - do_test all '!dev' false + command_ok_ \ + 'HOST "dev" DOES NOT MATCH PLAT "!dev"' -- \ + not plat_is_concerned \ + 'dev' \ + '!dev' + command_ok_ \ + 'HOST "ao751h" DOES MATCH PLAT "!dev"' -- \ + plat_is_concerned \ + 'ao751h' \ + '!dev' + command_ok_ \ + 'HOST "all" DOES NOT MATCH PLAT "!dev"' -- \ + not plat_is_concerned \ + 'all' \ + '!dev' # Platform: dev dimension2400 - do_test 'dev' 'dev dimension2400' true - do_test 'ao751h' 'dev dimension2400' false - do_test 'all' 'dev dimension2400' false + command_ok_ \ + 'HOST "dev" DOES MATCH PLAT "dev dimension2400"' -- \ + plat_is_concerned \ + 'dev' \ + 'dev dimension2400' + command_ok_ \ + 'HOST "ao751h" DOES NOT MATCH PLAT "dev dimension2400"' -- \ + not plat_is_concerned \ + 'ao751h' \ + 'dev dimension2400' + command_ok_ \ + 'HOST "all" DOES NOT MATCH PLAT "dev dimension2400"' -- \ + not plat_is_concerned \ + 'all' \ + 'dev dimension2400' # Platform: dev all - do_test 'dev' 'dev all' true - do_test 'ao751h' 'dev all' false - do_test 'all' 'dev all' true + command_ok_ \ + 'HOST "dev" DOES MATCH PLAT "dev all"' -- \ + plat_is_concerned \ + 'dev' \ + 'dev all' + command_ok_ \ + 'HOST "ao751h" DOES NOT MATCH PLAT "dev all"' -- \ + not plat_is_concerned \ + 'ao751h' \ + 'dev all' + command_ok_ \ + 'HOST "all" DOES MATCH PLAT "dev all"' -- \ + plat_is_concerned \ + 'all' \ + 'dev all' return 0 } diff --git a/tests/reduce_deps.sh b/tests/reduce_deps.sh index 386b609..41a4b58 100755 --- a/tests/reduce_deps.sh +++ b/tests/reduce_deps.sh @@ -1,6 +1,6 @@ # reduce_deps() tests # -# Copyright (C) 2014 Patrick "P. J." McDermott +# Copyright (C) 2014, 2018, 2019 Patrick McDermott # # This file is part of the ProteanOS Development Kit. # @@ -18,51 +18,125 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -do_test() -{ - local deps="${1}" - local union="${2}" - local host_arch="${3}" - local host_plat="${4}" - local result="${5}" - - deps="$(reduce_deps "${deps}" "${union}" "${host_arch}" "${host_plat}")" - - if [ "x${deps}" != "x${result}" ]; then - ${union} && printf 'Union' || printf 'Normal' - printf ' dependency list for ' - printf 'host arch "%s" and host plat "%s":\n' \ - "${host_arch}" "${host_plat}" - printf ' "%s" != "%s"\n' \ - "${deps}" "${result}" - tests_es=1 - fi -} - main() { + plan_ 13 + # Normal and union AND-lists. - do_test 'foo, bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' - do_test 'foo,bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' - do_test 'foo, bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' - do_test 'foo, bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' - do_test 'foo,bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' - do_test 'foo, bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' + command_ok_ \ + 'NORMAL LIST "foo, bar"' -- \ + [ x"$(reduce_deps \ + 'foo, bar' false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo, bar' \ + ] + command_ok_ \ + 'NORMAL LIST "foo,bar"' -- \ + [ x"$(reduce_deps \ + 'foo,bar' false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo, bar' \ + ] + command_ok_ \ + 'NORMAL LIST "foo, bar"' -- \ + [ x"$(reduce_deps \ + 'foo, bar' false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo, bar' \ + ] + command_ok_ \ + 'UNION LIST "foo, bar"' -- \ + [ x"$(reduce_deps \ + 'foo, bar' true \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo, bar' \ + ] + command_ok_ \ + 'UNION LIST "foo,bar"' -- \ + [ x"$(reduce_deps \ + 'foo,bar' true \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo, bar' \ + ] + command_ok_ \ + 'UNION LIST "foo, bar"' -- \ + [ x"$(reduce_deps \ + 'foo, bar' true \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo, bar' \ + ] # Normal and union OR-lists. - do_test 'foo | bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' - do_test 'foo|bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' - do_test 'foo | bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' + command_ok_ \ + 'NORMAL LIST "foo | bar"' -- \ + [ x"$(reduce_deps \ + 'foo | bar' false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo | bar' \ + ] + command_ok_ \ + 'NORMAL LIST "foo|bar"' -- \ + [ x"$(reduce_deps \ + 'foo|bar' false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo | bar' \ + ] + command_ok_ \ + 'NORMAL LIST "foo | bar"' -- \ + [ x"$(reduce_deps \ + 'foo | bar' false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo | bar' \ + ] # Normal and union AND-lists with arch specs. - do_test 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' false \ - 'amd64-linux-glibc' 'dev' 'foo' - do_test 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' true \ - 'amd64-linux-glibc' 'dev' 'foo' + command_ok_ \ + 'NORMAL LIST "foo [amd64-linux-glibc], '$(: \ + )'bar [!amd64-linux-glibc]"' -- \ + [ x"$(reduce_deps \ + 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' \ + false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo' \ + ] + command_ok_ \ + 'UNION LIST "foo [amd64-linux-glibc], '$(: \ + )'bar [!amd64-linux-glibc]"' -- \ + [ x"$(reduce_deps \ + 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' \ + true \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo' \ + ] # Normal and union AND-lists with plat specs. - do_test 'foo <dev>, bar <!dev>' false 'amd64-linux-glibc' 'dev' 'foo' - do_test 'foo <dev>, bar <!dev>' true 'amd64-linux-glibc' 'dev' 'foo' + command_ok_ \ + 'NORMAL LIST "foo <dev>, bar <!dev>"' -- \ + [ x"$(reduce_deps \ + 'foo <dev>, bar <!dev>' false \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo' \ + ] + command_ok_ \ + 'UNION LIST "foo <dev>, bar <!dev>"' -- \ + [ x"$(reduce_deps \ + 'foo <dev>, bar <!dev>' true \ + 'amd64-linux-glibc' 'dev' \ + )" = \ + x'foo' \ + ] return 0 } diff --git a/tests/resolve_deps.basic.sh b/tests/resolve_deps.basic.sh index 3edad56..9281bb4 100755 --- a/tests/resolve_deps.basic.sh +++ b/tests/resolve_deps.basic.sh @@ -1,6 +1,6 @@ # Basic resolve_deps() test # -# Copyright (C) 2014 Patrick "P. J." McDermott +# Copyright (C) 2014 Patrick McDermott # # This file is part of the ProteanOS Development Kit. # @@ -30,14 +30,17 @@ main() local results= local test_results= + plan_ 2 + results='foo bar baz qux quux' test_results="$(resolve_deps "${pkgs}" "${deps}")" - test_diff "${results}" "${test_results}" + is_diff 'resolve_deps' "${results}" "${test_results}" results="$(printf '%s\n' ${results} | sort)" test_results="$(printf '%s\n' $(resolve_deps "${pkgs}" "${deps}") | \ sort)" - test_diff "${results}" "${test_results}" + is_diff 'resolve_deps (split into multiple lines)' \ + "${results}" "${test_results}" return 0 } |