Sat May 2 07:24:32 2020 UTC ()
regress: move tests for platform tools to tools-platform


(rillig)
diff -r1.15 -r1.16 pkgsrc/regress/tools/Makefile
diff -r0 -r1.1 pkgsrc/regress/tools-platform/awk.test
diff -r0 -r1.1 pkgsrc/regress/tools-platform/sed.test
diff -r0 -r1.1 pkgsrc/regress/tools-platform/sort.test
diff -r0 -r1.1 pkgsrc/regress/tools-platform/tar.test
diff -r0 -r1.1 pkgsrc/regress/tools-platform/tests.subr
diff -r0 -r1.1 pkgsrc/regress/tools-platform/tr.test
diff -r1.1 -r1.2 pkgsrc/regress/tools-platform/sh.test
diff -r1.1 -r1.2 pkgsrc/regress/tools-platform/spec
diff -r1.8 -r0 pkgsrc/regress/tools/files/awk-test.sh
diff -r1.1 -r0 pkgsrc/regress/tools/files/sed-test.sh
diff -r1.1 -r0 pkgsrc/regress/tools/files/sort-test.sh
diff -r1.1 -r0 pkgsrc/regress/tools/files/tar-test.sh
diff -r1.3 -r0 pkgsrc/regress/tools/files/sh-test.sh
diff -r1.2 -r0 pkgsrc/regress/tools/files/tr-test.sh

cvs diff -r1.15 -r1.16 pkgsrc/regress/tools/Makefile (expand / switch to unified diff)

--- pkgsrc/regress/tools/Makefile 2019/03/24 11:29:19 1.15
+++ pkgsrc/regress/tools/Makefile 2020/05/02 07:24:31 1.16
@@ -1,32 +1,30 @@ @@ -1,32 +1,30 @@
1# $NetBSD: Makefile,v 1.15 2019/03/24 11:29:19 rillig Exp $ 1# $NetBSD: Makefile,v 1.16 2020/05/02 07:24:31 rillig Exp $
2# 2#
3 3
4DISTNAME= # not applicable 4DISTNAME= # not applicable
5PKGNAME= regress-tools-1.2 5PKGNAME= regress-tools-1.2
6CATEGORIES= regress 6CATEGORIES= regress
7MASTER_SITES= # none 7MASTER_SITES= # none
8DISTFILES= # none 8DISTFILES= # none
9 9
10MAINTAINER= pkgsrc-users@NetBSD.org 10MAINTAINER= pkgsrc-users@NetBSD.org
11COMMENT= Test whether the TOOLS do what I expect 11COMMENT= Test whether the TOOLS do what I expect
12LICENSE= 2-clause-bsd 12LICENSE= 2-clause-bsd
13 13
14WRKSRC= ${WRKDIR} 14WRKSRC= ${WRKDIR}
15NO_CHECKSUM= yes 15NO_CHECKSUM= yes
16PLIST_SRC= # none 16PLIST_SRC= # none
17REGRESS_TESTS+= logging shquote 17REGRESS_TESTS+= logging shquote
18REGRESS_TESTS+= awk sed sh sort tar tr 
19USE_TOOLS+= awk sed sh sort tar tr 
20 18
21TOOLS_CREATE+= script-dquot 19TOOLS_CREATE+= script-dquot
22TOOLS_SCRIPT.script-dquot= \ 20TOOLS_SCRIPT.script-dquot= \
23 echo "hello; world" 21 echo "hello; world"
24 22
25TOOLS_CREATE+= script-backslash 23TOOLS_CREATE+= script-backslash
26TOOLS_SCRIPT.script-backslash= \ 24TOOLS_SCRIPT.script-backslash= \
27 echo hello\;\ world 25 echo hello\;\ world
28 26
29# If both of the above tools are properly quoted during logging, the 27# If both of the above tools are properly quoted during logging, the
30# semicolon in "hello; world" is never interpreted as a shell command 28# semicolon in "hello; world" is never interpreted as a shell command
31# delimiter, and this tool is never run. 29# delimiter, and this tool is never run.
32TOOLS_CREATE+= world 30TOOLS_CREATE+= world

File Added: pkgsrc/regress/tools-platform/awk.test
#! /bin/sh
# $NetBSD: awk.test,v 1.1 2020/05/02 07:24:32 rillig Exp $
#

set -e

mydir=`dirname "$0"`
. "${mydir}/tests.subr"

#
# Functions specific for the awk testsuite.
#

