pkgsrc-WIP-changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

mk/tests: rewrite the tests for the SCM systems



Module Name:	pkgsrc-wip
Committed By:	Roland Illig <rillig%NetBSD.org@localhost>
Pushed By:	rillig
Date:		Mon Mar 14 19:52:37 2022 +0000
Changeset:	d495450cb979ff67f6acd5b5ebf96d1d9001671d

Modified Files:
	mk/tests/Kyuafile
	mk/tests/Makefile
	mk/tests/cvs-checkout_date
	mk/tests/cvs-checkout_date.mk
	mk/tests/cvs-multi
	mk/tests/cvs-multi.mk
	mk/tests/cvs-show-all
	mk/tests/cvs-show-all.mk
	mk/tests/cvs-single
	mk/tests/cvs-single.mk
	mk/tests/fossil-checkout_date
	mk/tests/fossil-checkout_date.mk
	mk/tests/fossil-multi
	mk/tests/fossil-multi.mk
	mk/tests/fossil-show-all
	mk/tests/fossil-show-all.mk
	mk/tests/fossil-single
	mk/tests/fossil-single.mk
	mk/tests/git-checkout_date
	mk/tests/git-checkout_date.mk
	mk/tests/git-multi
	mk/tests/git-multi.mk
	mk/tests/git-show-all
	mk/tests/git-show-all.mk
	mk/tests/git-single
	mk/tests/git-single.mk
	mk/tests/hg-checkout_date
	mk/tests/hg-checkout_date.mk
	mk/tests/hg-multi
	mk/tests/hg-multi.mk
	mk/tests/hg-show-all
	mk/tests/hg-show-all.mk
	mk/tests/hg-single
	mk/tests/hg-single.mk
	mk/tests/svn-checkout_date
	mk/tests/svn-checkout_date.mk
	mk/tests/svn-multi
	mk/tests/svn-multi.mk
	mk/tests/svn-show-all
	mk/tests/svn-show-all.mk
	mk/tests/svn-single
	mk/tests/svn-single.mk
	mk/tests/test.subr
Added Files:
	mk/tests/git-update
	mk/tests/git-update.mk

Log Message:
mk/tests: rewrite the tests for the SCM systems

The test for updating the cached Git archive needs to modify the remote
repository after building the package once.  To allow advanced tests
like this, the basic operations of the SCM systems must be made
available to the individual tests.

To see a diff of this commit:
https://wip.pkgsrc.org/cgi-bin/gitweb.cgi?p=pkgsrc-wip.git;a=commitdiff;h=d495450cb979ff67f6acd5b5ebf96d1d9001671d

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

diffstat:
 mk/tests/Kyuafile                |   1 +
 mk/tests/Makefile                |   2 +-
 mk/tests/cvs-checkout_date       |   4 +-
 mk/tests/cvs-checkout_date.mk    |   2 +-
 mk/tests/cvs-multi               |   4 +-
 mk/tests/cvs-multi.mk            |   2 +-
 mk/tests/cvs-show-all            |   4 +-
 mk/tests/cvs-show-all.mk         |   2 +-
 mk/tests/cvs-single              |   4 +-
 mk/tests/cvs-single.mk           |   2 +-
 mk/tests/fossil-checkout_date    |   4 +-
 mk/tests/fossil-checkout_date.mk |   2 +-
 mk/tests/fossil-multi            |   4 +-
 mk/tests/fossil-multi.mk         |   2 +-
 mk/tests/fossil-show-all         |   4 +-
 mk/tests/fossil-show-all.mk      |   2 +-
 mk/tests/fossil-single           |   4 +-
 mk/tests/fossil-single.mk        |   2 +-
 mk/tests/git-checkout_date       |   4 +-
 mk/tests/git-checkout_date.mk    |   2 +-
 mk/tests/git-multi               |   4 +-
 mk/tests/git-multi.mk            |   2 +-
 mk/tests/git-show-all            |   4 +-
 mk/tests/git-show-all.mk         |   2 +-
 mk/tests/git-single              |   4 +-
 mk/tests/git-single.mk           |   2 +-
 mk/tests/git-update              |  30 +++++
 mk/tests/git-update.mk           |  15 +++
 mk/tests/hg-checkout_date        |   4 +-
 mk/tests/hg-checkout_date.mk     |   2 +-
 mk/tests/hg-multi                |   4 +-
 mk/tests/hg-multi.mk             |   2 +-
 mk/tests/hg-show-all             |   4 +-
 mk/tests/hg-show-all.mk          |   2 +-
 mk/tests/hg-single               |   4 +-
 mk/tests/hg-single.mk            |   2 +-
 mk/tests/svn-checkout_date       |   4 +-
 mk/tests/svn-checkout_date.mk    |   2 +-
 mk/tests/svn-multi               |   4 +-
 mk/tests/svn-multi.mk            |   2 +-
 mk/tests/svn-show-all            |   4 +-
 mk/tests/svn-show-all.mk         |   2 +-
 mk/tests/svn-single              |   4 +-
 mk/tests/svn-single.mk           |   2 +-
 mk/tests/test.subr               | 271 +++++++++++++++++++++++----------------
 45 files changed, 265 insertions(+), 174 deletions(-)

