regress: move tests for platform tools to tools-platformdiff -r1.15 -r1.16 pkgsrc/regress/tools/Makefile
(rillig)
@@ -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 | |||
4 | DISTNAME= # not applicable | 4 | DISTNAME= # not applicable | |
5 | PKGNAME= regress-tools-1.2 | 5 | PKGNAME= regress-tools-1.2 | |
6 | CATEGORIES= regress | 6 | CATEGORIES= regress | |
7 | MASTER_SITES= # none | 7 | MASTER_SITES= # none | |
8 | DISTFILES= # none | 8 | DISTFILES= # none | |
9 | 9 | |||
10 | MAINTAINER= pkgsrc-users@NetBSD.org | 10 | MAINTAINER= pkgsrc-users@NetBSD.org | |
11 | COMMENT= Test whether the TOOLS do what I expect | 11 | COMMENT= Test whether the TOOLS do what I expect | |
12 | LICENSE= 2-clause-bsd | 12 | LICENSE= 2-clause-bsd | |
13 | 13 | |||
14 | WRKSRC= ${WRKDIR} | 14 | WRKSRC= ${WRKDIR} | |
15 | NO_CHECKSUM= yes | 15 | NO_CHECKSUM= yes | |
16 | PLIST_SRC= # none | 16 | PLIST_SRC= # none | |
17 | REGRESS_TESTS+= logging shquote | 17 | REGRESS_TESTS+= logging shquote | |
18 | REGRESS_TESTS+= awk sed sh sort tar tr | |||
19 | USE_TOOLS+= awk sed sh sort tar tr | |||
20 | 18 | |||
21 | TOOLS_CREATE+= script-dquot | 19 | TOOLS_CREATE+= script-dquot | |
22 | TOOLS_SCRIPT.script-dquot= \ | 20 | TOOLS_SCRIPT.script-dquot= \ | |
23 | echo "hello; world" | 21 | echo "hello; world" | |
24 | 22 | |||
25 | TOOLS_CREATE+= script-backslash | 23 | TOOLS_CREATE+= script-backslash | |
26 | TOOLS_SCRIPT.script-backslash= \ | 24 | TOOLS_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. | |
32 | TOOLS_CREATE+= world | 30 | TOOLS_CREATE+= world |
#! /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
#! /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"
#! /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"
#! /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
# $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
}
#! /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"
@@ -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 | |||
11 | set -eu | 11 | set -eu | |
12 | 12 | |||
13 | dief() { | 13 | dief() { | |
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 | |||
31 | pathname="first/second/third/fourth" | 31 | pathname="first/second/third/fourth" | |
32 | 32 | |||
33 | # Make sure that the usual word expansions work. | 33 | # Make sure that the usual word expansions work. | |
34 | assert_that "##: ${pathname##*/}" --equals "##: fourth" | 34 | assert_that "##: ${pathname##*/}" --equals "##: fourth" | |
35 | assert_that "#: ${pathname#*/}" --equals "#: second/third/fourth" | 35 | assert_that "#: ${pathname#*/}" --equals "#: second/third/fourth" | |
36 | assert_that "%%: ${pathname%%/*}" --equals "%%: first" | 36 | assert_that "%%: ${pathname%%/*}" --equals "%%: first" | |
37 | assert_that "%: ${pathname%/*}" --equals "%: first/second/third" | 37 | assert_that "%: ${pathname%/*}" --equals "%: first/second/third" | |
38 | 38 | |||
39 | # Make sure that $(...) subshells work. | 39 | # Make sure that $(...) subshells work. | |
40 | assert_that "subshell: $(echo world | tr 'world' 'hello')" \ | 40 | assert_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. | |||
45 | line='#define bindir "/usr/bin" /* bar */' | |||
46 | case $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 | ;; | |||
53 | esac |
@@ -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 | |||
13 | do_test() { | 17 | do_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 | |||
37 | check_result() { | 47 | check_result() { | |
38 | exit_status 0 | 48 | exit_status 0 | |
39 | } | 49 | } |