# usage: test_assignment <testname> <input> <expected-output>
test_assignment() {
	testcase_start "$1"
	o=`echo "" | awk '{print var}' var="$2"`
	assert_equal "$1" "$3" "${o}"
}

# usage: test_passline <testname> <input>
test_passline() {
	testcase_start "$1"
	o=`awk '{print}' <<EOF
$2
EOF
`
	assert_equal "$1" "$2" "${o}"
}

#
# The actual test.
#

#
# Assignment of variables from the command line. The Solaris
# /usr/bin/awk does not conform to the POSIX specification, but passes
# the right hand side of the assignment uninterpreted. It fails the
# cmd.3 test case. The "for" loop makes sure that awk can handle strings
# of 4096 bytes length.
#
test_assignment "cmd.1" \
	"foo" "foo"
test_assignment "cmd.2" \
	"foo bar baz" "foo bar baz"
test_assignment "cmd.3" \
	"CPPFLAGS=\\\"-Dfoo=bar\\\"" "CPPFLAGS=\"-Dfoo=bar\""
line="a"
for i in 0 1 2 3 4 5 6 7 8 9 10 11 12; do
	test_assignment "cmd.2^${i}" "${line}" "${line}"
	line="${line}${line}"
done

#
# Passing strings from stdin to stdout. awk should be able to handle at
# least 2^12 characters per line.
#
# Solaris 9 /usr/bin/awk: 2559 bytes
# Solaris 9 /usr/bin/nawk: 6144 bytes
#
line="a"
for i in 0 1 2 3 4 5 6 7 8 9 10 11 12; do
	test_passline "line.2^${i}" "${line}"
	line="${line}${line}"
done

File Added: pkgsrc/regress/tools-platform/sed.test
#! /bin/sh
# $NetBSD: sed.test,v 1.1 2020/05/02 07:24:32 rillig Exp $
#

set -e

mydir=`dirname "$0"`
. "${mydir}/tests.subr"

#
# Functions specific for the "sed" testsuite.
#

# usage: sed_test <testname> <input> <expected-output> <args...>
sed_test() {
	testname=$1; input=$2; expected=$3; shift 3;

	testcase_start "${testname}"
	output=`sed "$@" <<EOF
$input
EOF
`
	assert_equal "${testname}" "${expected}" "${output}"
}

#
# The actual test.
#

nl="
"

#
# Make sure that sed(1) can handle character classes.
#
sed_test "[[:character classes:]]" \
	"hello${nl}foo bar" \
	"hello" \
	-e "/[[:space:]]/d"

File Added: pkgsrc/regress/tools-platform/sort.test
#! /bin/sh
# $NetBSD: sort.test,v 1.1 2020/05/02 07:24:32 rillig Exp $
#

set -e

mydir=`dirname "$0"`
. "${mydir}/tests.subr"

#
# Functions specific for the "sort" testsuite.
#

# usage: sort_test <testname> <input> <expected-output> <args...>
sort_test() {
	testname=$1; input=$2; expected=$3; shift 3;

	testcase_start "${testname}"
	output=`sort "$@" <<EOF
$input
EOF
`
	assert_equal "${testname}" "${expected}" "${output}"
}

#
# The actual test.
#

nl="
"

sort_test "one line" \
	"text line 1" "text line 1"
sort_test "uppercase letters" \
	"A${nl}B${nl}C" "A${nl}B${nl}C"
sort_test "A < C < b" \
	"A${nl}b${nl}C" "A${nl}C${nl}b"

File Added: pkgsrc/regress/tools-platform/tar.test
#! /bin/sh
# $NetBSD: tar.test,v 1.1 2020/05/02 07:24:32 rillig Exp $
#

set -e

mydir=`dirname "$0"`
. "${mydir}/tests.subr"

#
# Functions specific for the tar testsuite.
#

# none.

#
# The actual test.
#

# tar must support the -z option.
#
testcase_start "-z"
echo "data" > file
tar cfz archive.tar.gz file

File Added: pkgsrc/regress/tools-platform/tests.subr
# $NetBSD: tests.subr,v 1.1 2020/05/02 07:24:32 rillig Exp $
#

# usage: testcase_start <testname>
testcase_start() {
	printf "  Running testcase %s\\n" "$1"
}

# usage: assert_equal <testname> <expected> <got>
assert_equal() {
	[ "x$2" = "x$3" ] && return 0
	printf "error: assert_equal failed for \"%s\":\nexpected: %s\nbut got:  %s\n" "$1" "$2" "$3" 1>&2
	return 1
}