diffs:
diff --git a/mk/tests/Kyuafile b/mk/tests/Kyuafile
index 0d0f81a0f8..3a11e5c2ce 100644
--- a/mk/tests/Kyuafile
+++ b/mk/tests/Kyuafile
@@ -20,6 +20,7 @@ test "git-show-all"
 test "git-single"
 test "git-checkout_date"
 test "git-multi"
+test "git-update"
 
 test "hg-show-all"
 test "hg-single"
diff --git a/mk/tests/Makefile b/mk/tests/Makefile
index 768323f652..6460395973 100644
--- a/mk/tests/Makefile
+++ b/mk/tests/Makefile
@@ -2,7 +2,7 @@
 
 TESTS=	   cvs-show-all    cvs-single    cvs-checkout_date    cvs-multi
 TESTS+=	fossil-show-all fossil-single fossil-checkout_date fossil-multi
-TESTS+=	   git-show-all    git-single    git-checkout_date    git-multi
+TESTS+=	   git-show-all    git-single    git-checkout_date    git-multi git-update
 TESTS+=	    hg-show-all     hg-single     hg-checkout_date     hg-multi
 TESTS+=	   svn-show-all    svn-single    svn-checkout_date    svn-multi
 TESTS+=	zzz-copy-paste
diff --git a/mk/tests/cvs-checkout_date b/mk/tests/cvs-checkout_date
index 4e1408ecf5..1ecd36dd15 100644
--- a/mk/tests/cvs-checkout_date
+++ b/mk/tests/cvs-checkout_date
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "cvs-checkout_date.mk"
-setup_cvs_repository
+set_up_package "cvs-checkout_date.mk"
+set_up_repository cvs
 
 step "Testing CVS with CHECKOUT_DATE"
 CHECKOUT_DATE="2018-02-01" package_make patch
diff --git a/mk/tests/cvs-checkout_date.mk b/mk/tests/cvs-checkout_date.mk
index 783d453a43..6de80ca2a6 100644
--- a/mk/tests/cvs-checkout_date.mk
+++ b/mk/tests/cvs-checkout_date.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-CVS_ROOT=	${.CURDIR}/files/repo
+CVS_ROOT=	${.CURDIR:H}/repos
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/cvs-multi b/mk/tests/cvs-multi
index 74807d0563..2da8f8ff39 100644
--- a/mk/tests/cvs-multi
+++ b/mk/tests/cvs-multi
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "cvs-multi.mk"
-setup_cvs_repository
+set_up_package "cvs-multi.mk"
+set_up_repository cvs
 
 step "Testing CVS with multiple repositories"
 package_make patch
diff --git a/mk/tests/cvs-multi.mk b/mk/tests/cvs-multi.mk
index 23a9613c73..55bd85e9fe 100644
--- a/mk/tests/cvs-multi.mk
+++ b/mk/tests/cvs-multi.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-CVS_ROOT=		${.CURDIR}/files/repo
+CVS_ROOT=		${.CURDIR:H}/repos
 CVS_REPOSITORIES=	2017 current
 CVS_ROOT.2017=		${CVS_ROOT}
 CVS_MODULE.2017=	${CVS_MODULE}
diff --git a/mk/tests/cvs-show-all b/mk/tests/cvs-show-all
index 285ce59e5c..237b896292 100644
--- a/mk/tests/cvs-show-all
+++ b/mk/tests/cvs-show-all
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "cvs-show-all.mk"
-setup_cvs_repository
+set_up_package "cvs-show-all.mk"
+set_up_repository cvs
 
 step "Testing show-all-cvs"
 package_make show-all-cvs
diff --git a/mk/tests/cvs-show-all.mk b/mk/tests/cvs-show-all.mk
index f6a551fa47..43815d9e2a 100644
--- a/mk/tests/cvs-show-all.mk
+++ b/mk/tests/cvs-show-all.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-CVS_ROOT=		${.CURDIR}/files/repo
+CVS_ROOT=		${.CURDIR:H}/repos
 CVS_REPOSITORIES=	2017 current
 CVS_ROOT.2017=		${CVS_ROOT}
 CVS_MODULE.2017=	${CVS_MODULE}
