Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/regress regress/show-all: migrate to regress/infra-uni...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/2e816ad92ab6
branches:  trunk
changeset: 435127:2e816ad92ab6
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Wed Jul 01 08:15:58 2020 +0000

description:
regress/show-all: migrate to regress/infra-unittests

The test framework over there makes it easier to run several independent
tests.  The previous way of squeezing all tests into a single package
Makefile did not scale well and made it invonvenient to add new tests.
In addition, there was no need to create a full-fledged package just to
test this tiny piece of the pkgsrc infrastructure, since that can be
used in categories and the top-level as well.

diffstat:

 regress/infra-unittests/show-all.sh |  157 ++++++++++++++++++++++++++++++++++++
 regress/show-all/DESCR              |    5 -
 regress/show-all/Makefile           |   45 ----------
 regress/show-all/PLIST              |    2 -
 regress/show-all/spec               |   90 --------------------
 5 files changed, 157 insertions(+), 142 deletions(-)

diffs (truncated from 319 to 300 lines):

diff -r 4d14ebf55517 -r 2e816ad92ab6 regress/infra-unittests/show-all.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/infra-unittests/show-all.sh       Wed Jul 01 08:15:58 2020 +0000
@@ -0,0 +1,157 @@
+#! /bin/sh
+# $NetBSD: show-all.sh,v 1.1 2020/07/01 08:15:58 rillig Exp $
+#
+# Tests for the show-all target from mk/misc/show.mk.
+#
+# Ensures that the show-all target prints all variants of variable
+# values as intended.  This involves sorted multi-valued variables (like
+# CONFIGURE_ENV), other multi-valued variables (like CONFIGURE_ARGS),
+# variables containing special characters that need to be escaped, and
+# various other edge cases.
+#
+
+. './test.subr'
+
+
+if test_case_begin 'show all'; then
+
+       # Ensures that the output of the show-all target is easily
+       # recognizable by pkgsrc developers.
+       #
+       # The variable values are aligned in column 24 by default.  The
+       # variable assignments have the same form as those that are
+       # written in Makefiles.
+       #
+       # For lists of values, each value is written on a line of its
+       # own, to aid readability.  The final line only contains the
+       # comment marker, for ease of implementation.  This comment
+       # marker also provides a convenient place for remarks like
+       # "sorted" or "ends with space".
+
+       create_file 'test.mk' <<'EOF'
+REGRESS.empty=         # empty
+REGRESS.space=         ${:U } # a single space
+REGRESS.value=         All * kinds of `strange' \escape $$characters
+
+REGRESS_ENV.empty=     # empty
+REGRESS_ENV.space=     ${:U } # a single space
+REGRESS_ENV.value=     VAR1=value1 VAR2=`command execution via backticks` *=all
+
+REGRESS_ARGS.empty=    # empty
+REGRESS_ARGS.space=    ${:U } # a single space
+REGRESS_ARGS.value=    VAR1=value1 VAR2=`command execution via backticks` *=all
+
+# Variable names may also contain special characters that must be escaped.
+#
+# The "*" variable is built-in into bmake and expands to the current
+# make target, which in this case is "show-all-regress".
+#
+# The "**" variable ensures that show-all doesn't accidentally expand
+# filenames.
+*=                     bmake built-in
+**=                    asterisk
+
+_VARGROUPS+=           regress
+_PKG_VARS.regress+=    REGRESS_ENV.undefined REGRESS_ENV.empty REGRESS_ENV.space REGRESS_ENV.value
+_PKG_VARS.regress+=    REGRESS_ARGS.undefined REGRESS_ARGS.empty REGRESS_ARGS.space REGRESS_ARGS.value
+_PKG_VARS.regress+=    REGRESS.undefined REGRESS.empty REGRESS.space REGRESS.value
+_PKG_VARS.regress+=    * **
+_SORTED_VARS.regress=  *_ENV.*
+_LISTED_VARS.regress=  *_ARGS.*
+
+RUN=   @set -eu;
+.include "${PKGSRCDIR}/mk/misc/show.mk"
+EOF
+
+       PKGSRCDIR="$pkgsrcdir" \
+       "$make" -f 'test.mk' 'show-all-regress' 1> 'output' 2>&1 \
+       && exitcode=0 || exitcode=$?
+
+       create_file 'expected' <<'EOF'
+regress:
+  pkg   REGRESS_ENV.undefined   # undefined
+  pkg   REGRESS_ENV.empty=      # empty
+  pkg   REGRESS_ENV.space=      # empty
+  pkg   REGRESS_ENV.value=      \
+                                *=all \
+                                VAR1=value1 \
+                                VAR2=`command \
+                                backticks` \
+                                execution \
+                                via \
+                                # end of REGRESS_ENV.value (sorted)
+  pkg   REGRESS_ARGS.undefined  # undefined
+  pkg   REGRESS_ARGS.empty=     # empty
+  pkg   REGRESS_ARGS.space=     # empty
+  pkg   REGRESS_ARGS.value=     \
+                                VAR1=value1 \
+                                VAR2=`command \
+                                execution \
+                                via \
+                                backticks` \
+                                *=all \
+                                # end of REGRESS_ARGS.value
+  pkg   REGRESS.undefined       # undefined
+  pkg   REGRESS.empty=          # empty
+  pkg   REGRESS.space=           # ends with space
+  pkg   REGRESS.value=          All * kinds of `strange' \escape $$characters
+  pkg   *=                      show-all-regress
+  pkg   **=                     asterisk
+
+EOF
+
+       # On first sight it may seem strange that bmake doesn't handle
+       # the backticks command as a single word. Luckily, this is a
+       # rare case.
+       #
+       # On the other hand, if it did, bmake would also have to handle
+       # variable expansion and all the other syntactic difficulties
+       # from parsing shell commands, and that would be just too much.
+
+       assert_that "$exitcode" --equals '0'
+       assert_that 'output' --file-equals 'expected'
+
+       test_case_end
+fi
+
+
+if test_case_begin 'show dollars in variable values'; then
+
+       create_file 'test.mk' <<'EOF'
+SHELLVAR_PLAIN=                "$$var $${var} $$other $$$$"
+SHELLVAR_ENV=          "$$var $${var} $$other $$$$"
+SHELLVAR_ARGS=         "$$var $${var} $$other $$$$"
+
+_VARGROUPS+=           shellvar
+_PKG_VARS.shellvar=    SHELLVAR_PLAIN SHELLVAR_ENV SHELLVAR_ARGS
+_SORTED_VARS.shellvar= *_ENV
+_LISTED_VARS.shellvar= *_ARGS
+
+RUN=   @set -eu;
+.include "${PKGSRCDIR}/mk/misc/show.mk"
+EOF
+
+       PKGSRCDIR="$pkgsrcdir" \
+       "$make" -f 'test.mk' 'show-all-shellvar' 1> 'output' 2>&1 \
+       && exitcode=0 || exitcode=$?
+
+       # Up to 2020-03-20, the output of the ENV and ARGS variables differed
+       # a lot from the PLAIN variable.
+       #
+       create_file 'expected' <<'EOF'
+shellvar:
+  pkg   SHELLVAR_PLAIN=         "$$var $${var} $$other $$$$"
+  pkg   SHELLVAR_ENV=           \
+                                "$$var $${var} $$other $$$$" \
+                                # end of SHELLVAR_ENV (sorted)
+  pkg   SHELLVAR_ARGS=          \
+                                "$$var $${var} $$other $$$$" \
+                                # end of SHELLVAR_ARGS
+
+EOF
+
+       assert_that "$exitcode" --equals '0'
+       assert_that 'output' --file-equals 'expected'
+
+       test_case_end
+fi
diff -r 4d14ebf55517 -r 2e816ad92ab6 regress/show-all/DESCR
--- a/regress/show-all/DESCR    Wed Jul 01 07:55:46 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-Ensures that the show-all target prints all variants of variable values
-as intended. This involves sorted multi-valued variables (like
-CONFIGURE_ENV), other multi-valued variables (like CONFIGURE_ARGS),
-variables containing special characters that need to be escaped, and
-various other edge cases.
diff -r 4d14ebf55517 -r 2e816ad92ab6 regress/show-all/Makefile
--- a/regress/show-all/Makefile Wed Jul 01 07:55:46 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-# $NetBSD: Makefile,v 1.5 2020/03/20 16:39:03 rillig Exp $
-
-DISTNAME=      show-all-1.0
-CATEGORIES=    regress
-MASTER_SITES=  # none
-DISTFILES=     # none
-
-MAINTAINER=    pkgsrc-users%NetBSD.org@localhost
-COMMENT=       Demonstrates the show-all target
-LICENSE=       2-clause-bsd
-
-REGRESS.empty=         # empty
-REGRESS.space=         ${:U } # a single space
-REGRESS.value=         All * kinds of `strange' \escape $$characters
-
-REGRESS_ENV.empty=     # empty
-REGRESS_ENV.space=     ${:U } # a single space
-REGRESS_ENV.value=     VAR1=value1 VAR2=`command execution via backticks` *=all
-
-REGRESS_ARGS.empty=    # empty
-REGRESS_ARGS.space=    ${:U } # a single space
-REGRESS_ARGS.value=    VAR1=value1 VAR2=`command execution via backticks` *=all
-
-# Variable names may also contain special characters that must be escaped.
-*=                     bmake built-in
-**=                    asterisk
-
-_VARGROUPS+=           regress
-_PKG_VARS.regress+=    REGRESS_ENV.undefined REGRESS_ENV.empty REGRESS_ENV.space REGRESS_ENV.value
-_PKG_VARS.regress+=    REGRESS_ARGS.undefined REGRESS_ARGS.empty REGRESS_ARGS.space REGRESS_ARGS.value
-_PKG_VARS.regress+=    REGRESS.undefined REGRESS.empty REGRESS.space REGRESS.value
-_PKG_VARS.regress+=    * **
-_SORTED_VARS.regress=  *_ENV.*
-_LISTED_VARS.regress=  *_ARGS.*
-
-SHELLVAR_PLAIN=                "$$var $${var} $$other $$$$"
-SHELLVAR_ENV=          "$$var $${var} $$other $$$$"
-SHELLVAR_ARGS=         "$$var $${var} $$other $$$$"
-
-_VARGROUPS+=           shellvar
-_PKG_VARS.shellvar=    SHELLVAR_PLAIN SHELLVAR_ENV SHELLVAR_ARGS
-_SORTED_VARS.shellvar= *_ENV
-_LISTED_VARS.shellvar= *_ARGS
-
-.include "../../mk/bsd.pkg.mk"
diff -r 4d14ebf55517 -r 2e816ad92ab6 regress/show-all/PLIST
--- a/regress/show-all/PLIST    Wed Jul 01 07:55:46 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,2 +0,0 @@
-@comment $NetBSD: PLIST,v 1.1 2018/11/10 10:40:56 rillig Exp $
-@comment intentionally empty
diff -r 4d14ebf55517 -r 2e816ad92ab6 regress/show-all/spec
--- a/regress/show-all/spec     Wed Jul 01 07:55:46 2020 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,90 +0,0 @@
-# $NetBSD: spec,v 1.5 2020/07/01 07:39:52 rillig Exp $
-
-tmpdir=${TMPDIR:-/tmp}/pkgsrc-show-all
-rm -rf "$tmpdir"
-mkdir -p "$tmpdir"
-
-require_file() {
-       if diff -u "$3" "$1" > /dev/null; then
-               :
-       else
-               regress_fail "Expected files to be equal."
-               diff -u "$3" "$1" || true
-       fi
-}
-
-
-do_test() {
-       $TEST_MAKE show-all-regress > "$tmpdir/show-all-regress.out"
-       $TEST_MAKE show-all-shellvar > "$tmpdir/show-all-shellvar.out"
-}
-
-check_result() {
-       exit_status 0
-
-       cat <<'EOF' > "$tmpdir/expected"
-regress:
-  pkg   REGRESS_ENV.undefined   # undefined
-  pkg   REGRESS_ENV.empty=      # empty
-  pkg   REGRESS_ENV.space=      # empty
-  pkg   REGRESS_ENV.value=      \
-                                *=all \
-                                VAR1=value1 \
-                                VAR2=`command \
-                                backticks` \
-                                execution \
-                                via \
-                                # end of REGRESS_ENV.value (sorted)
-  pkg   REGRESS_ARGS.undefined  # undefined
-  pkg   REGRESS_ARGS.empty=     # empty
-  pkg   REGRESS_ARGS.space=     # empty
-  pkg   REGRESS_ARGS.value=     \
-                                VAR1=value1 \
-                                VAR2=`command \
-                                execution \
-                                via \
-                                backticks` \
-                                *=all \
-                                # end of REGRESS_ARGS.value
-  pkg   REGRESS.undefined       # undefined
-  pkg   REGRESS.empty=          # empty
-  pkg   REGRESS.space=           # ends with space
-  pkg   REGRESS.value=          All * kinds of `strange' \escape $$characters
-  pkg   *=                      show-all-regress
-  pkg   **=                     asterisk
-
-EOF
-
-       # The "*" variable is built-in into bmake and expands to the current
-       # make target, which in this case is "show-all-regress".
-
-       # The "**" variable ensures that show-all doesn't accidentally expand
-       # filenames.
-
-       # It's a bit strange that bmake doesn't handle the backticks command
-       # as a single word. Luckily, this is a rare case.
-       #
-       # On the other hand, if it did, bmake would also have to handle
-       # variable expansion and all the other syntactic difficulties from
-       # parsing shell commands, and that would be just too much.
-
-       require_file "$tmpdir/show-all-regress.out" --equals "$tmpdir/expected"



Home | Main Index | Thread Index | Old Index