File Added: pkgsrc/regress/tools-platform/tr.test
#! /bin/sh
# $NetBSD: tr.test,v 1.1 2020/05/02 07:24:32 rillig Exp $
#

set -e

mydir=`dirname "$0"`
. "${mydir}/tests.subr"

#
# Functions specific for the tr testsuite.
#

# usage: tr_test <testname> <input> <expected-output> <args...>
tr_test() {
	testname=$1; input=$2; expected=$3; shift 3;

	testcase_start "${testname}"
	output=`tr "$@" <<EOF
$input
EOF
`
	assert_equal "${testname}" "${expected}" "${output}"
}

#
# The actual test.
#

nl="
"

tr_test "simple" \
	"foo" "baa" "fo" "ba"
tr_test "tolower" \
	"The Great Green Fox" "the great green fox" "A-Z" "a-z"
tr_test "eat-newlines" \
	"foo${nl}bar${nl}" "foobar" -d "\\n"
tr_test "eat-minus" \
	"describe-function" "describefunction" -d "-"
tr_test "eat-minus-d" \
	"describe-function" "escribefunction" -d -- "-d"
tr_test "eat-d-minus" \
	"describe-function" "escribefunction" -d "d-"

s="0123456789abcdef"
s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"
s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"
s="$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s$s"
f="ffffffffffffffff"
f="$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f"
f="$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f$f"

tr_test "65536" \
	"$s" "$f" -d "0-9a-e"

cvs diff -r1.1 -r1.2 pkgsrc/regress/tools-platform/sh.test (expand / switch to unified diff)