diff --git a/mk/tests/cvs-single b/mk/tests/cvs-single
index 38ed371d7c..233ce73f8b 100644
--- a/mk/tests/cvs-single
+++ b/mk/tests/cvs-single
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "cvs-single.mk"
-setup_cvs_repository
+set_up_package "cvs-single.mk"
+set_up_repository cvs
 
 step "Testing CVS with a single repository"
 package_make patch
diff --git a/mk/tests/cvs-single.mk b/mk/tests/cvs-single.mk
index 86ac878c1f..b7992ac1e9 100644
--- a/mk/tests/cvs-single.mk
+++ b/mk/tests/cvs-single.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-CVS_ROOT=	${.CURDIR}/files/repo
+CVS_ROOT=	${.CURDIR:H}/repos
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/fossil-checkout_date b/mk/tests/fossil-checkout_date
index b026cdd53e..a458940b49 100644
--- a/mk/tests/fossil-checkout_date
+++ b/mk/tests/fossil-checkout_date
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "fossil-checkout_date.mk"
-setup_fossil_repository
+set_up_package "fossil-checkout_date.mk"
+set_up_repository fossil
 
 step "Testing Fossil with CHECKOUT_DATE"
 CHECKOUT_DATE="2018-02-01" package_make patch
diff --git a/mk/tests/fossil-checkout_date.mk b/mk/tests/fossil-checkout_date.mk
index 9055119650..a502bd2732 100644
--- a/mk/tests/fossil-checkout_date.mk
+++ b/mk/tests/fossil-checkout_date.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-FOSSIL_REPO=	${.CURDIR}/files/repo/pkgbase.fossil
+FOSSIL_REPO=	${.CURDIR:H}/repos/pkgbase.fossil
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/fossil-multi b/mk/tests/fossil-multi
index 3dcc056fab..e20803d656 100644
--- a/mk/tests/fossil-multi
+++ b/mk/tests/fossil-multi
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "fossil-multi.mk"
-setup_fossil_repository
+set_up_package "fossil-multi.mk"
+set_up_repository fossil
 
 step "Testing Fossil with multiple repositories"
 package_make patch
diff --git a/mk/tests/fossil-multi.mk b/mk/tests/fossil-multi.mk
index 9a6e423b1b..4871f62259 100644
--- a/mk/tests/fossil-multi.mk
+++ b/mk/tests/fossil-multi.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-FOSSIL_REPO=		${.CURDIR}/files/repo/pkgbase.fossil
+FOSSIL_REPO=		${.CURDIR:H}/repos/pkgbase.fossil
 FOSSIL_REPOSITORIES=	2017 current
 FOSSIL_REPO.2017=	${FOSSIL_REPO}
 FOSSIL_VERSION.2017=	v2017
diff --git a/mk/tests/fossil-show-all b/mk/tests/fossil-show-all
index 32dbd1236c..89cae2c06b 100644
--- a/mk/tests/fossil-show-all
+++ b/mk/tests/fossil-show-all
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "fossil-show-all.mk"
-setup_fossil_repository
+set_up_package "fossil-show-all.mk"
+set_up_repository fossil
 
 step "Testing show-all-fossil"
 package_make show-all-fossil
diff --git a/mk/tests/fossil-show-all.mk b/mk/tests/fossil-show-all.mk
index e97ba7e7f3..9e77788ca0 100644
--- a/mk/tests/fossil-show-all.mk
+++ b/mk/tests/fossil-show-all.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-FOSSIL_REPO=		${.CURDIR}/files/repo/pkgbase.fossil
+FOSSIL_REPO=		${.CURDIR:H}/repos/pkgbase.fossil
 FOSSIL_REPOSITORIES=	2017 current
 FOSSIL_REPO.2017=	${FOSSIL_REPO}
 FOSSIL_VERSION.2017=	v2017
diff --git a/mk/tests/fossil-single b/mk/tests/fossil-single
index 156d12d8d2..1bf3376345 100644
--- a/mk/tests/fossil-single
+++ b/mk/tests/fossil-single
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "fossil-single.mk"
-setup_fossil_repository
+set_up_package "fossil-single.mk"
+set_up_repository fossil
 
 step "Testing Fossil with a single repository"
 package_make patch
