summaryrefslogtreecommitdiff
path: root/mk/pkgtasks/tests
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2017-06-01 02:06:04 +0000
committerjlam <jlam@pkgsrc.org>2017-06-01 02:06:04 +0000
commit097f66db251a632208d70b1e836294373236b6a5 (patch)
tree8163edb98fb66c45fbe4e8d36ae5d7950660c3e4 /mk/pkgtasks/tests
parent90ec6bcdd0556552a73fb825631d794bc5bef991 (diff)
downloadpkgsrc-097f66db251a632208d70b1e836294373236b6a5.tar.gz
Add "pkgtasks" framework to generate data files used by pkgtasks.
A full dependency on the "pkgtasks" package will be added if a non-empty data file is generated by the framework. This framework is not yet hooked into bsd.pkg.mk, pending some other changes.
Diffstat (limited to 'mk/pkgtasks/tests')
-rw-r--r--mk/pkgtasks/tests/Kyuafile61
-rwxr-xr-xmk/pkgtasks/tests/create_usergroup_test169
-rwxr-xr-xmk/pkgtasks/tests/directories_test111
-rwxr-xr-xmk/pkgtasks/tests/files_test168
-rwxr-xr-xmk/pkgtasks/tests/fonts_test116
-rwxr-xr-xmk/pkgtasks/tests/groups_test113
-rwxr-xr-xmk/pkgtasks/tests/info_files_test109
-rwxr-xr-xmk/pkgtasks/tests/ocaml_findlib_test104
-rwxr-xr-xmk/pkgtasks/tests/permissions_test110
-rwxr-xr-xmk/pkgtasks/tests/pkgtasks_test139
-rwxr-xr-xmk/pkgtasks/tests/shells_test104
-rwxr-xr-xmk/pkgtasks/tests/shlibs_test100
-rw-r--r--mk/pkgtasks/tests/test.mk69
-rwxr-xr-xmk/pkgtasks/tests/users_test113
14 files changed, 1586 insertions, 0 deletions
diff --git a/mk/pkgtasks/tests/Kyuafile b/mk/pkgtasks/tests/Kyuafile
new file mode 100644
index 00000000000..d904646df59
--- /dev/null
+++ b/mk/pkgtasks/tests/Kyuafile
@@ -0,0 +1,61 @@
+-- $NetBSD: Kyuafile,v 1.1 2017/06/01 02:06:05 jlam Exp $
+--[[-----------------------------------------------------------------------
+Copyright (c) 2017 The NetBSD Foundation, Inc.
+All rights reserved.
+
+This code is derived from software contributed to The NetBSD Foundation
+by Johnny C. Lam.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+--]]-----------------------------------------------------------------------
+
+--[[-----------------------------------------------------------------------
+
+ The following variables will be used if they are set.
+
+ MAKE The name or path to the BSD make(1) utility. The default
+ is "make".
+
+ PKGSRCDIR
+ The location of the pkgsrc source tree. The default is
+ "/usr/pkgsrc".
+
+--]]-----------------------------------------------------------------------
+
+syntax( 2 )
+
+test_suite( "pkgsrc_pkgtasks" )
+
+atf_test_program { name = "create_usergroup_test",
+ required_programs = "perl" }
+atf_test_program { name = "directories_test" }
+atf_test_program { name = "files_test" }
+atf_test_program { name = "fonts_test" }
+atf_test_program { name = "groups_test" }
+atf_test_program { name = "info_files_test" }
+atf_test_program { name = "ocaml_findlib_test" }
+atf_test_program { name = "permissions_test" }
+atf_test_program { name = "pkgtasks_test" }
+atf_test_program { name = "shells_test" }
+atf_test_program { name = "shlibs_test" }
+atf_test_program { name = "users_test" }
diff --git a/mk/pkgtasks/tests/create_usergroup_test b/mk/pkgtasks/tests/create_usergroup_test
new file mode 100755
index 00000000000..9575fbd1cb2
--- /dev/null
+++ b/mk/pkgtasks/tests/create_usergroup_test
@@ -0,0 +1,169 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: create_usergroup_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# LOCALBASE
+# The location of the installation directory for packages.
+# The default is "/usr/pkg".
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+# TASK_MODULE_DIR
+# The location of the pkgtasks modules directory. The
+# default is "${LOCALBASE}/share/pkgtasks-1".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/usergroup.mk"
+
+all: create-usergroup
+
+pre-cmd: .PHONY
+ ${PRE_CMD.su-create-usergroup}; exit 1
+
+.PHONY: su-target
+su-target: .USE
+ ${RUN}${PRE_CMD.su-create-usergroup}; ${MAKE} su-${.TARGET}
+EOF
+}
+
+###
+### test1: pre-command check for existent group
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pre-command check for existent group"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+USERGROUP_PHASE= build
+PKG_GROUPS= wheel
+PERL5= perl
+EOF
+ ${MAKE} pre-cmd PKGSRCDIR="${PKGSRCDIR}" ||
+ atf_fail "existent group wasn't found"
+ atf_pass
+}
+
+###
+### test2: pre-command check for nonexistent group
+###
+
+atf_test_case test2
+
+test2_head()
+{
+ atf_set "descr" "pre-command check for nonexistent group"
+}
+
+test2_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+USERGROUP_PHASE= build
+PKG_GROUPS= nonexistent
+PERL5= perl
+EOF
+ ${MAKE} pre-cmd PKGSRCDIR="${PKGSRCDIR}"
+ [ $? -gt 0 ] || atf_fail "nonexistent group was found"
+ atf_pass
+}
+
+###
+### test3: create-usergroup
+###
+
+atf_test_case test3
+
+test3_head()
+{
+ : ${LOCALBASE:=/usr/pkg}
+ : ${TASK_MODULE_DIR:=${LOCALBASE}/share/pkgtasks-1}
+
+ atf_set "descr" "create-usergroup with existing group & user"
+ atf_set "require.files" "${TASK_MODULE_DIR}/load.subr"
+}
+
+test3_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+USERGROUP_PHASE= build
+PKG_CREATE_USERGROUP= no
+PKG_GROUPS= wheel
+PKG_USERS= root:wheel
+
+PERL5= perl
+PKGNAME= test-pkg
+SETENV= env
+SH= /bin/sh
+PKG_REFCOUNT_DBDIR= ${.CURDIR}/refcount
+EOF
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" ||
+ atf_fail "couldn't create groups and users"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+ atf_add_test_case test2
+ atf_add_test_case test3
+}
diff --git a/mk/pkgtasks/tests/directories_test b/mk/pkgtasks/tests/directories_test
new file mode 100755
index 00000000000..d38b411de78
--- /dev/null
+++ b/mk/pkgtasks/tests/directories_test
@@ -0,0 +1,111 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: directories_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/directories.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.directories}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/directories.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+MAKE_DIRS= ${PREFIX}/lib/modules
+OWN_DIRS= ${VARBASE}/test
+REQD_DIRS= ${PREFIX}/empty_dir
+MAKE_DIRS_PERMS= ${PREFIX}/lib/suid_modules root wheel 0700
+OWN_DIRS_PERMS= ${VARBASE}/secret root wheel 0700
+REQD_DIRS_PERMS= ${PREFIX}/unwriteable root wheel 0500
+EOF
+ # Expected output is each directory stripped of leading
+ # "${PREFIX}/" and inserted into the following template:
+ #
+ # # DIR: <dir> <flags> [<mode> [<user> [<group>]]]
+ #
+ cat > expected << 'EOF'
+# DIR: lib/modules m
+# DIR: lib/suid_modules m 0700 root wheel
+# DIR: /var/test mo
+# DIR: /var/secret mo 0700 root wheel
+# DIR: empty_dir fm
+# DIR: unwriteable fm 0500 root wheel
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/files_test b/mk/pkgtasks/tests/files_test
new file mode 100755
index 00000000000..42ef833c9ce
--- /dev/null
+++ b/mk/pkgtasks/tests/files_test
@@ -0,0 +1,168 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: files_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/files.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.files}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/files.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+FAIL_MSG= echo
+
+# Use config file directory with a package-specific subdirectory.
+PKG_SYSCONFDIR= /etc/${PKG_SYSCONFSUBDIR}
+PKG_SYSCONFSUBDIR= daemon
+PKG_SYSCONFDIR_PERMS= daemon daemon 0750
+
+CONF_FILES= ${PREFIX}/share/examples/daemon/conf ${PKG_SYSCONFDIR}/conf
+CONF_FILES_PERMS= ${PREFIX}/share/examples/daemon/private-conf \
+ ${PKG_SYSCONFDIR}/private-conf daemon daemon 0640
+REQD_FILES= /dev/null ${PREFIX}/libdata/empty
+REQD_FILES_PERMS= /dev/null ${PREFIX}/libdata/unwriteable daemon daemon 0440
+
+# init/rc.d.mk would turn "RCD_SCRIPTS=daemond daemon-authd" into the following.
+_INIT_SCRIPTS= share/examples/rc.d/daemond /etc/rc.d/daemond
+_INIT_SCRIPTS+= share/examples/rc.d/daemon-authd /etc/rc.d/daemon-authd
+EOF
+ # Expected output is each file path stripped of leading
+ # "${PREFIX}/" and inserted into the following template:
+ #
+ # # FILE: <target> <flags> <source> [<mode> [<user> [<group>]]]
+ #
+ cat > expected << 'EOF'
+# FILE: /etc/daemon/conf c share/examples/daemon/conf 0644
+# FILE: /etc/daemon/private-conf c share/examples/daemon/private-conf 0640 daemon daemon
+# FILE: libdata/empty cf /dev/null 0644
+# FILE: libdata/unwriteable cf /dev/null 0440 daemon daemon
+# FILE: /etc/rc.d/daemond cr share/examples/rc.d/daemond 0755
+# FILE: /etc/rc.d/daemon-authd cr share/examples/rc.d/daemon-authd 0755
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+###
+### test2
+###
+
+atf_test_case test2
+
+test2_head()
+{
+ atf_set "descr" "_pkgtasks-files-postinstall-check"
+}
+
+test2_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ # Setup
+ setup
+
+ # Create all of the source files to pass checks.
+ for n in 1 2 3 4 5 6 7 8 9; do
+ ( exec > source$n )
+ done
+
+ cat > mk.conf << 'EOF'
+FAIL_MSG= echo
+
+LOCALBASE= ${.CURDIR}
+DESTDIR= # empty
+
+CONF_FILES= source1 target1 source2 target2
+CONF_FILES_PERMS= source3 target3 u3 g3 0640 \
+ source4 target4 u4 g4 0640
+REQD_FILES= source5 target5 source6 target7
+REQD_FILES_PERMS= source8 target8 u8 g8 0400 \
+ source9 target9 u9 g9 0400
+EOF
+ ${MAKE} _pkgtasks-files-postinstall-check \
+ PKGSRCDIR="${PKGSRCDIR}" > output
+
+ if grep -cq "^" output; then
+ cat output
+ atf_fail "postinstall checks failed"
+ fi
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+ atf_add_test_case test2
+}
diff --git a/mk/pkgtasks/tests/fonts_test b/mk/pkgtasks/tests/fonts_test
new file mode 100755
index 00000000000..cfaaac32adb
--- /dev/null
+++ b/mk/pkgtasks/tests/fonts_test
@@ -0,0 +1,116 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: fonts_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/fonts.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.fonts}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/fonts.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+# X11 settings that affect ${X11_ENCODINGSDIR}.
+X11_TYPE= modular
+X11BASE= ${PREFIX}
+
+.for _util in mkfontdir mkfontscale ttmkfdir type1inst
+TOOLS_PATH.{_util}= ${PREFIX}/bin/${_util}
+.endfor
+
+FONTS_DIRS.ttf= ${PREFIX}/share/fonts/ttf1 \
+ ${PREFIX}/share/fonts/ttf2
+FONTS_DIRS.type1= ${PREFIX}/share/fonts/type1
+FONTS_DIRS.x11= ${PREFIX}/share/fonts/pcf \
+ ${PREFIX}/share/fonts/snf
+EOF
+ # Expected output is each path stripped of leading "${PREFIX}/"
+ # and inserted into the following template:
+ #
+ # # FONTS: <fontdir> <fonttype>
+ #
+ cat > expected << 'EOF'
+# FONTS: share/fonts/ttf1 ttf
+# FONTS: share/fonts/ttf2 ttf
+# FONTS: share/fonts/type1 type1
+# FONTS: share/fonts/pcf x11
+# FONTS: share/fonts/snf x11
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/groups_test b/mk/pkgtasks/tests/groups_test
new file mode 100755
index 00000000000..ecc4cfd29de
--- /dev/null
+++ b/mk/pkgtasks/tests/groups_test
@@ -0,0 +1,113 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: groups_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/usergroup.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.groups}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1: groups
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/usergroup.mk | groups"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > getgid.sh << 'EOF'
+case $1 in
+g1) echo 1 ;;
+g2) echo 2 ;;
+*) exit 1 ;;
+esac
+EOF
+ cat > mk.conf << 'EOF'
+USERGROUP_PHASE= configure
+PKG_GROUPS= g1 g2 g3
+
+SH= /bin/sh
+_GETGID_CMD= ${SH} getgid.sh
+EOF
+ # Expected output is each group inserted into the
+ # following template:
+ #
+ # # GROUP: <group>[:<gid>]
+ #
+ cat > expected << 'EOF'
+# GROUP: g1:1
+# GROUP: g2:2
+# GROUP: g3
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/info_files_test b/mk/pkgtasks/tests/info_files_test
new file mode 100755
index 00000000000..2b2b8a0f57a
--- /dev/null
+++ b/mk/pkgtasks/tests/info_files_test
@@ -0,0 +1,109 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: info_files_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/info_files.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.info_files}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/info_files.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+PKGINFODIR= share/info
+
+# Create mock ${INFO_FILES_cmd}.
+INFO_FILES= yes
+INFO_FILES_cmd= \
+ ( echo ${PKGINFODIR:Q}"/test1.info"; \
+ echo ${PKGINFODIR:Q}"/test2.info"; \
+ echo ${PKGINFODIR:Q}"/test3.info" )
+EOF
+ # Expected output is each path stripped of leading "${PREFIX}/"
+ # and inserted into the following template:
+ #
+ # # INFO: <file>
+ #
+ cat > expected << 'EOF'
+# INFO: share/info/test1.info
+# INFO: share/info/test2.info
+# INFO: share/info/test3.info
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/ocaml_findlib_test b/mk/pkgtasks/tests/ocaml_findlib_test
new file mode 100755
index 00000000000..77fcc9365c5
--- /dev/null
+++ b/mk/pkgtasks/tests/ocaml_findlib_test
@@ -0,0 +1,104 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: ocaml_findlib_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/ocaml_findlib.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.ocaml_findlib}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/ocaml_findlib.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+OCAML_FINDLIB_DIRS= bz2 dbm ldap sqlite3 odn
+EOF
+ # Expected output is each path stripped of leading "${PREFIX}/"
+ # and inserted into the following template:
+ #
+ # # FINDLIB: <directory>
+ #
+ cat > expected << 'EOF'
+# FINDLIB: bz2
+# FINDLIB: dbm
+# FINDLIB: ldap
+# FINDLIB: sqlite3
+# FINDLIB: odn
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/permissions_test b/mk/pkgtasks/tests/permissions_test
new file mode 100755
index 00000000000..f05aca651a5
--- /dev/null
+++ b/mk/pkgtasks/tests/permissions_test
@@ -0,0 +1,110 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: permissions_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/permissions.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.permissions}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/permissions.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+REAL_ROOT_USER= root
+REAL_ROOT_GROUP= wheel
+GAMES_USER= games
+GAMES_GROUP= games
+GAMEMODE= 2551
+GAMEDATAMODE= 664
+GAMEDIRMODE= 775
+
+SPECIAL_PERMS= ${PREFIX}/bin/sudo ${SETUID_ROOT_PERMS} \
+ ${PREFIX}/bin/tetris ${SETGID_GAMES_PERMS}
+EOF
+ # Expected output is each directory stripped of leading
+ # "${PREFIX}/" and inserted into the following template:
+ #
+ # # PERMS: <path> <mode> <owner> <group>
+ #
+ cat > expected << 'EOF'
+# PERMS: bin/sudo 4511 root wheel
+# PERMS: bin/tetris 2551 games games
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/pkgtasks_test b/mk/pkgtasks/tests/pkgtasks_test
new file mode 100755
index 00000000000..4799fc9e732
--- /dev/null
+++ b/mk/pkgtasks/tests/pkgtasks_test
@@ -0,0 +1,139 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: pkgtasks_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/bsd.pkgtasks.mk"
+
+all: value
+value: ${PKGTASKS_DATAFILE}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+
+.PHONY: depends
+depends: .PHONY
+ @${ECHO} ${DEPENDS:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/bsd.pkgtasks.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+MAKE_DIRS+= dir
+CONF_FILES+= source target
+PKG_GROUPS+= g1
+PKG_USERS+= u1:g1
+EOF
+ # Expected output.
+ cat > expected << 'EOF'
+# DIR: dir m
+# FILE: target c source 0644
+# GROUP: g1
+# USER: u1:g1:::/nonexistent:/sbin/nologin
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+###
+### test2
+###
+
+atf_test_case test2
+
+test2_head()
+{
+ atf_set "descr" "pkgtasks dependency"
+}
+
+test2_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+MAKE_DIRS+= dir
+CONF_FILES+= source target
+PKG_GROUPS+= g1
+PKG_USERS+= u1:g1
+EOF
+ ${MAKE} depends PKGSRCDIR="${PKGSRCDIR}" > output
+
+ cat output
+ grep -q "pkgtools/pkgtasks" output ||
+ atf_fail "pkgtasks dependency missing"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+ atf_add_test_case test2
+}
diff --git a/mk/pkgtasks/tests/shells_test b/mk/pkgtasks/tests/shells_test
new file mode 100755
index 00000000000..6778327ceac
--- /dev/null
+++ b/mk/pkgtasks/tests/shells_test
@@ -0,0 +1,104 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: shells_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/shells.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.shells}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/shells.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+PKG_SHELL= ${PREFIX}/bin/bash
+PKG_SHELL+= ${PREFIX}/bin/pdksh
+PKG_SHELL+= ${PREFIX}/bin/zsh
+EOF
+ # Expected output is each directory stripped of leading
+ # "${PREFIX}/" and inserted into the following template:
+ #
+ # # SHELL: <path>
+ #
+ cat > expected << 'EOF'
+# SHELL: bin/bash
+# SHELL: bin/pdksh
+# SHELL: bin/zsh
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/shlibs_test b/mk/pkgtasks/tests/shlibs_test
new file mode 100755
index 00000000000..e35ee9211f6
--- /dev/null
+++ b/mk/pkgtasks/tests/shlibs_test
@@ -0,0 +1,100 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: shlibs_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/shlibs.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.shlibs}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1
+###
+
+atf_test_case test1
+
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/shlibs.mk"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > mk.conf << 'EOF'
+SHLIB_TYPE= a.out
+EOF
+ # Expected output is each directory stripped of leading
+ # "${PREFIX}/" and inserted into the following template:
+ #
+ # # SHLIB: <directory> [...]
+ #
+ cat > expected << 'EOF'
+# SHLIB: lib
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}
diff --git a/mk/pkgtasks/tests/test.mk b/mk/pkgtasks/tests/test.mk
new file mode 100644
index 00000000000..c0f9f509cf3
--- /dev/null
+++ b/mk/pkgtasks/tests/test.mk
@@ -0,0 +1,69 @@
+# $NetBSD: test.mk,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# Definitions used by pkgtasks/*.mk files that are not assigned default
+# values.
+#
+_PKGTASKS_DIR?= ${WRKDIR}/.pkgtasks
+CAT?= cat
+CP?= cp
+ECHO?= echo
+FAIL_MSG?= ${ECHO} "!!!"
+LOCALBASE?= /usr/pkg
+MKDIR?= mkdir -p
+MV?= mv
+NOLOGIN?= /sbin/nologin
+PKG_SYSCONFDIR?= /etc
+PREFIX?= ${LOCALBASE}
+RM?= rm
+RUN?= @
+SH?= /bin/sh
+STEP_MSG?= ${ECHO} ">>>"
+TEST?= test
+VARBASE?= /var
+
+_PKGTASKS_NEEDARGS= \
+ needargs() { \
+ if ${TEST} $$3 -lt $$2; then \
+ ${FAIL_MSG} "$$1 must have a multiple of $$2 words. Rest: $$4"; \
+ return 1; \
+ fi; \
+ }
+
+# Override any other default definitions so that generated files go into
+# the current directory.
+#
+WRKDIR= ${.CURDIR}
+
+.PHONY: all
+all: _all
+
+.PHONY: _all
+_all:
+ ${RUN}: "do nothing"
diff --git a/mk/pkgtasks/tests/users_test b/mk/pkgtasks/tests/users_test
new file mode 100755
index 00000000000..7e5a165bad2
--- /dev/null
+++ b/mk/pkgtasks/tests/users_test
@@ -0,0 +1,113 @@
+#!/usr/bin/env atf-sh
+#
+# $NetBSD: users_test,v 1.1 2017/06/01 02:06:05 jlam Exp $
+#
+# Copyright (c) 2017 The NetBSD Foundation, Inc.
+# All rights reserved.
+#
+# This code is derived from software contributed to The NetBSD Foundation
+# by Johnny C. Lam.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+
+# ENVIRONMENT
+# The following variables are used if they are set:
+#
+# MAKE The name or path to the BSD make(1) utility. The default
+# is "make".
+#
+# PKGSRCDIR
+# The location of the pkgsrc source tree. The default is
+# "/usr/pkgsrc".
+#
+
+setup()
+{
+ cat > Makefile << 'EOF'
+.include "${PKGSRCDIR}/mk/pkgtasks/tests/test.mk"
+.sinclude "mk.conf"
+.include "${PKGSRCDIR}/mk/pkgtasks/usergroup.mk"
+
+all: value
+value: ${_PKGTASKS_DATA.users}
+ ${RUN}${CP} ${.ALLSRC:Q} ${.TARGET:Q}
+EOF
+}
+
+###
+### test1: users
+###
+
+atf_test_case test1
+test1_head()
+{
+ atf_set "descr" "pkgsrc/mk/pkgtasks/usergroup.mk | users"
+}
+
+test1_body()
+{
+ : ${MAKE:=make}
+ : ${PKGSRCDIR:=/usr/pkgsrc}
+
+ setup
+
+ cat > getuid.sh << 'EOF'
+case $1 in
+u1) echo 1 ;;
+u2) echo 2 ;;
+*) exit 1 ;;
+esac
+EOF
+ cat > mk.conf << 'EOF'
+USERGROUP_PHASE= configure
+PKG_USERS= u1:g1 u2:g2 u3:g3
+PKG_GECOS.u3= test user u1 description
+
+SH= /bin/sh
+_GETUID_CMD= ${SH} getuid.sh
+EOF
+ # Expected output is each user:group inserted into the
+ # following template:
+ #
+ # # USER: <user>:<group>[:<uid>]
+ #
+ cat > expected << 'EOF'
+# USER: u1:g1:1::/nonexistent:/sbin/nologin
+# USER: u2:g2:2::/nonexistent:/sbin/nologin
+# USER: u3:g3::test user u1 description:/nonexistent:/sbin/nologin
+EOF
+ echo ">>> expected"
+ cat expected
+
+ ${MAKE} PKGSRCDIR="${PKGSRCDIR}" || atf_fail "make(1) failed"
+
+ echo ">>> value"
+ cat value
+
+ cmp expected value || atf_fail "expected differs from value"
+ atf_pass
+}
+
+atf_init_test_cases()
+{
+ atf_add_test_case test1
+}