Github messages for voidlinux
 help / color / mirror / Atom feed
From: Chocimier <Chocimier@users.noreply.github.com>
To: ml@inbox.vuxu.org
Subject: Re: [PR PATCH] [Updated] common/tests: create
Date: Mon, 30 Jan 2023 19:44:17 +0100	[thread overview]
Message-ID: <20230130184417.g89KUyoy5JqVNDf-ogfVrHOybWSy0oaXibTQ71CT9ls@z> (raw)
In-Reply-To: <gh-mailinglist-notifications-41a7ca26-5023-4802-975b-f1789d68868e-void-packages-29448@inbox.vuxu.org>

[-- Attachment #1: Type: text/plain, Size: 320 bytes --]

There is an updated pull request by Chocimier against master on the void-packages repository

https://github.com/Chocimier/void-packages-org tests
https://github.com/void-linux/void-packages/pull/29448

common/tests: create
None

A patch file from https://github.com/void-linux/void-packages/pull/29448.patch is attached

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: github-pr-tests-29448.patch --]
[-- Type: text/x-diff, Size: 12047 bytes --]

From 14c9ce2055f8a0865c084177e167115a2c00e02a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <chocimier@tlen.pl>
Date: Sat, 13 Mar 2021 22:16:17 +0100
Subject: [PATCH 1/2] common/tests: create

---
 common/tests/00-target-pkg.bats       |  7 +++
 common/tests/10-jobs_number.bats      | 45 +++++++++++++++++
 common/tests/10-options-comptype.bats | 71 +++++++++++++++++++++++++++
 common/tests/all.sh                   | 11 +++++
 common/tests/lib/testfuncs.bash       | 24 +++++++++
 common/tests/templates/jobcounter     | 26 ++++++++++
 common/tests/templates/pkg            |  9 ++++
 7 files changed, 193 insertions(+)
 create mode 100644 common/tests/00-target-pkg.bats
 create mode 100644 common/tests/10-jobs_number.bats
 create mode 100644 common/tests/10-options-comptype.bats
 create mode 100755 common/tests/all.sh
 create mode 100644 common/tests/lib/testfuncs.bash
 create mode 100644 common/tests/templates/jobcounter
 create mode 100644 common/tests/templates/pkg

