diff --git a/regress/Makefile b/regress/Makefile index 9f97c2bde9f0..4e2e1c708b55 100644 --- a/regress/Makefile +++ b/regress/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.21 2018/11/10 10:40:55 rillig Exp $ +# $NetBSD: Makefile,v 1.22 2019/03/21 21:45:30 rillig Exp $ # # See https://www.netbsd.org/docs/pkgsrc/regression.html for more # information about these tests. @@ -15,6 +15,7 @@ SUBDIR+= check-portability SUBDIR+= compiler SUBDIR+= env-vars SUBDIR+= ignore-tools +SUBDIR+= infra-unittests SUBDIR+= make-env-phases SUBDIR+= make-quoting SUBDIR+= pkg-options diff --git a/regress/infra-unittests/mocked-include.sh b/regress/infra-unittests/mocked-include.sh new file mode 100644 index 000000000000..cec97a319b1e --- /dev/null +++ b/regress/infra-unittests/mocked-include.sh @@ -0,0 +1,20 @@ +#! /bin/sh +set -eu + +# Ensures that files that are overridden in the "mocked pkgsrc" directory +# are picked up before those from the "real pkgsrc" directory. + +. "./test.subr" + +create_file "including.mk" <&2 + exit 1 +} + +maybe_cleanup() { + exit_status=$? + if [ $exit_status -ne 0 ]; then + printf 'info: the test files are in %s\n' "$tmpdir" 1>&2 + exit $exit_status + fi + + [ "$cleanup" = "yes" ] && rm -rf "$tmpdir" +} +trap "maybe_cleanup" EXIT + +mock_cmd() { + cmdname="$1" + shift 1 + + { + printf '#! /bin/sh\n\n' + while [ $# -ge 4 ]; do + case $1,$3 in + (--when-args,--then-output) + cat <&2 + exit 1 + ;; + esac + done + cat <&2 +exit 1 +EOF + } > "$tmpdir/$cmdname" + chmod +x "$tmpdir/$cmdname" + + printf '%s\n' "$tmpdir/$cmdname" +} + +create_file() { + cat > "$tmpdir/$1" +} + +create_pkgsrc_file() { + mkdir -p "$mocked_pkgsrcdir/$(dirname "$1")" + cat > "$mocked_pkgsrcdir/$1" +} + +test_file() { + cat < "$tmpdir/test.subr.main.mk" +PKGSRCDIR= $real_pkgsrcdir +.PATH: $mocked_pkgsrcdir +.PATH: $real_pkgsrcdir +.include "$1" +EOF + shift + + bmake -f "$tmpdir/test.subr.main.mk" "$@" +} + +assert_that() { + case "$2" in + (--equals) + [ "x$1" = "x$3" ] && return 0 + printf 'assertion failed:\nexpected: <%s>\nbut was: <%s>\n' "$3" "$1" 1>&2 + exit 1 + (*) + printf 'usage: assert_that --equals \n' 1>&2 + exit 1 + esac +} diff --git a/regress/infra-unittests/tools-bison.sh b/regress/infra-unittests/tools-bison.sh new file mode 100644 index 000000000000..160328d64a06 --- /dev/null +++ b/regress/infra-unittests/tools-bison.sh @@ -0,0 +1,59 @@ +#! /bin/sh +set -eu + +# Tests for mk/tools/bison.mk + +. "./test.subr" + +bison=$(mock_cmd mock-bison \ + --when-args "--version" --then-output "bison 1.5" +) + +pkg_admin=$(mock_cmd mock-pkg_admin \ + --when-args "pmatch bison>=1.0 bison-1.5" --then-exit 0 \ + --when-args "pmatch bison>=1.1 bison-1.5" --then-exit 0 \ + --when-args "pmatch bison>=2.0 bison-1.5" --then-exit 1 +) + +# A package may add more than one entry to the BISON_REQD list. The +# platform-provided bison may only be used if all of the BISON_REQD +# entries are below the platform-provided version. +# +create_file "multiple-reqd-entries.mk" <