Source-Changes-HG archive

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

[pkgsrc/trunk]: pkgsrc/regress/tools-platform regress: add tools-platform/ fo...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/66dc1889e1f1
branches:  trunk
changeset: 430529:66dc1889e1f1
user:      rillig <rillig%pkgsrc.org@localhost>
date:      Fri May 01 18:37:59 2020 +0000

description:
regress: add tools-platform/ for testing the platform tools

Right now, the tests in regress/tools are a mixture of testing the pkgsrc
infrastructure in mk/tools and the tools provided by the platforms.
These don't go well together, therefore the tests for the platform tools
will be migrated here.

diffstat:

 regress/tools-platform/sh.test              |  41 +++++++++++++++++++++++++++++
 regress/tools-platform/spec                 |  39 +++++++++++++++++++++++++++
 regress/tools-platform/zzz-prepare-tools.mk |  40 ++++++++++++++++++++++++++++
 3 files changed, 120 insertions(+), 0 deletions(-)

diffs (132 lines):

diff -r f60eff36aacb -r 66dc1889e1f1 regress/tools-platform/sh.test
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/tools-platform/sh.test    Fri May 01 18:37:59 2020 +0000
@@ -0,0 +1,41 @@
+#! /bin/sh
+# $NetBSD: sh.test,v 1.1 2020/05/01 18:37:59 rillig Exp $
+#
+# Tests for the shell that is available as ${SH} in Makefiles.
+#
+# Having a feature tested in this file does not mean it is available in
+# Makefiles since devel/bmake may use a completely different shell for
+# running its commands.  For example on SunOS, devel/bmake typically
+# uses /usr/xpg4/bin/sh while TOOLS_PLATFORM.sh is /bin/ksh.
+
+set -eu
+
+dief() {
+       printf 'error: [sh.test] ' 1>&2
+       printf "$@" 1>&2
+       printf '\n' 1>&2
+       exit 1
+}
+
+assert_that() {
+       case $2 in
+       (--equals)
+               [ "x$1" = "x$3" ] \
+               || dief 'assertion failed: expected "%s", got "%s"' "$3" "$1"
+               ;;
+       (*)     dief 'wrong assert_that call: %s' "$*"
+               ;;
+       esac
+}
+
+pathname="first/second/third/fourth"
+
+# Make sure that the usual word expansions work.
+assert_that "##: ${pathname##*/}"      --equals "##: fourth"
+assert_that "#: ${pathname#*/}"                --equals "#: second/third/fourth"
+assert_that "%%: ${pathname%%/*}"      --equals "%%: first"
+assert_that "%: ${pathname%/*}"                --equals "%: first/second/third"
+
+# Make sure that $(...) subshells work.
+assert_that "subshell: $(echo world | tr 'world' 'hello')" \
+       --equals "subshell: hello"
diff -r f60eff36aacb -r 66dc1889e1f1 regress/tools-platform/spec
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/tools-platform/spec       Fri May 01 18:37:59 2020 +0000
@@ -0,0 +1,39 @@
+# $NetBSD: spec,v 1.1 2020/05/01 18:37:59 rillig Exp $
+#
+# Tests for the platform-provided tools.
+#
+# The individual *.test files are run in a minimal environment.
+# In that environment, only the PATH is set, and it points to a
+# directory containing only the tools from mk/tools/tools.${OPSYS}.mk.
+#
+# The individual tests may create arbitrary files in their current
+# working directory.
+#
+
+do_test() {
+       regressdir="$PWD"
+       tmpdir="$(mktemp -d)" || { TEST_EXITSTATUS=$?; return; }
+       bindir="$tmpdir/bin"
+       mkdir "$bindir"
+       (
+               cd ../../pkgtools/digest \
+               && $TEST_MAKE \
+                       BINDIR="$bindir" \
+                       -f "$regressdir/zzz-prepare-tools.mk" \
+                       "prepare-platform-tools"
+       )
+
+       for testfile in *.test; do
+               mkdir "$tmpdir/work"
+               (cd "$tmpdir/work" && "$bindir/env" -i PATH="$bindir" \
+                       "sh" "$regressdir/$testfile") \
+               || TEST_EXITSTATUS=$?
+               rm -rf "$tmpdir/work"
+       done
+
+       rm -rf "$tmpdir"
+}
+
+check_result() {
+       exit_status 0
+}
diff -r f60eff36aacb -r 66dc1889e1f1 regress/tools-platform/zzz-prepare-tools.mk
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/regress/tools-platform/zzz-prepare-tools.mk       Fri May 01 18:37:59 2020 +0000
@@ -0,0 +1,40 @@
+# $NetBSD: zzz-prepare-tools.mk,v 1.1 2020/05/01 18:37:59 rillig Exp $
+#
+# This "package" creates wrappers for the platform tools in a temporary
+# directory.
+#
+
+PKGNAME=       tools-platform-2020.05.01
+CATEGORIES=    pkgtools
+
+USE_TOOLS=     chmod sed sh tr
+
+.include "../../mk/bsd.prefs.mk"
+
+PLATFORM_TOOLS!= \
+       ${SED} -n \
+               's,^TOOLS_PLATFORM\.\([^[:space:]]*\)[?]=.*,\1,p' \
+               ../../mk/tools/tools.*.mk
+
+prepare-platform-tools:
+.for tool in ${PLATFORM_TOOLS:O:u}
+.  if ${TOOLS_PLATFORM.${tool}:U} && ${TOOLS_PLATFORM.${tool}:[#]} == 1
+.    for cmd in ${TOOLS_PLATFORM.${tool}}
+.      if ${cmd:M/*}
+       @ln -s ${cmd:Q} ${BINDIR:Q}/${tool:Q}
+.      elif ${cmd} == "[" || ${cmd:Necho:Nfalse:Ntest:Ntrue} != ${cmd}
+# ignore these shell builtins
+.      else
+       @${ECHO} "Skipping single-word tool "${tool:Q}": "${cmd:Q}
+.      endif
+.    endfor
+.  elif ${TOOLS_PLATFORM.${tool}:U}
+       @{ \
+               ${ECHO} '#! '${SH:Q};                                   \
+               ${ECHO} 'exec '${TOOLS_PLATFORM.${tool}:Q}' "$$@"';     \
+       } > ${BINDIR:Q}/${tool:Q}
+       @${CHMOD} +x ${BINDIR:Q}/${tool:Q}
+.  endif
+.endfor
+
+.include "../../mk/bsd.pkg.mk"



Home | Main Index | Thread Index | Old Index