diff --git a/mk/tests/fossil-single.mk b/mk/tests/fossil-single.mk
index 310e6ee951..f5b940fa5d 100644
--- a/mk/tests/fossil-single.mk
+++ b/mk/tests/fossil-single.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-FOSSIL_REPO=	${.CURDIR}/files/repo/pkgbase.fossil
+FOSSIL_REPO=	${.CURDIR:H}/repos/pkgbase.fossil
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/git-checkout_date b/mk/tests/git-checkout_date
index 4a575fe7b4..d93a265d98 100644
--- a/mk/tests/git-checkout_date
+++ b/mk/tests/git-checkout_date
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "git-checkout_date.mk"
-setup_git_repository
+set_up_package "git-checkout_date.mk"
+set_up_repository git
 
 step "Testing Git with CHECKOUT_DATE"
 CHECKOUT_DATE="2018-02-01" package_make patch
diff --git a/mk/tests/git-checkout_date.mk b/mk/tests/git-checkout_date.mk
index 69f509d570..f9ef34da2b 100644
--- a/mk/tests/git-checkout_date.mk
+++ b/mk/tests/git-checkout_date.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-GIT_REPO=	${.CURDIR}/files/repo/pkgbase
+GIT_REPO=	${.CURDIR:H}/repos/pkgbase
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/git-multi b/mk/tests/git-multi
index 08f392a85f..05fc5d02d5 100644
--- a/mk/tests/git-multi
+++ b/mk/tests/git-multi
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "git-multi.mk"
-setup_git_repository
+set_up_package "git-multi.mk"
+set_up_repository git
 
 step "Testing Git with multiple repositories"
 package_make patch
diff --git a/mk/tests/git-multi.mk b/mk/tests/git-multi.mk
index 72ec505e0e..33775f5b07 100644
--- a/mk/tests/git-multi.mk
+++ b/mk/tests/git-multi.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-GIT_REPO=		${.CURDIR}/files/repo/pkgbase
+GIT_REPO=		${.CURDIR:H}/repos/pkgbase
 GIT_REPOSITORIES=	2017 current
 GIT_REPO.2017=		${GIT_REPO}
 GIT_TAG.2017=		v2017
diff --git a/mk/tests/git-show-all b/mk/tests/git-show-all
index 028d8c49a9..57626b56c7 100644
--- a/mk/tests/git-show-all
+++ b/mk/tests/git-show-all
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "git-show-all.mk"
-setup_git_repository
+set_up_package "git-show-all.mk"
+set_up_repository git
 
 step "Testing show-all-git"
 package_make show-all-git
diff --git a/mk/tests/git-show-all.mk b/mk/tests/git-show-all.mk
index 644c707b4e..e0dc4ecd63 100644
--- a/mk/tests/git-show-all.mk
+++ b/mk/tests/git-show-all.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-GIT_REPO=		${.CURDIR}/files/repo/pkgbase
+GIT_REPO=		${.CURDIR:H}/repos/pkgbase
 GIT_REPOSITORIES=	2017 current
 GIT_REPO.2017=		${GIT_REPO}
 GIT_TAG.2017=		v2017
diff --git a/mk/tests/git-single b/mk/tests/git-single
index e45c0e43e7..2ce33e9380 100644
--- a/mk/tests/git-single
+++ b/mk/tests/git-single
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "git-single.mk"
-setup_git_repository
+set_up_package "git-single.mk"
+set_up_repository git
 
 step "Testing Git with a single repository"
 package_make patch
