summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore3
-rw-r--r--tests/aux/common.sh69
-rw-r--r--tests/aux/tap-functions.sh229
-rwxr-xr-xtests/build.sh56
-rw-r--r--tests/local.mk14
-rw-r--r--tests/pkg/control/control3
l---------tests/pkg/data/bin/false1
-rwxr-xr-xtests/pkg/data/bin/true7
-rw-r--r--tests/pkg/data/dev/null0
-rw-r--r--tests/pkg/specials3
-rwxr-xr-xtests/version.sh38
11 files changed, 423 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
new file mode 100644
index 0000000..966477b
--- /dev/null
+++ b/tests/.gitignore
@@ -0,0 +1,3 @@
+*.log
+*.trs
+pkg.opk
diff --git a/tests/aux/common.sh b/tests/aux/common.sh
new file mode 100644
index 0000000..9f9edcc
--- /dev/null
+++ b/tests/aux/common.sh
@@ -0,0 +1,69 @@
+# Functions common to tests
+#
+# Copyright (C) 2018, 2019 Patrick McDermott
+#
+# This file is part of opkg-opk.
+#
+# opkg-opk 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.
+#
+# opkg-opk 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 opkg-opk. If not, see <http://www.gnu.org/licenses/>.
+
+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
+}
+
+cmd_is()
+{
+ local description="${1}"
+ shift 1
+ local ok=
+ local eof=
+ local got=
+ local exp=
+
+ ok=true
+ exec 3<<-EOF
+ $("${@}")
+ EOF
+ while :; do
+ eof=0
+ IFS='' read -r got <&3 || eof=$((${eof} + 1))
+ IFS='' read -r exp <&0 || eof=$((${eof} + 2))
+ [ ${eof} -eq 3 ] && break
+ [ x"${got}" = x"${exp}" ] && continue
+ if ${ok}; then
+ not_ok_ -- "${description}"
+ diag_ " Failed test '${description}'"
+ ok=false
+ fi
+ diag_ " got: '${got}'"
+ diag_ " expected: '${exp}'"
+ done
+ exec 3<&-
+
+ if ${ok}; then
+ ok_ -- "${description}"
+ fi
+}
diff --git a/tests/aux/tap-functions.sh b/tests/aux/tap-functions.sh
new file mode 100644
index 0000000..adc628a
--- /dev/null
+++ b/tests/aux/tap-functions.sh
@@ -0,0 +1,229 @@
+# -*- shell-script -*-
+#
+# Copyright (C) 2011-2023 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/build.sh b/tests/build.sh
new file mode 100755
index 0000000..760d9be
--- /dev/null
+++ b/tests/build.sh
@@ -0,0 +1,56 @@
+# Test for package building
+#
+# Copyright (C) 2023 Patrick McDermott
+#
+# This file is part of opkg-opk.
+#
+# opkg-opk 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.
+#
+# opkg-opk 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 opkg-opk. If not, see <http://www.gnu.org/licenses/>.
+
+set -eu
+
+. "${TOP_SRCDIR}/tests/aux/tap-functions.sh"
+. "${TOP_SRCDIR}/tests/aux/common.sh"
+
+plan_ 2
+
+mkdir -p "${TOP_BUILDDIR}/tests/"
+
+# FIXME: Specify specials override file
+SOURCE_DATE_EPOCH=1685592000 command_ok_ 'package building' -- \
+ "${TOP_BUILDDIR}/opkg-opk" \
+ -b \
+ -c "${TOP_SRCDIR}/tests/pkg/control/" \
+ -d "${TOP_SRCDIR}/tests/pkg/data/" \
+ "${TOP_BUILDDIR}/tests/pkg.opk"
+
+# FIXME: /dev/null should be a char device
+cmd_is 'package info' \
+ "${TOP_BUILDDIR}/opkg-opk" \
+ -f control \
+ -L \
+ "${TOP_BUILDDIR}/tests/pkg.opk" \
+ 0<<-EOF
+ Package: foo
+ Source: foo
+ Version: 1.0
+
+ drwxr-xr-x pj/pj 0 2023-06-01 00:00:00 /
+ drwxr-xr-x pj/pj 0 2023-06-01 00:00:00 /bin/
+ lrwxrwxrwx pj/pj 0 2023-06-01 00:00:00 /bin/false -> true
+ -rwxr-xr-x pj/pj 84 2023-06-01 00:00:00 /bin/true
+ drwxr-xr-x pj/pj 0 2023-06-01 00:00:00 /dev/
+ -rw-r--r-- pj/pj 0 2023-06-01 00:00:00 /dev/null
+ EOF
+
+:
diff --git a/tests/local.mk b/tests/local.mk
new file mode 100644
index 0000000..84833d1
--- /dev/null
+++ b/tests/local.mk
@@ -0,0 +1,14 @@
+TESTS = \
+ %reldir%/version.sh \
+ %reldir%/build.sh
+TEST_EXTENSIONS = .sh
+SH_LOG_DRIVER = \
+ AM_TAP_AWK='$(AWK)' \
+ TOP_SRCDIR="$(abs_top_srcdir)" \
+ TOP_BUILDDIR="$(abs_top_builddir)" \
+ $(SHELL) $(top_srcdir)/build-aux/tap-driver.sh
+EXTRA_DIST += \
+ $(TESTS) \
+ build-aux/tap-driver.sh \
+ tests/aux/tap-functions.sh \
+ tests/aux/common.sh
diff --git a/tests/pkg/control/control b/tests/pkg/control/control
new file mode 100644
index 0000000..6955953
--- /dev/null
+++ b/tests/pkg/control/control
@@ -0,0 +1,3 @@
+Package: foo
+Source: foo
+Version: 1.0
diff --git a/tests/pkg/data/bin/false b/tests/pkg/data/bin/false
new file mode 120000
index 0000000..f32a580
--- /dev/null
+++ b/tests/pkg/data/bin/false
@@ -0,0 +1 @@
+true \ No newline at end of file
diff --git a/tests/pkg/data/bin/true b/tests/pkg/data/bin/true
new file mode 100755
index 0000000..7fe2095
--- /dev/null
+++ b/tests/pkg/data/bin/true
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+if [ x"$(basename "${0}")" = x'true' ]; then
+ return 0
+else
+ return 1
+fi
diff --git a/tests/pkg/data/dev/null b/tests/pkg/data/dev/null
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tests/pkg/data/dev/null
diff --git a/tests/pkg/specials b/tests/pkg/specials
new file mode 100644
index 0000000..c97eef3
--- /dev/null
+++ b/tests/pkg/specials
@@ -0,0 +1,3 @@
+version=1
+type major minor name
+c 1 3 /dev/null
diff --git a/tests/version.sh b/tests/version.sh
new file mode 100755
index 0000000..6038d70
--- /dev/null
+++ b/tests/version.sh
@@ -0,0 +1,38 @@
+# Test for opkg-opk's version output
+#
+# Copyright (C) 2019 Patrick McDermott
+#
+# This file is part of opkg-opk.
+#
+# opkg-opk 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.
+#
+# opkg-opk 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 opkg-opk. If not, see <http://www.gnu.org/licenses/>.
+
+set -eu
+
+. "${TOP_SRCDIR}/tests/aux/tap-functions.sh"
+
+plan_ 1
+
+got="$("${TOP_BUILDDIR}/opkg-opk" -V)"
+case "${got}" in
+ 'opkg-opk '*)
+ result_ 'ok' -- 'opkg-opk version output'
+ ;;
+ *)
+ result_ 'not ok' -- 'opkg-opk version output'
+ diag_ " Failed test 'opkg-opk version output'"
+ diag_ " got: '${got}'"
+ ;;
+esac
+
+: