pkgsrc-WIP-changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
mk/*-package.mk: replace ad-hoc tests with Kyua tests
Module Name: pkgsrc-wip
Committed By: Roland Illig <rillig%NetBSD.org@localhost>
Pushed By: rillig
Date: Thu Mar 8 23:21:32 2018 +0000
Changeset: 8b8142b3c09fa9ad7daf1eb575df23a7d3cb8dbd
Added Files:
mk/tests/Kyuafile
mk/tests/cvs-multi
mk/tests/cvs-multi.mk
mk/tests/cvs-single
mk/tests/cvs-single.mk
mk/tests/fossil-multi
mk/tests/fossil-multi.mk
mk/tests/fossil-single
mk/tests/fossil-single.mk
mk/tests/git-multi
mk/tests/git-multi.mk
mk/tests/git-single
mk/tests/git-single.mk
mk/tests/hg-multi
mk/tests/hg-multi.mk
mk/tests/hg-single
mk/tests/hg-single.mk
mk/tests/svn-multi
mk/tests/svn-multi.mk
mk/tests/svn-single
mk/tests/svn-single.mk
mk/tests/test.subr
Removed Files:
mk-scm-tests/DESCR
mk-scm-tests/Makefile
mk-scm-tests/files/test
Log Message:
mk/*-package.mk: replace ad-hoc tests with Kyua tests
Before, the tests were all written in a single file, which was not
extensible and difficult to understand.
When run directly, the tests all pass. When run via Kyua, they fail
because they expect the file test.subr in the same directory. Someone
familiar with Kyua needs to fix this.
To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=8b8142b3c09fa9ad7daf1eb575df23a7d3cb8dbd
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
diffstat:
mk-scm-tests/DESCR | 3 -
mk-scm-tests/Makefile | 83 -----------------
mk-scm-tests/files/test | 223 ----------------------------------------------
mk/tests/Kyuafile | 25 ++++++
mk/tests/cvs-multi | 12 +++
mk/tests/cvs-multi.mk | 22 +++++
mk/tests/cvs-single | 10 +++
mk/tests/cvs-single.mk | 15 ++++
mk/tests/fossil-multi | 12 +++
mk/tests/fossil-multi.mk | 20 +++++
mk/tests/fossil-single | 10 +++
mk/tests/fossil-single.mk | 15 ++++
mk/tests/git-multi | 12 +++
mk/tests/git-multi.mk | 20 +++++
mk/tests/git-single | 10 +++
mk/tests/git-single.mk | 15 ++++
mk/tests/hg-multi | 12 +++
mk/tests/hg-multi.mk | 20 +++++
mk/tests/hg-single | 10 +++
mk/tests/hg-single.mk | 15 ++++
mk/tests/svn-multi | 12 +++
mk/tests/svn-multi.mk | 20 +++++
mk/tests/svn-single | 10 +++
mk/tests/svn-single.mk | 15 ++++
mk/tests/test.subr | 219 +++++++++++++++++++++++++++++++++++++++++++++
25 files changed, 531 insertions(+), 309 deletions(-)
diffs:
diff --git a/mk-scm-tests/DESCR b/mk-scm-tests/DESCR
deleted file mode 100644
index 92625353c1..0000000000
--- a/mk-scm-tests/DESCR
+++ /dev/null
@@ -1,3 +0,0 @@
-This pseudo package ensures that the various source code management
-systems in wip/mk work similarly to each other and handle the typical use
-cases correctly.
diff --git a/mk-scm-tests/Makefile b/mk-scm-tests/Makefile
deleted file mode 100644
index b664a26243..0000000000
--- a/mk-scm-tests/Makefile
+++ /dev/null
@@ -1,83 +0,0 @@
-# $NetBSD$
-
-.include "../../mk/bsd.prefs.mk"
-
-SCM_UNDER_TEST?= # none; set by files/test
-.if empty(SCM_UNDER_TEST)
-
-DISTNAME= mk-scm-tests-1.0
-CATEGORIES= pkgtools
-PLIST_SRC= # none
-DISTFILES= # none
-
-MAINTAINER= rillig%NetBSD.org@localhost
-HOMEPAGE= https://www.pkgsrc.org/
-COMMENT= System tests for wip/mk infrastructure
-LICENSE= 2-clause-bsd
-
-NO_CHECKSUM= yes
-NO_BUILD= yes
-USE_TOOLS+= bash
-
-run-tests: .PHONY
- ${BASH} files/test
-
-do-install:
- ${DO_NADA}
-
-.else
-
-DISTNAME= pkgbase-1.0
-CATEGORIES= pkgtools
-PLIST_SRC= # none
-
-.endif
-
-.if ${SCM_UNDER_TEST} == cvs
-CVS_ROOT= ${.CURDIR}/tmp/repo
-CVS_REPOSITORIES= 2017 current
-CVS_ROOT.2017= ${CVS_ROOT}
-CVS_MODULE.2017= ${CVS_MODULE}
-CVS_TAG.2017= v2017
-CVS_ROOT.current= ${CVS_ROOT}
-CVS_MODULE.current= ${CVS_MODULE}
-.include "../../wip/mk/cvs-package.mk"
-.endif
-
-.if ${SCM_UNDER_TEST} == fossil
-FOSSIL_REPO= ${.CURDIR}/tmp/repo/pkgbase/pkgbase.fossil
-FOSSIL_REPOSITORIES= 2017 current
-FOSSIL_REPO.2017= ${FOSSIL_REPO}
-FOSSIL_VERSION.2017= v2017
-FOSSIL_REPO.current= ${FOSSIL_REPO}
-.include "../../wip/mk/fossil-package.mk"
-.endif
-
-.if ${SCM_UNDER_TEST} == git
-GIT_REPO= ${.CURDIR}/tmp/repo/pkgbase
-GIT_REPOSITORIES= 2017 current
-GIT_REPO.2017= ${GIT_REPO}
-GIT_TAG.2017= v2017
-GIT_REPO.current= ${GIT_REPO}
-.include "../../wip/mk/git-package.mk"
-.endif
-
-.if ${SCM_UNDER_TEST} == hg
-HG_REPO= ${.CURDIR}/tmp/repo/pkgbase
-HG_REPOSITORIES= 2017 current
-HG_REPO.2017= ${HG_REPO}
-HG_TAG.2017= v2017
-HG_REPO.current= ${HG_REPO}
-.include "../../wip/mk/hg-package.mk"
-.endif
-
-.if ${SCM_UNDER_TEST} == svn
-SVN_REPO= file://${.CURDIR}/tmp/repo/pkgbase/trunk
-SVN_REPOSITORIES= 2017 current
-SVN_REPO.2017= ${SVN_REPO}
-SVN_REVISION.2017= 1
-SVN_REPO.current= ${SVN_REPO}
-.include "../../wip/mk/svn-package.mk"
-.endif
-
-.include "../../mk/bsd.pkg.mk"
diff --git a/mk-scm-tests/files/test b/mk-scm-tests/files/test
deleted file mode 100644
index 61e0185d6b..0000000000
--- a/mk-scm-tests/files/test
+++ /dev/null
@@ -1,223 +0,0 @@
-#! /bin/bash
-set -eu
-
-step() {
- echo ""
- echo "T: $*" 1>&2
-}
-
-die() {
- echo "E: $*" 1>&2
- exit 1
-}
-
-# There didn't seem to be a pre-built tool doing this.
-cvs_admin_set_date() {
- awk '
- BEGIN { FS = "\t"; OFS = FS }
- now && $1 == "date" { now = 0; $2 = "'"$3"';" }
- $0 == "'"$2"'" { now = 1 }
- { print }
- ' \
- "$1" > "$1.tmp"
- mv -f "$1.tmp" "$1"
-}
-
-setup_cvs_repository() {
- cvs -d "$repodir" init
- mkdir "$repodir/pkgbase"
-
- cvs -d "$repodir" checkout -d "$basedir/pkgbase" "pkgbase"
- pushd "$basedir/pkgbase"
-
- echo "2017-01-01" > today
- cvs add today
- cvs commit -m "today is 2017-01-01" today
- cvs_admin_set_date "$repodir/pkgbase/today,v" "1.1" "2017.01.01.00.00.00"
- cvs tag v2017 .
-
- echo "2018-01-01" > today
- cvs commit -m "today is 2018-01-01" today
- cvs_admin_set_date "$repodir/pkgbase/today,v" "1.2" "2018.01.01.00.00.00"
-
- echo "2018-03-01" > today
- cvs commit -m "today is 2018-03-01" today
- cvs_admin_set_date "$repodir/pkgbase/today,v" "1.3" "2018.03.01.00.00.00"
-
- popd
-}
-
-setup_fossil_repository() {
- mkdir -p "$repodir/pkgbase"
- pushd "$repodir/pkgbase"
- fossil init --date-override "2017-01-01" pkgbase.fossil
- fossil open "pkgbase.fossil"
-
- echo "2017-01-01" > today
- fossil add today
- fossil commit -m "today is 2017-01-01" --date-override "2017-01-01" --hash -- today
- fossil tag add --date-override "2017-01-01 00:00:01" v2017 tip
-
- echo "2018-01-01" > today
- fossil add today
- fossil commit -m "today is 2018-01-01" --date-override "2018-01-01" --hash -- today
-
- echo "2018-03-01" > today
- fossil commit -m "today is 2018-03-01" --date-override "2018-03-01" --hash -- today
-
- popd
-}
-
-setup_git_repository() {
- git init "$repodir/pkgbase"
- pushd "$repodir/pkgbase"
-
- echo "2017-01-01" > today
- git add today
- GIT_AUTHOR_DATE="2017-01-01T00:00:00Z" GIT_COMMITTER_DATE="2017-01-01T00:00:00Z" \
- git commit -m "today is 2017-01-01" -- today
- git tag v2017
-
- echo "2018-01-01" > today
- git add today
- GIT_AUTHOR_DATE="2018-01-01T00:00:00Z" GIT_COMMITTER_DATE="2018-01-01T00:00:00Z" \
- git commit -m "today is 2018-01-01" -- today
-
- echo "2018-03-01" > today
- GIT_AUTHOR_DATE="2018-03-01T00:00:00Z" GIT_COMMITTER_DATE="2018-03-01T00:00:00Z" \
- git commit -m "today is 2018-03-01" -- today
-
- popd
-}
-
-setup_hg_repository() {
- hg init "$repodir/pkgbase"
- pushd "$repodir/pkgbase"
-
- echo "2017-01-01" > today
- hg add today
- hg commit -m "today is 2017-01-01" -d "2017-01-01T00:00:00Z" -u "user" -- today
- hg tag -u "user" v2017
-
- echo "2018-01-01" > today
- hg add today
- hg commit -m "today is 2018-01-01" -d "2018-01-01T00:00:00Z" -u "user" -- today
-
- echo "2018-03-01" > today
- hg commit -m "today is 2018-03-01" -d "2018-03-01T00:00:00Z" -u "user" -- today
-
- popd
-}
-
-setup_svn_repository() {
- mkdir "$repodir"
- svnadmin create "$repodir/pkgbase"
- hook="$repodir/pkgbase/hooks/pre-revprop-change"
- printf '%s\n' '#! /bin/sh' '# allow everything' > "$hook"
- chmod +x "$hook"
- svn checkout "file://$repodir/pkgbase" "$basedir/svnwork"
- pushd "$basedir/svnwork"
- mkdir "trunk"
- cd "trunk"
-
- echo "2017-01-01" > today
- svn add .
- svn commit -m "today is 2017-01-01"
- svn propset "svn:date" --revprop -r HEAD "2017-01-01T00:00:00.000000Z"
-
- svn -m "v2017" --parents copy "file://$repodir/pkgbase/trunk" "file://$repodir/pkgbase/tags/v2017"
- svn propset "svn:date" --revprop -r HEAD "2017-01-01T00:00:00.000001Z"
-
- echo "2018-01-01" > today
- svn commit -m "today is 2018-01-01"
- svn propset "svn:date" --revprop -r HEAD "2018-01-01T00:00:00.000000Z"
-
- echo "2018-03-01" > today
- svn commit -m "today is 2018-03-01"
- svn propset "svn:date" --revprop -r HEAD "2018-03-01T00:00:00.000000Z"
-
- popd
-}
-
-pkgsrc_make() {
- bmake=`type "bmake" 1>/dev/null 2>&1 && echo "bmake" || echo "make"`
- DISTDIR="$basedir/distfiles" "$bmake" "$@"
-}
-
-assert_that() {
- case "${1-}${3+:}${3-}${5+:}${5-}${7+:}${7-}" in
- ("--file:--has-content")
- actual=`cat "$2"`
- [ "$4" = "$actual" ] || die "expected file $2 to contain \"$4\", but found \"$actual\"."
- ;;
- (*) die "assert_that called with invalid arguments: $*"
- esac
-}
-
-test_scm() {
- case "$1" in
- (cvs) scm_display_name="CVS" scm_tag_varname="CVS_TAG" ;;
- (fossil) scm_display_name="Fossil" scm_tag_varname="FOSSIL_VERSION";;
- (git) scm_display_name="Git" scm_tag_varname="GIT_TAG" ;;
- (hg) scm_display_name="Mercurial" scm_tag_varname="HG_TAG" ;;
- (svn) scm_display_name="Subversion" scm_tag_varname="SVN_REVISION" ;;
- esac
-
- # Sets up a repository in $repodir, with these commits:
- # - at 2017-01-01TZ, the file "today" contains "2017-01-01".
- # - this commit is tagged v2017.
- # - at 2018-01-01TZ, the file "today" contains "2018-01-01".
- # - at 2018-03-01TZ, the file "today" contains "2018-03-01".
- #
- step "Setting up $scm_display_name repository"
- rm -rf "$repodir"
- setup_${1}_repository
- wrkdir=`pkgsrc_make show-var VARNAME=WRKDIR`
-
- step "Dumping API variables for $scm_display_name (for manual inspection)"
- SCM_UNDER_TEST="$1" pkgsrc_make clean
- SCM_UNDER_TEST="$1" pkgsrc_make "show-all-$1"
- :
- : "needs to be inspected manually"
-
- step "Testing $scm_display_name"
- SCM_UNDER_TEST="$1" pkgsrc_make clean
- SCM_UNDER_TEST="$1" pkgsrc_make patch
- :
- assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
- assert_that --file "$wrkdir/2017/today" --has-content "2017-01-01"
- assert_that --file "$wrkdir/current/today" --has-content "2018-03-01"
-
- step "Testing $scm_display_name with CHECKOUT_DATE"
- SCM_UNDER_TEST="$1" pkgsrc_make clean
- SCM_UNDER_TEST="$1" CHECKOUT_DATE="2018-02-01" pkgsrc_make patch
- :
- assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-01-01"
-
- step "Testing $scm_display_name with tagged checkout"
- SCM_UNDER_TEST="$1" pkgsrc_make clean
- tag_value="v2017"; test "$1" = "svn" && tag_value="1"
- eval "SCM_UNDER_TEST=\"\$1\" $scm_tag_varname=\"\$tag_value\" pkgsrc_make patch"
- :
- assert_that --file "$wrkdir/pkgbase/today" --has-content "2017-01-01"
-
- SCM_UNDER_TEST="$1" pkgsrc_make clean
-}
-
-main() {
- basedir="$PWD/tmp"
- repodir="$basedir/repo"
- rm -rf "$basedir"
- mkdir "$basedir"
-
- test_scm "cvs"
- test_scm "fossil"
- test_scm "git"
- test_scm "hg"
- test_scm "svn"
-
- rm -rf "$basedir"
- step "OK"
-}
-
-main
diff --git a/mk/tests/Kyuafile b/mk/tests/Kyuafile
new file mode 100644
index 0000000000..efa88767f3
--- /dev/null
+++ b/mk/tests/Kyuafile
@@ -0,0 +1,25 @@
+syntax(2)
+
+test_suite("pkgsrc_wip_mk_scm")
+
+local function test(name)
+ -- Currently doesn't work because test.subr is not copied to the
+ -- temporary directory.
+ --
+ -- plain_test_program { name = name, required_files = "test.subr" }
+end
+
+test "cvs-single"
+test "cvs-multi"
+
+test "fossil-single"
+test "fossil-multi"
+
+test "git-single"
+test "git-multi"
+
+test "hg-single"
+test "hg-multi"
+
+test "svn-single"
+test "svn-multi"
diff --git a/mk/tests/cvs-multi b/mk/tests/cvs-multi
new file mode 100644
index 0000000000..6d28d48255
--- /dev/null
+++ b/mk/tests/cvs-multi
@@ -0,0 +1,12 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "cvs-multi.mk"
+setup_cvs_repository
+
+step "Testing CVS with multiple repositories"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
+assert_that --file "$wrkdir/2017/today" --has-content "2017-01-01"
+assert_that --file "$wrkdir/current/today" --has-content "2018-03-01"
diff --git a/mk/tests/cvs-multi.mk b/mk/tests/cvs-multi.mk
new file mode 100644
index 0000000000..23a9613c73
--- /dev/null
+++ b/mk/tests/cvs-multi.mk
@@ -0,0 +1,22 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for CVS with multiple repositories
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+CVS_ROOT= ${.CURDIR}/files/repo
+CVS_REPOSITORIES= 2017 current
+CVS_ROOT.2017= ${CVS_ROOT}
+CVS_MODULE.2017= ${CVS_MODULE}
+CVS_TAG.2017= v2017
+CVS_ROOT.current= ${CVS_ROOT}
+CVS_MODULE.current= ${CVS_MODULE}
+
+.include "../../wip/mk/cvs-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/cvs-single b/mk/tests/cvs-single
new file mode 100644
index 0000000000..b555eed055
--- /dev/null
+++ b/mk/tests/cvs-single
@@ -0,0 +1,10 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "cvs-single.mk"
+setup_cvs_repository
+
+step "Testing CVS with a single repository"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
diff --git a/mk/tests/cvs-single.mk b/mk/tests/cvs-single.mk
new file mode 100644
index 0000000000..86ac878c1f
--- /dev/null
+++ b/mk/tests/cvs-single.mk
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+CVS_ROOT= ${.CURDIR}/files/repo
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for CVS with a single repository
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+.include "../../wip/mk/cvs-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/fossil-multi b/mk/tests/fossil-multi
new file mode 100644
index 0000000000..9d5b07bcf8
--- /dev/null
+++ b/mk/tests/fossil-multi
@@ -0,0 +1,12 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "fossil-multi.mk"
+setup_fossil_repository
+
+step "Testing Fossil with multiple repositories"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
+assert_that --file "$wrkdir/2017/today" --has-content "2017-01-01"
+assert_that --file "$wrkdir/current/today" --has-content "2018-03-01"
diff --git a/mk/tests/fossil-multi.mk b/mk/tests/fossil-multi.mk
new file mode 100644
index 0000000000..9a6e423b1b
--- /dev/null
+++ b/mk/tests/fossil-multi.mk
@@ -0,0 +1,20 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Fossil with multiple repositories
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+FOSSIL_REPO= ${.CURDIR}/files/repo/pkgbase.fossil
+FOSSIL_REPOSITORIES= 2017 current
+FOSSIL_REPO.2017= ${FOSSIL_REPO}
+FOSSIL_VERSION.2017= v2017
+FOSSIL_REPO.current= ${FOSSIL_REPO}
+
+.include "../../wip/mk/fossil-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/fossil-single b/mk/tests/fossil-single
new file mode 100644
index 0000000000..9f4e6c0e54
--- /dev/null
+++ b/mk/tests/fossil-single
@@ -0,0 +1,10 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "fossil-single.mk"
+setup_fossil_repository
+
+step "Testing Fossil with a single repository"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
diff --git a/mk/tests/fossil-single.mk b/mk/tests/fossil-single.mk
new file mode 100644
index 0000000000..310e6ee951
--- /dev/null
+++ b/mk/tests/fossil-single.mk
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+FOSSIL_REPO= ${.CURDIR}/files/repo/pkgbase.fossil
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Fossil with a single repository
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+.include "../../wip/mk/fossil-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/git-multi b/mk/tests/git-multi
new file mode 100644
index 0000000000..d092107e32
--- /dev/null
+++ b/mk/tests/git-multi
@@ -0,0 +1,12 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "git-multi.mk"
+setup_git_repository
+
+step "Testing Git with multiple repositories"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
+assert_that --file "$wrkdir/2017/today" --has-content "2017-01-01"
+assert_that --file "$wrkdir/current/today" --has-content "2018-03-01"
diff --git a/mk/tests/git-multi.mk b/mk/tests/git-multi.mk
new file mode 100644
index 0000000000..72ec505e0e
--- /dev/null
+++ b/mk/tests/git-multi.mk
@@ -0,0 +1,20 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Git with multiple repositories
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+GIT_REPO= ${.CURDIR}/files/repo/pkgbase
+GIT_REPOSITORIES= 2017 current
+GIT_REPO.2017= ${GIT_REPO}
+GIT_TAG.2017= v2017
+GIT_REPO.current= ${GIT_REPO}
+
+.include "../../wip/mk/git-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/git-single b/mk/tests/git-single
new file mode 100644
index 0000000000..a8c8682de4
--- /dev/null
+++ b/mk/tests/git-single
@@ -0,0 +1,10 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "git-single.mk"
+setup_git_repository
+
+step "Testing Git with a single repository"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
diff --git a/mk/tests/git-single.mk b/mk/tests/git-single.mk
new file mode 100644
index 0000000000..8e5ae7d9fa
--- /dev/null
+++ b/mk/tests/git-single.mk
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+GIT_REPO= ${.CURDIR}/files/repo/pkgbase
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Git with a single repository
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+.include "../../wip/mk/git-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/hg-multi b/mk/tests/hg-multi
new file mode 100644
index 0000000000..162ca46c9a
--- /dev/null
+++ b/mk/tests/hg-multi
@@ -0,0 +1,12 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "hg-multi.mk"
+setup_hg_repository
+
+step "Testing Mercurial with multiple repositories"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
+assert_that --file "$wrkdir/2017/today" --has-content "2017-01-01"
+assert_that --file "$wrkdir/current/today" --has-content "2018-03-01"
diff --git a/mk/tests/hg-multi.mk b/mk/tests/hg-multi.mk
new file mode 100644
index 0000000000..8f8d599e9b
--- /dev/null
+++ b/mk/tests/hg-multi.mk
@@ -0,0 +1,20 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Mercurial with multiple repositories
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+HG_REPO= ${.CURDIR}/files/repo/pkgbase
+HG_REPOSITORIES= 2017 current
+HG_REPO.2017= ${HG_REPO}
+HG_TAG.2017= v2017
+HG_REPO.current= ${HG_REPO}
+
+.include "../../wip/mk/hg-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/hg-single b/mk/tests/hg-single
new file mode 100644
index 0000000000..fa7175726a
--- /dev/null
+++ b/mk/tests/hg-single
@@ -0,0 +1,10 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "hg-single.mk"
+setup_hg_repository
+
+step "Testing Mercurial with a single repository"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
diff --git a/mk/tests/hg-single.mk b/mk/tests/hg-single.mk
new file mode 100644
index 0000000000..ec27ba5080
--- /dev/null
+++ b/mk/tests/hg-single.mk
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+HG_REPO= ${.CURDIR}/files/repo/pkgbase
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Mercurial with a single repository
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+.include "../../wip/mk/hg-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/svn-multi b/mk/tests/svn-multi
new file mode 100644
index 0000000000..dca7e310cb
--- /dev/null
+++ b/mk/tests/svn-multi
@@ -0,0 +1,12 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "svn-multi.mk"
+setup_svn_repository
+
+step "Testing Subversion with multiple repositories"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
+assert_that --file "$wrkdir/2017/today" --has-content "2017-01-01"
+assert_that --file "$wrkdir/current/today" --has-content "2018-03-01"
diff --git a/mk/tests/svn-multi.mk b/mk/tests/svn-multi.mk
new file mode 100644
index 0000000000..6ffa39d405
--- /dev/null
+++ b/mk/tests/svn-multi.mk
@@ -0,0 +1,20 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Mercurial with multiple repositories
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+SVN_REPO= file://${.CURDIR}/files/repo/pkgbase/trunk
+SVN_REPOSITORIES= 2017 current
+SVN_REPO.2017= ${SVN_REPO}
+SVN_REVISION.2017= 1
+SVN_REPO.current= ${SVN_REPO}
+
+.include "../../wip/mk/svn-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/svn-single b/mk/tests/svn-single
new file mode 100644
index 0000000000..3ddbbfeaeb
--- /dev/null
+++ b/mk/tests/svn-single
@@ -0,0 +1,10 @@
+#! /bin/sh
+. "./test.subr"
+
+setup_package "svn-single.mk"
+setup_svn_repository
+
+step "Testing Subversion with a single repository"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
diff --git a/mk/tests/svn-single.mk b/mk/tests/svn-single.mk
new file mode 100644
index 0000000000..46bccbbad6
--- /dev/null
+++ b/mk/tests/svn-single.mk
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+DISTNAME= pkgbase-1.0
+CATEGORIES= pkgtools
+SVN_REPO= file://${.CURDIR}/files/repo/pkgbase/trunk
+
+MAINTAINER= rillig%NetBSD.org@localhost
+HOMEPAGE= https://www.pkgsrc.org/
+COMMENT= Test for Subversion with a single repository
+LICENSE= 2-clause-bsd
+
+NO_CHECKSUM= yes
+
+.include "../../wip/mk/svn-package.mk"
+.include "../../mk/bsd.pkg.mk"
diff --git a/mk/tests/test.subr b/mk/tests/test.subr
new file mode 100644
index 0000000000..b3966c6af2
--- /dev/null
+++ b/mk/tests/test.subr
@@ -0,0 +1,219 @@
+#! /bin/sh
+set -eu
+
+step() {
+ echo "" 1>&2
+ echo "T: $*" 1>&2
+}
+
+die() {
+ echo "E: $*" 1>&2
+ exit 1
+}
+
+# There didn't seem to be a pre-built tool doing this.
+cvs_admin_set_date() {
+ awk '
+ BEGIN { FS = "\t"; OFS = FS }
+ now && $1 == "date" { now = 0; $2 = "'"$3"';" }
+ $0 == "'"$2"'" { now = 1 }
+ { print }
+ ' \
+ "$1" > "$1.tmp"
+ mv -f "$1.tmp" "$1"
+}
+
+setup_package() {
+ pkgsrcdir=`cd "$PWD/../../.." && exec pwd`
+ test -f "$pkgsrcdir/mk/bsd.pkg.mk" || die "This test must be run from inside pkgsrc"
+
+ pkgdir="$pkgsrcdir/mk-scm-tests/mk-scm-tests"
+ rm -rf "$pkgdir"
+ mkdir -p "$pkgdir"
+ cp "$1" "$pkgdir/Makefile"
+ echo "Dummy description." > "$pkgdir/DESCR"
+ echo "@comment $""NetBSD""$" > "$pkgdir/PLIST"
+ cd "$pkgdir"
+
+ repodir="$pkgdir/files/repo"
+ mkdir -p "${repodir%/*}"
+
+ tmpdir="$pkgdir/tmp"
+ mkdir -p "$tmpdir"
+
+ wrkdir=`package_make show-var VARNAME=WRKDIR`
+}
+
+# The standard test repository contains these commits:
+# - at 2017-01-01TZ, the file "today" contains "2017-01-01".
+# - this commit is tagged v2017.
+# - at 2018-01-01TZ, the file "today" contains "2018-01-01".
+# - at 2018-03-01TZ, the file "today" contains "2018-03-01".
+
+setup_cvs_repository() {
+ cvs -d "$repodir" init
+ mkdir "$repodir/pkgbase"
+
+ cvs -d "$repodir" checkout -d "$tmpdir/pkgbase" "pkgbase"
+ cd "$tmpdir/pkgbase"
+
+ echo "2017-01-01" > today
+ cvs add today
+ cvs commit -m "today is 2017-01-01" today
+ cvs_admin_set_date "$repodir/pkgbase/today,v" "1.1" "2017.01.01.00.00.00"
+ cvs tag v2017 .
+
+ echo "2018-01-01" > today
+ cvs commit -m "today is 2018-01-01" today
+ cvs_admin_set_date "$repodir/pkgbase/today,v" "1.2" "2018.01.01.00.00.00"
+
+ echo "2018-03-01" > today
+ cvs commit -m "today is 2018-03-01" today
+ cvs_admin_set_date "$repodir/pkgbase/today,v" "1.3" "2018.03.01.00.00.00"
+}
+
+setup_fossil_repository() {
+ mkdir -p "$repodir"
+ cd "$repodir"
+ fossil init --date-override "2017-01-01" pkgbase.fossil
+ fossil open "pkgbase.fossil"
+
+ echo "2017-01-01" > today
+ fossil add today
+ fossil commit -m "today is 2017-01-01" --date-override "2017-01-01" --hash -- today
+ fossil tag add --date-override "2017-01-01 00:00:01" v2017 tip
+
+ echo "2018-01-01" > today
+ fossil add today
+ fossil commit -m "today is 2018-01-01" --date-override "2018-01-01" --hash -- today
+
+ echo "2018-03-01" > today
+ fossil commit -m "today is 2018-03-01" --date-override "2018-03-01" --hash -- today
+}
+
+setup_git_repository() {
+ git init "$repodir/pkgbase"
+ cd "$repodir/pkgbase"
+
+ echo "2017-01-01" > today
+ git add today
+ GIT_AUTHOR_DATE="2017-01-01T00:00:00Z" GIT_COMMITTER_DATE="2017-01-01T00:00:00Z" \
+ git commit -m "today is 2017-01-01" -- today
+ git tag v2017
+
+ echo "2018-01-01" > today
+ git add today
+ GIT_AUTHOR_DATE="2018-01-01T00:00:00Z" GIT_COMMITTER_DATE="2018-01-01T00:00:00Z" \
+ git commit -m "today is 2018-01-01" -- today
+
+ echo "2018-03-01" > today
+ GIT_AUTHOR_DATE="2018-03-01T00:00:00Z" GIT_COMMITTER_DATE="2018-03-01T00:00:00Z" \
+ git commit -m "today is 2018-03-01" -- today
+}
+
+setup_hg_repository() {
+ hg init "$repodir/pkgbase"
+ cd "$repodir/pkgbase"
+
+ echo "2017-01-01" > today
+ hg add today
+ hg commit -m "today is 2017-01-01" -d "2017-01-01T00:00:00Z" -u "user" -- today
+ hg tag -u "user" v2017
+
+ echo "2018-01-01" > today
+ hg commit -m "today is 2018-01-01" -d "2018-01-01T00:00:00Z" -u "user" -- today
+
+ echo "2018-03-01" > today
+ hg commit -m "today is 2018-03-01" -d "2018-03-01T00:00:00Z" -u "user" -- today
+}
+
+setup_svn_repository() {
+ mkdir "$repodir"
+ svnadmin create "$repodir/pkgbase"
+ hook="$repodir/pkgbase/hooks/pre-revprop-change"
+ printf '%s\n' '#! /bin/sh' '# allow everything' > "$hook"
+ chmod +x "$hook"
+ svn checkout "file://$repodir/pkgbase" "$tmpdir/svnwork"
+ cd "$tmpdir/svnwork"
+ mkdir "trunk"
+ cd "trunk"
+
+ echo "2017-01-01" > today
+ svn add .
+ svn commit -m "today is 2017-01-01"
+ svn propset "svn:date" --revprop -r HEAD "2017-01-01T00:00:00.000000Z"
+
+ svn -m "v2017" --parents copy "file://$repodir/pkgbase/trunk" "file://$repodir/pkgbase/tags/v2017"
+ svn propset "svn:date" --revprop -r HEAD "2017-01-01T00:00:00.000001Z"
+
+ echo "2018-01-01" > today
+ svn commit -m "today is 2018-01-01"
+ svn propset "svn:date" --revprop -r HEAD "2018-01-01T00:00:00.000000Z"
+
+ echo "2018-03-01" > today
+ svn commit -m "today is 2018-03-01"
+ svn propset "svn:date" --revprop -r HEAD "2018-03-01T00:00:00.000000Z"
+}
+
+package_make() {
+ cd "$pkgdir"
+ bmake=`type "bmake" 1>/dev/null 2>&1 && echo "bmake" || echo "make"`
+ DISTDIR="$tmpdir/distfiles" "$bmake" "$@"
+}
+
+assert_that() {
+ case "${1-}${3+:}${3-}${5+:}${5-}${7+:}${7-}" in
+ ("--file:--has-content")
+ actual=`cat "$2"`
+ [ "$4" = "$actual" ] || die "expected file $2 to contain \"$4\", but found \"$actual\"."
+ ;;
+ (*) die "assert_that called with invalid arguments: $*"
+ esac
+}
+
+test_scm() {
+ case "$1" in
+ (cvs) scm_display_name="CVS" scm_tag_varname="CVS_TAG" ;;
+ (fossil) scm_display_name="Fossil" scm_tag_varname="FOSSIL_VERSION";;
+ (git) scm_display_name="Git" scm_tag_varname="GIT_TAG" ;;
+ (hg) scm_display_name="Mercurial" scm_tag_varname="HG_TAG" ;;
+ (svn) scm_display_name="Subversion" scm_tag_varname="SVN_REVISION" ;;
+ esac
+
+ step "Setting up $scm_display_name repository"
+ rm -rf "$repodir"
+ setup_${1}_repository
+ wrkdir=`pkgsrc_make show-var VARNAME=WRKDIR`
+
+ : step "Dumping API variables for $scm_display_name (for manual inspection)"
+ : SCM_UNDER_TEST="$1" pkgsrc_make clean
+ : SCM_UNDER_TEST="$1" pkgsrc_make "show-all-$1"
+ :
+ : "needs to be inspected manually"
+
+ step "Testing $scm_display_name"
+ : pkgsrc_make clean
+ PKG_DEBUG_LEVEL=0 pkgsrc_make -f "$1-1-single.mk" clean
+ PKG_DEBUG_LEVEL=0 pkgsrc_make -f "$1-1-single.mk" build
+ #PKG_DEBUG_LEVEL=0 pkgsrc_make -f "$1-1-single.mk" do-build
+ exit 1
+ :
+ assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
+ assert_that --file "$wrkdir/2017/today" --has-content "2017-01-01"
+ assert_that --file "$wrkdir/current/today" --has-content "2018-03-01"
+
+ step "Testing $scm_display_name with CHECKOUT_DATE"
+ SCM_UNDER_TEST="$1" pkgsrc_make clean
+ SCM_UNDER_TEST="$1" CHECKOUT_DATE="2018-02-01" pkgsrc_make patch
+ :
+ assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-01-01"
+
+ step "Testing $scm_display_name with tagged checkout"
+ SCM_UNDER_TEST="$1" pkgsrc_make clean
+ tag_value="v2017"; test "$1" = "svn" && tag_value="1"
+ eval "SCM_UNDER_TEST=\"\$1\" $scm_tag_varname=\"\$tag_value\" pkgsrc_make patch"
+ :
+ assert_that --file "$wrkdir/pkgbase/today" --has-content "2017-01-01"
+
+ SCM_UNDER_TEST="$1" pkgsrc_make clean
+}
Home |
Main Index |
Thread Index |
Old Index