diff --git a/mk/tests/git-single.mk b/mk/tests/git-single.mk
index 8e5ae7d9fa..3f6fc7a2d2 100644
--- a/mk/tests/git-single.mk
+++ b/mk/tests/git-single.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-GIT_REPO=	${.CURDIR}/files/repo/pkgbase
+GIT_REPO=	${.CURDIR:H}/repos/pkgbase
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/git-update b/mk/tests/git-update
new file mode 100644
index 0000000000..3509ce4468
--- /dev/null
+++ b/mk/tests/git-update
@@ -0,0 +1,30 @@
+#! /bin/sh
+. "${0%/*}/test.subr"
+
+set_up_package "git-update.mk"
+set_up_repository git
+
+step "Testing Git before a remote update"
+package_make patch
+
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2018-03-01"
+
+step "Testing Git after a remote update"
+cd "$repoworkdir"
+scm_git_commit "2022-03-01"
+package_make clean
+package_make patch
+
+# The working copy of the package has been updated to reflect the remote
+# change.
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2022-03-01"
+# TODO: The archive in ${DISTDIR} should be updated, but it isn't.
+
+
+step "Testing Git after a remote update"
+package_make clean
+package_make patch
+
+# The working copy of the package has been updated to reflect the remote
+# change.
+assert_that --file "$wrkdir/pkgbase/today" --has-content "2022-03-01"
diff --git a/mk/tests/git-update.mk b/mk/tests/git-update.mk
new file mode 100644
index 0000000000..3f6fc7a2d2
--- /dev/null
+++ b/mk/tests/git-update.mk
@@ -0,0 +1,15 @@
+# $NetBSD$
+
+DISTNAME=	pkgbase-1.0
+CATEGORIES=	pkgtools
+GIT_REPO=	${.CURDIR:H}/repos/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-checkout_date b/mk/tests/hg-checkout_date
index e2003759b5..a93692710e 100644
--- a/mk/tests/hg-checkout_date
+++ b/mk/tests/hg-checkout_date
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "hg-checkout_date.mk"
-setup_hg_repository
+set_up_package "hg-checkout_date.mk"
+set_up_repository hg
 
 step "Testing Mercurial with CHECKOUT_DATE"
 CHECKOUT_DATE="2018-02-01" package_make patch
diff --git a/mk/tests/hg-checkout_date.mk b/mk/tests/hg-checkout_date.mk
index 0153f78f76..f573b31025 100644
--- a/mk/tests/hg-checkout_date.mk
+++ b/mk/tests/hg-checkout_date.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-HG_REPO=	${.CURDIR}/files/repo/pkgbase
+HG_REPO=	${.CURDIR:H}/repos/pkgbase
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/hg-multi b/mk/tests/hg-multi
index e17d8adb77..1198bfa711 100644
--- a/mk/tests/hg-multi
+++ b/mk/tests/hg-multi
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "hg-multi.mk"
-setup_hg_repository
+set_up_package "hg-multi.mk"
+set_up_repository hg
 
 step "Testing Mercurial with multiple repositories"
 package_make patch
diff --git a/mk/tests/hg-multi.mk b/mk/tests/hg-multi.mk
index 8f8d599e9b..d186ec8e10 100644
--- a/mk/tests/hg-multi.mk
+++ b/mk/tests/hg-multi.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-HG_REPO=		${.CURDIR}/files/repo/pkgbase
+HG_REPO=		${.CURDIR:H}/repos/pkgbase
 HG_REPOSITORIES=	2017 current
 HG_REPO.2017=		${HG_REPO}
 HG_TAG.2017=		v2017
diff --git a/mk/tests/hg-show-all b/mk/tests/hg-show-all
index 7cb1a75f21..f03e6c36d0 100644
--- a/mk/tests/hg-show-all
+++ b/mk/tests/hg-show-all
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "hg-show-all.mk"
-setup_hg_repository
+set_up_package "hg-show-all.mk"
+set_up_repository hg
 
 step "Testing show-all-hg"
 package_make show-all-hg
diff --git a/mk/tests/hg-show-all.mk b/mk/tests/hg-show-all.mk
index 60100a797c..e3502df068 100644
--- a/mk/tests/hg-show-all.mk
+++ b/mk/tests/hg-show-all.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-HG_REPO=		${.CURDIR}/files/repo/pkgbase
+HG_REPO=		${.CURDIR:H}/repos/pkgbase
 HG_REPOSITORIES=	2017 current
 HG_REPO.2017=		${HG_REPO}
 HG_TAG.2017=		v2017
diff --git a/mk/tests/hg-single b/mk/tests/hg-single
index 105e6e9e55..cb7ab4b562 100644
--- a/mk/tests/hg-single
+++ b/mk/tests/hg-single
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "hg-single.mk"
-setup_hg_repository
+set_up_package "hg-single.mk"
+set_up_repository hg
 
 step "Testing Mercurial with a single repository"
 package_make patch
diff --git a/mk/tests/hg-single.mk b/mk/tests/hg-single.mk
index ec27ba5080..df201a74a2 100644
--- a/mk/tests/hg-single.mk
+++ b/mk/tests/hg-single.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-HG_REPO=	${.CURDIR}/files/repo/pkgbase
+HG_REPO=	${.CURDIR:H}/repos/pkgbase
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/svn-checkout_date b/mk/tests/svn-checkout_date
index 4d758e08d1..e7fa52b04d 100644
--- a/mk/tests/svn-checkout_date
+++ b/mk/tests/svn-checkout_date
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "svn-checkout_date.mk"
-setup_svn_repository
+set_up_package "svn-checkout_date.mk"
+set_up_repository svn
 
 step "Testing Subversion with CHECKOUT_DATE"
 CHECKOUT_DATE="2018-02-01" package_make patch