--- pkgsrc/regress/tools-platform/sh.test 2020/05/01 18:37:59 1.1
+++ pkgsrc/regress/tools-platform/sh.test 2020/05/02 07:24:32 1.2
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: sh.test,v 1.1 2020/05/01 18:37:59 rillig Exp $ 2# $NetBSD: sh.test,v 1.2 2020/05/02 07:24:32 rillig Exp $
3# 3#
4# Tests for the shell that is available as ${SH} in Makefiles. 4# Tests for the shell that is available as ${SH} in Makefiles.
5# 5#
6# Having a feature tested in this file does not mean it is available in 6# Having a feature tested in this file does not mean it is available in
7# Makefiles since devel/bmake may use a completely different shell for 7# Makefiles since devel/bmake may use a completely different shell for
8# running its commands. For example on SunOS, devel/bmake typically 8# running its commands. For example on SunOS, devel/bmake typically
9# uses /usr/xpg4/bin/sh while TOOLS_PLATFORM.sh is /bin/ksh. 9# uses /usr/xpg4/bin/sh while TOOLS_PLATFORM.sh is /bin/ksh.
10 10
11set -eu 11set -eu
12 12
13dief() { 13dief() {
14 printf 'error: [sh.test] ' 1>&2 14 printf 'error: [sh.test] ' 1>&2
15 printf "$@" 1>&2 15 printf "$@" 1>&2
@@ -29,13 +29,25 @@ assert_that() { @@ -29,13 +29,25 @@ assert_that() {
29} 29}
30 30
31pathname="first/second/third/fourth" 31pathname="first/second/third/fourth"
32 32
33# Make sure that the usual word expansions work. 33# Make sure that the usual word expansions work.
34assert_that "##: ${pathname##*/}" --equals "##: fourth" 34assert_that "##: ${pathname##*/}" --equals "##: fourth"
35assert_that "#: ${pathname#*/}" --equals "#: second/third/fourth" 35assert_that "#: ${pathname#*/}" --equals "#: second/third/fourth"
36assert_that "%%: ${pathname%%/*}" --equals "%%: first" 36assert_that "%%: ${pathname%%/*}" --equals "%%: first"
37assert_that "%: ${pathname%/*}" --equals "%: first/second/third" 37assert_that "%: ${pathname%/*}" --equals "%: first/second/third"
38 38
39# Make sure that $(...) subshells work. 39# Make sure that $(...) subshells work.
40assert_that "subshell: $(echo world | tr 'world' 'hello')" \ 40assert_that "subshell: $(echo world | tr 'world' 'hello')" \
41 --equals "subshell: hello" 41 --equals "subshell: hello"
 42
 43# In NetBSD 7, /bin/sh handled backslashes in word expansions incorrectly.
 44# See https://gnats.netbsd.org/43469.
 45line='#define bindir "/usr/bin" /* bar */'
 46case $MACHINE_PLATFORM in
 47(NetBSD-[0-7].*-*)
 48 assert_that "${line%%/\**}" --equals '#define bindir "'
 49 ;;
 50(*)
 51 assert_that "${line%%/\**}" --equals '#define bindir "/usr/bin" '
 52 ;;
 53esac

cvs diff -r1.1 -r1.2 pkgsrc/regress/tools-platform/spec (expand / switch to unified diff)

--- pkgsrc/regress/tools-platform/spec 2020/05/01 18:37:59 1.1
+++ pkgsrc/regress/tools-platform/spec 2020/05/02 07:24:32 1.2
@@ -1,39 +1,49 @@ @@ -1,39 +1,49 @@
1# $NetBSD: spec,v 1.1 2020/05/01 18:37:59 rillig Exp $ 1# $NetBSD: spec,v 1.2 2020/05/02 07:24:32 rillig Exp $
2# 2#
3# Tests for the platform-provided tools. 3# Tests for the platform-provided tools.
4# 4#
5# The individual *.test files are run in a minimal environment. 5# The individual *.test files are run in a minimal environment.
6# In that environment, only the PATH is set, and it points to a 6# In that environment, only the PATH is set, and it points to a
7# directory containing only the tools from mk/tools/tools.${OPSYS}.mk. 7# directory containing only the tools from mk/tools/tools.${OPSYS}.mk.
8# 8#
 9# Additionally, MACHINE_PLATFORM is set, so that the tests can expect
 10# different results depending on the platform. This is used for
 11# documenting bugs that have been fixed in a certain version.
 12#
9# The individual tests may create arbitrary files in their current 13# The individual tests may create arbitrary files in their current
10# working directory. 14# working directory.
11# 15#
12 16
13do_test() { 17do_test() {
14 regressdir="$PWD" 18 regressdir="$PWD"
15 tmpdir="$(mktemp -d)" || { TEST_EXITSTATUS=$?; return; } 19 tmpdir="$(mktemp -d)" || { TEST_EXITSTATUS=$?; return; }
16 bindir="$tmpdir/bin" 20 bindir="$tmpdir/bin"
17 mkdir "$bindir" 21 mkdir "$bindir"
18 ( 22 (
19 cd ../../pkgtools/digest \ 23 cd ../../pkgtools/digest \
20 && $TEST_MAKE \ 24 && $TEST_MAKE \
21 BINDIR="$bindir" \ 25 BINDIR="$bindir" \
22 -f "$regressdir/zzz-prepare-tools.mk" \ 26 -f "$regressdir/zzz-prepare-tools.mk" \
23 "prepare-platform-tools" 27 "prepare-platform-tools"
24 ) 28 )
 29 machine_platform=$(
 30 cd ../../pkgtools/digest \
 31 && $TEST_MAKE show-var VARNAME=MACHINE_PLATFORM
 32 )
25 33
26 for testfile in *.test; do 34 for testfile in *.test; do
27 mkdir "$tmpdir/work" 35 mkdir "$tmpdir/work"
28 (cd "$tmpdir/work" && "$bindir/env" -i PATH="$bindir" \ 36 (cd "$tmpdir/work" && "$bindir/env" -i \
 37 MACHINE_PLATFORM="$machine_platform" \
 38 PATH="$bindir" \
29 "sh" "$regressdir/$testfile") \ 39 "sh" "$regressdir/$testfile") \
30 || TEST_EXITSTATUS=$? 40 || TEST_EXITSTATUS=$?
31 rm -rf "$tmpdir/work" 41 rm -rf "$tmpdir/work"
32 done 42 done
33 43
34 rm -rf "$tmpdir" 44 rm -rf "$tmpdir"
35} 45}
36 46
37check_result() { 47check_result() {
38 exit_status 0 48 exit_status 0
39} 49}

File Deleted: pkgsrc/regress/tools/files/Attic/awk-test.sh

File Deleted: pkgsrc/regress/tools/files/Attic/sed-test.sh

File Deleted: pkgsrc/regress/tools/files/Attic/sort-test.sh

File Deleted: pkgsrc/regress/tools/files/Attic/tar-test.sh

File Deleted: pkgsrc/regress/tools/files/Attic/sh-test.sh

File Deleted: pkgsrc/regress/tools/files/Attic/tr-test.sh