diff --git a/common/tests/00-target-pkg.bats b/common/tests/00-target-pkg.bats
new file mode 100644
index 000000000000..02428e41d0c1
--- /dev/null
+++ b/common/tests/00-target-pkg.bats
@@ -0,0 +1,7 @@
+@test "Build simple pkg" {
+	load lib/testfuncs
+	prepare_pkg_test
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
+	test -f "${pkgfile}"
+	cleanup_pkg_test
+}
diff --git a/common/tests/10-jobs_number.bats b/common/tests/10-jobs_number.bats
new file mode 100644
index 000000000000..d92a124d0a10
--- /dev/null
+++ b/common/tests/10-jobs_number.bats
@@ -0,0 +1,45 @@
+@test "by default, one job" {
+	load lib/testfuncs
+	prepare_pkg_test jobcounter
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-jobcounter
+	test -f "${pkgfile}"
+	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
+	echo "$jobs"
+	test 1 = "$jobs"
+	cleanup_pkg_test
+}
+
+@test "-j 11" {
+	load lib/testfuncs
+	prepare_pkg_test jobcounter
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" -j 11 pkg xbps-src-test-jobcounter
+	test -f "${pkgfile}"
+	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
+	echo "$jobs"
+	test 11 = "$jobs"
+	cleanup_pkg_test
+}
+
+@test "XBPS_MAKEJOBS=6" {
+	load lib/testfuncs
+	prepare_pkg_test jobcounter
+	echo XBPS_MAKEJOBS=6 > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-jobcounter
+	test -f "${pkgfile}"
+	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
+	echo "$jobs"
+	test 6 = "$jobs"
+	cleanup_pkg_test
+}
+
+@test "-j 2 XBPS_MAKEJOBS=5" {
+	load lib/testfuncs
+	prepare_pkg_test jobcounter
+	echo XBPS_MAKEJOBS=5 > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" -j 2 pkg xbps-src-test-jobcounter
+	test -f "${pkgfile}"
+	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
+	echo "$jobs"
+	test 2 = "$jobs"
+	cleanup_pkg_test
+}
diff --git a/common/tests/10-options-comptype.bats b/common/tests/10-options-comptype.bats
new file mode 100644
index 000000000000..f403bbd5d2c8
--- /dev/null
+++ b/common/tests/10-options-comptype.bats
@@ -0,0 +1,71 @@
+@test "XBPS_PKG_COMPTYPE=none" {
+	load lib/testfuncs
+	prepare_pkg_test
+	echo XBPS_PKG_COMPTYPE=none > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
+	test -f "${pkgfile}"
+	mime=$(file -b --mime-type "${pkgfile}")
+	echo "$mime"
+	test application/x-tar = "$mime"
+	cleanup_pkg_test
+}
+
+@test "XBPS_PKG_COMPTYPE=gzip" {
+	load lib/testfuncs
+	prepare_pkg_test
+	echo XBPS_PKG_COMPTYPE=gzip > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
+	test -f "${pkgfile}"
+	mime=$(file -b --mime-type "${pkgfile}")
+	echo "$mime"
+	test application/gzip = "$mime"
+	cleanup_pkg_test
+}
+
+@test "XBPS_PKG_COMPTYPE=bzip2" {
+	load lib/testfuncs
+	prepare_pkg_test
+	echo XBPS_PKG_COMPTYPE=bzip2 > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
+	test -f "${pkgfile}"
+	mime=$(file -b --mime-type "${pkgfile}")
+	echo "$mime"
+	test application/x-bzip2 = "$mime"
+	cleanup_pkg_test
+}
+
+@test "XBPS_PKG_COMPTYPE=xz" {
+	load lib/testfuncs
+	prepare_pkg_test
+	echo XBPS_PKG_COMPTYPE=xz > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
+	test -f "${pkgfile}"
+	mime=$(file -b --mime-type "${pkgfile}")
+	echo "$mime"
+	test application/x-xz = "$mime"
+	cleanup_pkg_test
+}
+
+@test "XBPS_PKG_COMPTYPE=lz4" {
+	load lib/testfuncs
+	prepare_pkg_test
+	echo XBPS_PKG_COMPTYPE=lz4 > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
+	test -f "${pkgfile}"
+	mime=$(file -b --mime-type "${pkgfile}")
+	echo "$mime"
+	test application/x-lz4 = "$mime"
+	cleanup_pkg_test
+}
+
+@test "XBPS_PKG_COMPTYPE=zstd" {
+	load lib/testfuncs
+	prepare_pkg_test
+	echo XBPS_PKG_COMPTYPE=zstd > "${tmpconf}"
+	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
+	test -f "${pkgfile}"
+	mime=$(file -b --mime-type "${pkgfile}")
+	echo "$mime"
+	test application/zstd = "$mime"
+	cleanup_pkg_test
+}
diff --git a/common/tests/all.sh b/common/tests/all.sh
new file mode 100755
index 000000000000..fafdde8171a0
--- /dev/null
+++ b/common/tests/all.sh
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+if ! command -v bats > /dev/null; then
+	echo Missing 'bats' command
+	exit 1
+fi
+
+for i in "$(dirname "$0")"/*.bats; do
+	echo $i
+	bats "$i"
+done
diff --git a/common/tests/lib/testfuncs.bash b/common/tests/lib/testfuncs.bash
new file mode 100644
index 000000000000..e7ba6a541599
--- /dev/null
+++ b/common/tests/lib/testfuncs.bash
@@ -0,0 +1,24 @@
+distdir="${BATS_TEST_DIRNAME}/../.."
+template=
+tmprepodir=
+tmprepo=
+tmpconf=
+
+prepare_pkg_test() {
+	template=${1:-pkg}
+	cd "${distdir}"
+	tmprepodir="$(mktemp -d -p ${PWD}/hostdir/binpkgs)"
+	tmprepo="$(basename ${tmprepodir})"
+	tmpconf="etc/conf.${tmprepo}"
+	pkgfile="${tmprepodir}/xbps-src-test-${template}-1_1.$(xbps-uhelper arch).xbps"
+	rm -fr srcpkgs/xbps-src-test-${template}
+	mkdir srcpkgs/xbps-src-test-${template}
+	cp "${BATS_TEST_DIRNAME}/templates/${template}" srcpkgs/xbps-src-test-${template}/template
+	echo XBPS_SUCMD=true > "${tmpconf}"
+}
+
+cleanup_pkg_test() {
+	rm -r srcpkgs/xbps-src-test-${template}
+	rm -r "${tmprepodir}"
+	rm "etc/conf.${tmprepo}"
+}
diff --git a/common/tests/templates/jobcounter b/common/tests/templates/jobcounter
new file mode 100644
index 000000000000..77a56bdd751e
--- /dev/null
+++ b/common/tests/templates/jobcounter
@@ -0,0 +1,26 @@
+# Template file for 'xbps-src-test-jobcounter'
+pkgname=xbps-src-test-jobcounter
+version=1
+revision=1
+build_style=gnu-makefile
+make_cmd="./make"
+make_use_env=yes
+short_desc="Dummy package"
+license="BSD-2-Clause"
+maintainer="Orphaned <orphan@voidlinux.org>"
+homepage="http://voidlinux.org"
+
+pre_build() {
+	mkdir -p ${DESTDIR}/etc
+	cat > ./make << EOF
+	#!/usr/bin/env bash
+	echo x "\$@"
+	while getopts "j:" opt; do
+		case "\$opt" in
+			j) echo \$OPTARG > ${DESTDIR}/etc/jobs; exit 0
+		esac
+	done
+EOF
+	cat make
+	chmod +x ./make
+}
diff --git a/common/tests/templates/pkg b/common/tests/templates/pkg
new file mode 100644
index 000000000000..68333f6fa80e
--- /dev/null
+++ b/common/tests/templates/pkg
@@ -0,0 +1,9 @@
+# Template file for 'xbps-src-test-pkg'
+pkgname=xbps-src-test-pkg
+version=1
+revision=1
+build_style=meta
+short_desc="Dummy package"
+license="BSD-2-Clause"
+maintainer="Orphaned <orphan@voidlinux.org>"
+homepage="http://voidlinux.org"

From 0994f81d5f20928c81e5224bc364b79f688be77c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Piotr=20W=C3=B3jcik?= <chocimier@tlen.pl>
Date: Fri, 27 Jan 2023 22:18:15 +0100
Subject: [PATCH 2/2] common/tests: cleanup with teardown

---
 common/tests/00-target-pkg.bats       | 10 ++++++++--
 common/tests/10-jobs_number.bats      | 19 ++++++++-----------
 common/tests/10-options-comptype.bats | 25 ++++++++-----------------
 3 files changed, 24 insertions(+), 30 deletions(-)

diff --git a/common/tests/00-target-pkg.bats b/common/tests/00-target-pkg.bats
index 02428e41d0c1..e6b8b843cecd 100644
--- a/common/tests/00-target-pkg.bats
+++ b/common/tests/00-target-pkg.bats
@@ -1,7 +1,13 @@
-@test "Build simple pkg" {
+setup() {
 	load lib/testfuncs
 	prepare_pkg_test
+}
+
+teardown() {
+	cleanup_pkg_test
+}
+
+@test "Build simple pkg" {
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
 	test -f "${pkgfile}"
-	cleanup_pkg_test
 }
diff --git a/common/tests/10-jobs_number.bats b/common/tests/10-jobs_number.bats
index d92a124d0a10..2d961beb8771 100644
--- a/common/tests/10-jobs_number.bats
+++ b/common/tests/10-jobs_number.bats
@@ -1,45 +1,42 @@
-@test "by default, one job" {
+setup() {
 	load lib/testfuncs
 	prepare_pkg_test jobcounter
+}
+
+teardown() {
+	cleanup_pkg_test
+}
+
+@test "by default, one job" {
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-jobcounter
 	test -f "${pkgfile}"
 	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
 	echo "$jobs"
 	test 1 = "$jobs"
-	cleanup_pkg_test
 }
 
 @test "-j 11" {
-	load lib/testfuncs
-	prepare_pkg_test jobcounter
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" -j 11 pkg xbps-src-test-jobcounter
 	test -f "${pkgfile}"
 	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
 	echo "$jobs"
 	test 11 = "$jobs"
-	cleanup_pkg_test
 }
 
 @test "XBPS_MAKEJOBS=6" {
-	load lib/testfuncs
-	prepare_pkg_test jobcounter
 	echo XBPS_MAKEJOBS=6 > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-jobcounter
 	test -f "${pkgfile}"
 	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
 	echo "$jobs"
 	test 6 = "$jobs"
-	cleanup_pkg_test
 }
 
 @test "-j 2 XBPS_MAKEJOBS=5" {
-	load lib/testfuncs
-	prepare_pkg_test jobcounter
 	echo XBPS_MAKEJOBS=5 > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" -j 2 pkg xbps-src-test-jobcounter
 	test -f "${pkgfile}"
 	jobs=$(tar xOf ${pkgfile} ./etc/jobs)
 	echo "$jobs"
 	test 2 = "$jobs"
-	cleanup_pkg_test
 }
diff --git a/common/tests/10-options-comptype.bats b/common/tests/10-options-comptype.bats
index f403bbd5d2c8..c765f8a1686e 100644
--- a/common/tests/10-options-comptype.bats
+++ b/common/tests/10-options-comptype.bats
@@ -1,71 +1,62 @@
-@test "XBPS_PKG_COMPTYPE=none" {
+setup() {
 	load lib/testfuncs
 	prepare_pkg_test
+}
+
+teardown() {
+	cleanup_pkg_test
+}
+
+@test "XBPS_PKG_COMPTYPE=none" {
 	echo XBPS_PKG_COMPTYPE=none > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
 	test -f "${pkgfile}"
 	mime=$(file -b --mime-type "${pkgfile}")
 	echo "$mime"
 	test application/x-tar = "$mime"
-	cleanup_pkg_test
 }
 
 @test "XBPS_PKG_COMPTYPE=gzip" {
-	load lib/testfuncs
-	prepare_pkg_test
 	echo XBPS_PKG_COMPTYPE=gzip > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
 	test -f "${pkgfile}"
 	mime=$(file -b --mime-type "${pkgfile}")
 	echo "$mime"
 	test application/gzip = "$mime"
-	cleanup_pkg_test
 }
 
 @test "XBPS_PKG_COMPTYPE=bzip2" {
-	load lib/testfuncs
-	prepare_pkg_test
 	echo XBPS_PKG_COMPTYPE=bzip2 > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
 	test -f "${pkgfile}"
 	mime=$(file -b --mime-type "${pkgfile}")
 	echo "$mime"
 	test application/x-bzip2 = "$mime"
-	cleanup_pkg_test
 }
 
 @test "XBPS_PKG_COMPTYPE=xz" {
-	load lib/testfuncs
-	prepare_pkg_test
 	echo XBPS_PKG_COMPTYPE=xz > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
 	test -f "${pkgfile}"
 	mime=$(file -b --mime-type "${pkgfile}")
 	echo "$mime"
 	test application/x-xz = "$mime"
-	cleanup_pkg_test
 }
 
 @test "XBPS_PKG_COMPTYPE=lz4" {
-	load lib/testfuncs
-	prepare_pkg_test
 	echo XBPS_PKG_COMPTYPE=lz4 > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
 	test -f "${pkgfile}"
 	mime=$(file -b --mime-type "${pkgfile}")
 	echo "$mime"
 	test application/x-lz4 = "$mime"
-	cleanup_pkg_test
 }
 
 @test "XBPS_PKG_COMPTYPE=zstd" {
-	load lib/testfuncs
-	prepare_pkg_test
 	echo XBPS_PKG_COMPTYPE=zstd > "${tmpconf}"
 	./xbps-src -c "${tmprepo}" -r "${tmprepo}" pkg xbps-src-test-pkg
 	test -f "${pkgfile}"
 	mime=$(file -b --mime-type "${pkgfile}")
 	echo "$mime"
 	test application/zstd = "$mime"
-	cleanup_pkg_test
 }

  parent reply	other threads:[~2023-01-30 18:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-13 21:23 [PR PATCH] " Chocimier
2022-05-08  2:12 ` github-actions
2022-08-09  2:13 ` github-actions
2022-08-24  2:14 ` [PR PATCH] [Closed]: " github-actions
2023-01-30 18:44 ` Chocimier [this message]
2023-05-02  1:52 ` github-actions
2023-05-16  1:54 ` [PR PATCH] [Closed]: " github-actions

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230130184417.g89KUyoy5JqVNDf-ogfVrHOybWSy0oaXibTQ71CT9ls@z \
    --to=chocimier@users.noreply.github.com \
    --cc=ml@inbox.vuxu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).