diff --git a/mk/tests/svn-checkout_date.mk b/mk/tests/svn-checkout_date.mk
index 8959a9eab7..a70bf04057 100644
--- a/mk/tests/svn-checkout_date.mk
+++ b/mk/tests/svn-checkout_date.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-SVN_REPO=	file://${.CURDIR}/files/repo/pkgbase/trunk
+SVN_REPO=	file://${.CURDIR:H}/repos/pkgbase/trunk
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/svn-multi b/mk/tests/svn-multi
index 7b30d45921..9b7f2cdd97 100644
--- a/mk/tests/svn-multi
+++ b/mk/tests/svn-multi
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "svn-multi.mk"
-setup_svn_repository
+set_up_package "svn-multi.mk"
+set_up_repository svn
 
 step "Testing Subversion with multiple repositories"
 package_make patch
diff --git a/mk/tests/svn-multi.mk b/mk/tests/svn-multi.mk
index 5a1fcab3be..2db8ba6e91 100644
--- a/mk/tests/svn-multi.mk
+++ b/mk/tests/svn-multi.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-SVN_REPO=		file://${.CURDIR}/files/repo/pkgbase/trunk
+SVN_REPO=		file://${.CURDIR:H}/repos/pkgbase/trunk
 SVN_REPOSITORIES=	2017 current
 SVN_REPO.2017=		${SVN_REPO}
 SVN_REVISION.2017=	1
diff --git a/mk/tests/svn-show-all b/mk/tests/svn-show-all
index 1896ee2d9a..50380c3f07 100644
--- a/mk/tests/svn-show-all
+++ b/mk/tests/svn-show-all
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "svn-show-all.mk"
-setup_svn_repository
+set_up_package "svn-show-all.mk"
+set_up_repository svn
 
 step "Testing show-all-svn"
 package_make show-all-svn
diff --git a/mk/tests/svn-show-all.mk b/mk/tests/svn-show-all.mk
index 8b019b8c84..8cd8e90334 100644
--- a/mk/tests/svn-show-all.mk
+++ b/mk/tests/svn-show-all.mk
@@ -10,7 +10,7 @@ LICENSE=	2-clause-bsd
 
 NO_CHECKSUM=	yes
 
-SVN_REPO=		file://${.CURDIR}/files/repo/pkgbase/trunk
+SVN_REPO=		file://${.CURDIR:H}/repos/pkgbase/trunk
 SVN_REPOSITORIES=	2017 current
 SVN_REPO.2017=		${SVN_REPO}
 SVN_REVISION.2017=	1
diff --git a/mk/tests/svn-single b/mk/tests/svn-single
index 6d05d1e2fb..eb1aaa81aa 100644
--- a/mk/tests/svn-single
+++ b/mk/tests/svn-single
@@ -1,8 +1,8 @@
 #! /bin/sh
 . "${0%/*}/test.subr"
 
-setup_package "svn-single.mk"
-setup_svn_repository
+set_up_package "svn-single.mk"
+set_up_repository svn
 
 step "Testing Subversion with a single repository"
 package_make patch
diff --git a/mk/tests/svn-single.mk b/mk/tests/svn-single.mk
index 46bccbbad6..1ba44ea9fd 100644
--- a/mk/tests/svn-single.mk
+++ b/mk/tests/svn-single.mk
@@ -2,7 +2,7 @@
 
 DISTNAME=	pkgbase-1.0
 CATEGORIES=	pkgtools
-SVN_REPO=	file://${.CURDIR}/files/repo/pkgbase/trunk
+SVN_REPO=	file://${.CURDIR:H}/repos/pkgbase/trunk
 
 MAINTAINER=	rillig%NetBSD.org@localhost
 HOMEPAGE=	https://www.pkgsrc.org/
diff --git a/mk/tests/test.subr b/mk/tests/test.subr
index 00fe6368ab..c93a17b417 100644
--- a/mk/tests/test.subr
+++ b/mk/tests/test.subr
@@ -1,4 +1,22 @@
 #! /bin/sh
+#
+# This file contains helper functions for the SCM tests (CVS, Fossil,
+# Git, Mercurial, Subversion).  All these SCM systems share a common
+# structure:
+#
+#	* During the tests, a temporary directory is created in
+#	  ${PKGSRCDIR}, containing all files relevant to the tests.
+#
+#	* The "remote" repositories are created on-demand in $reposdir,
+#	  containing a few selected commits.  Code that modifies these
+#	  repositories works from $repoworkdir.
+#
+#	* Each SCM system is implemented via a few shell functions that are
+#	  called by set_up_repository and that may also be called directly.
+#
+#	* Since several SCM systems check out the code into a directory whose
+#	  name corresponds to the repository URL, the repositories are named
+#	  "pkgbase", which is the package name used in the various test cases.
 
 set -eu
 
@@ -15,40 +33,27 @@ die() {
 	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() {
+set_up_package() {
 	trap clean_up EXIT
 
 	pkgsrcdir=`cd "$srcdir/../../.." && exec pwd`
 	test -f "$pkgsrcdir/mk/bsd.pkg.mk" || die "This test must be run from inside pkgsrc"
 
-	category=`uuidgen 2>/dev/null || echo "wip-mk-scm-${RANDOM-4}"`
-	pkgdir="$pkgsrcdir/$category/$testname"
-	rm -rf "$pkgdir"
+	categorydir="$pkgsrcdir/00-wip-mk-tests-scm"
+	rm -rf "$categorydir"
+
+	pkgdir="$categorydir/$testname"
 	mkdir -p "$pkgdir"
+
 	cp "$srcdir/$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"
+	reposdir="$categorydir/repos"
+	repoworkdir="$categorydir/repo-work"
 
-	# Install the VCS if necessary; needed by setup_*_repository.
+	# Install the VCS if necessary; needed by set_up_repository.
 	package_make depends
 	package_make clean
 
@@ -56,139 +61,179 @@ setup_package() {
 }
 
 clean_up() {
-	if [ "${category-}" ]; then
-		rm -rf "$pkgsrcdir/$category"
+	if [ $? -eq 0 ] && [ "${categorydir-}" ]; then
+		rm -rf "$categorydir"
 	fi
 }
 
-# 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".
+set_up_repository() {
+	step "Setting up $(scm_$1_name) repository"
+
+	scm_$1_init
+	cd "$repoworkdir"
+	> today
+	scm_$1_add 'today'
+	scm_$1_commit "2017-01-01"
+	scm_$1_tag v2017
+	scm_$1_commit "2018-01-01"
+	scm_$1_commit "2018-03-01"
+}
 
-setup_cvs_repository() {
-	step "Setting up CVS repository"
+scm_cvs_name() {
+	echo "CVS"
+}
 
-	cvs -d "$repodir" init
-	mkdir "$repodir/pkgbase"
+scm_cvs_init() {
+	cvs -d "$reposdir" init
+	mkdir "$reposdir/pkgbase"
 
-	cvs -d "$repodir" checkout -d "$tmpdir/pkgbase" "pkgbase"
-	cd "$tmpdir/pkgbase"
+	cvs -d "$reposdir" checkout -d "$repoworkdir" "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 .
+scm_cvs_add() {
+	cvs add "$1"
+}
 
-	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"
+scm_cvs_commit() {
+	echo "$1" > today
+	cvs commit -m "today is $1" today
+	cvs_admin_set_date "$reposdir/pkgbase/today,v" "$(tr -- - . < today).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"
+scm_cvs_tag() {
+	cvs tag "$1" .
 }
 
-setup_fossil_repository() {
-	step "Setting up Fossil repository"
+cvs_admin_set_date() {
+	# Adjust the date of the previous commit.
+	awk '
+		BEGIN { FS = "\t"; OFS = FS }
+		NR == 1 && $1 == "head" { rev = $2; sub(";", "", rev) }
+		now && $1 == "date" { now = 0; $2 = "'"$2"';" }
+		$0 == rev { now = 1 }
+		{ print }
+	' "$1" > "$1.tmp"
+	mv -f "$1.tmp" "$1"
+}
 
-	mkdir -p "$repodir"
-	cd "$repodir"
-	fossil init --date-override "2017-01-01" pkgbase.fossil
-	fossil open "pkgbase.fossil"
+scm_fossil_name() {
+	echo "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
+scm_fossil_init() {
+	mkdir -p "$reposdir"
+	cd "$reposdir"
+	fossil init --date-override '2017-01-01' 'pkgbase.fossil'
+	fossil open --workdir "$repoworkdir" 'pkgbase.fossil'
+}
 
-	echo "2018-01-01" > today
-	fossil add today
-	fossil commit -m "today is 2018-01-01" --date-override "2018-01-01" --hash -- today
+scm_fossil_add() {
+	fossil add "$1"
+}
 
-	echo "2018-03-01" > today
-	fossil commit -m "today is 2018-03-01" --date-override "2018-03-01" --hash -- today
+scm_fossil_commit() {
+	echo "$1" > today
+	fossil commit -m "today is $1" --date-override "$1" --hash -- today
 }
 
-setup_git_repository() {
-	step "Setting up Git repository"
+scm_fossil_tag() {
+	# XXX: Why 1 second after midnight?
+	fossil tag add --date-override "$(cat today) 00:00:01" "$1" tip
+}
 
-	git init "$repodir/pkgbase"
-	cd "$repodir/pkgbase"
+scm_git_name() {
+	echo "Git"
+}
 
-	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 -c user.name="User" -c user.email="user%example.org@localhost" \
-			commit -m "today is 2017-01-01" today
-	git tag v2017
+scm_git_init() {
+	# When cloning a Git repository, the name of the working directory
+	# is based on the repository name.
+	repodir="$reposdir/pkgbase"
+	git -c init.defaultBranch=master init "$repodir"
+	ln -s "$repodir" "$repoworkdir"
+}
 
-	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 -c user.name="User" -c user.email="user%example.org@localhost" \
-			commit -m "today is 2018-01-01" today
+scm_git_add() {
+	git add "$1"
+}
 
-	echo "2018-03-01" > today
-	GIT_AUTHOR_DATE="2018-03-01T00:00:00Z" GIT_COMMITTER_DATE="2018-03-01T00:00:00Z" \
+scm_git_commit() {
+	echo "$1" > today
+	GIT_AUTHOR_DATE="$1""T00:00:00Z" GIT_COMMITTER_DATE="$1""T00:00:00Z" \
 		git -c user.name="User" -c user.email="user%example.org@localhost" \
-			commit -m "today is 2018-03-01" today
+			commit -m "today is $1" today
+}
+
+scm_git_tag() {
+	git tag "$1"
+}
+
+scm_hg_name() {
+	echo "Mercurial"
 }
 
-setup_hg_repository() {
-	step "Setting up Mercurial repository"
+scm_hg_init() {
+	# When cloning a Mercurial repository, the name of the working
+	# directory is based on the repository name.
+	repodir="$reposdir/pkgbase"
+	hg init "$repodir"
+	ln -s "$repodir" "$repoworkdir"
+}
 
-	hg init "$repodir/pkgbase"
-	cd "$repodir/pkgbase"
+scm_hg_add() {
+	hg add "$1"
+}
 
-	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
+scm_hg_commit() {
+	echo "$1" > today
+	hg commit -m "today is $1" -d "$1T00:00:00Z" -u "user" -- today
+}
 
-	echo "2018-01-01" > today
-	hg commit -m "today is 2018-01-01" -d "2018-01-01T00:00:00Z" -u "user" -- today
+scm_hg_tag() {
+	hg tag -u "user" "$1"
+}
 
-	echo "2018-03-01" > today
-	hg commit -m "today is 2018-03-01" -d "2018-03-01T00:00:00Z" -u "user" -- today
+scm_svn_name() {
+	echo "Subversion"
 }
 
-setup_svn_repository() {
-	step "Setting up Subversion repository"
+scm_svn_init() {
+	repodir="$reposdir/pkgbase"
+	mkdir "$reposdir"
+	svnadmin create "$repodir"
 
-	mkdir "$repodir"
-	svnadmin create "$repodir/pkgbase"
-	hook="$repodir/pkgbase/hooks/pre-revprop-change"
+	hook="$repodir/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 checkout "file://$repodir" "$repoworkdir"
 
-	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"
+	cd "$repoworkdir"
+	mkdir trunk tags branches
+	svn add trunk tags branches
 
-	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"
+	repoworkdir="$repoworkdir/trunk"
+}
+
+scm_svn_add() {
+	svn add "$1"
+}
+
+scm_svn_commit() {
+	echo "$1" > today
+	svn commit -m "today is $1"
+	svn propset "svn:date" --revprop -r HEAD "$1T00: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"
+scm_svn_tag() {
+	svn -m "$1" --parents copy "file://$repodir/trunk" "file://$repodir/tags/$1"
+	svn propset "svn:date" --revprop -r HEAD "$(cat today)T00:00:00.000001Z"
 }
 
 package_make() {
 	cd "$pkgdir"
 	bmake=`type "bmake" 1>/dev/null 2>&1 && echo "bmake" || echo "make"`
-	DISTDIR="$tmpdir/distfiles" "$bmake" "$@"
+	DISTDIR="$categorydir/distfiles" "$bmake" "$@"
 }
 
 assert_that() {


Home | Main Index | Thread Index | Old Index