public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH v3] eclass/lua-utils.eclass: Add support for test-runners
@ 2021-01-08  0:14 Conrad Kostecki
  2021-01-20 21:27 ` Conrad Kostecki
  0 siblings, 1 reply; 2+ messages in thread
From: Conrad Kostecki @ 2021-01-08  0:14 UTC (permalink / raw
  To: gentoo-dev

During migration of dev-lua/* ebuilds to slotted lua, I noticed, that
many ebuilds use 'dev-lua/busted' for running tests. This change adds
support for running a test-runner, at first only 'busted' for now.
Also a non-color and plaintext output will be used for the test-runner 'busted'.

This is basically a copy of the test-runner section, written by mgorny,
which already exists in 'distutils-r1', but modified and adapted to lua.

In order to use this feature, you can define 'lua_enable_tests busted'
to setup everything needed for tests and run them. By default,
'dev-lua/busted' assumes, that tests are in the 'spec' folder.

If this is not the case, you can add a second argument to specify a
different folder. For example, if the folder is called 'foo', you can
just run 'lua_enable_tests busted foo'.

More test-runners can be added in future, if needed.

PATCH v2 has two changes:
- removed EAPI condition, as lua-utils is EAPI=7 only.
- make test_directoy as a local variable and use eval in src_test to
  read it.

PATCH v3 has the right patch, as v2 was wrong.

Signed-off-by: Conrad Kostecki <conikost@gentoo.org>
---
 eclass/lua-utils.eclass | 70 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 70 insertions(+)

diff --git a/eclass/lua-utils.eclass b/eclass/lua-utils.eclass
index 100be14cb08..0589318ef51 100644
--- a/eclass/lua-utils.eclass
+++ b/eclass/lua-utils.eclass
@@ -344,6 +344,76 @@ _lua_export() {
 	done
 }
 
+# @FUNCTION: lua_enable_tests
+# @USAGE: <test-runner> <test-directory>
+# @DESCRIPTION:
+# Set up IUSE, RESTRICT, BDEPEND and src_test() for running tests
+# with the specified test runner.  Also copies the current value
+# of RDEPEND to test?-BDEPEND.  The test-runner argument must be one of:
+#
+# - busted: dev-lua/busted
+#
+# Additionally, a second argument can be passed after <test-runner>,
+# so <test-runner> will use that directory to search for tests.
+# If not passed, a default directory of <test-runner> will be used.
+#
+# - busted: spec
+#
+# This function is meant as a helper for common use cases, and it only
+# takes care of basic setup.  You still need to list additional test
+# dependencies manually.  If you have uncommon use case, you should
+# not use it and instead enable tests manually.
+#
+# This function must be called in global scope, after RDEPEND has been
+# declared.  Take care not to overwrite the variables set by it.
+lua_enable_tests() {
+	debug-print-function ${FUNCNAME} "${@}"
+
+	[[ ${#} -ge 1 ]] || die "${FUNCNAME} takes at least one argument: test-runner (test-directory)"
+	local test_directory
+	local test_pkg
+	case ${1} in
+		busted)
+			test_directory="${2:-spec}"
+			test_pkg="dev-lua/busted"
+			if [[ ! ${_LUA_SINGLE_R0} ]]; then
+				eval "lua_src_test() {
+					busted --lua=\"\${ELUA}\" --output=\"plainTerminal\" \"${test_directory}\" || die \"Tests fail with \${ELUA}\"
+				}"
+				src_test() {
+					lua_foreach_impl lua_src_test
+				}
+			else
+				eval "src_test() {
+					busted --lua=\"\${ELUA}\" --output=\"plainTerminal\" \"${test_directory}\" || die \"Tests fail with \${ELUA}\"
+				}"
+			fi
+			;;
+		*)
+			die "${FUNCNAME}: unsupported argument: ${1}"
+	esac
+
+	local test_deps=${RDEPEND}
+	if [[ -n ${test_pkg} ]]; then
+		if [[ ! ${_LUA_SINGLE_R0} ]]; then
+			test_deps+=" ${test_pkg}[${LUA_USEDEP}]"
+		else
+			test_deps+=" $(lua_gen_cond_dep "
+				${test_pkg}[\${LUA_USEDEP}]
+			")"
+		fi
+	fi
+	if [[ -n ${test_deps} ]]; then
+		IUSE+=" test"
+		RESTRICT+=" !test? ( test )"
+		BDEPEND+=" test? ( ${test_deps} )"
+	fi
+
+	# we need to ensure successful return in case we're called last,
+	# otherwise Portage may wrongly assume sourcing failed
+	return 0
+}
+
 # @FUNCTION: lua_get_CFLAGS
 # @USAGE: [<impl>]
 # @DESCRIPTION:
-- 
2.30.0



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [gentoo-dev] [PATCH v3] eclass/lua-utils.eclass: Add support for test-runners
  2021-01-08  0:14 [gentoo-dev] [PATCH v3] eclass/lua-utils.eclass: Add support for test-runners Conrad Kostecki
@ 2021-01-20 21:27 ` Conrad Kostecki
  0 siblings, 0 replies; 2+ messages in thread
From: Conrad Kostecki @ 2021-01-20 21:27 UTC (permalink / raw
  To: gentoo-dev


Am 08.01.2021 um 01:14 schrieb Conrad Kostecki:
> During migration of dev-lua/* ebuilds to slotted lua, I noticed, that
> many ebuilds use 'dev-lua/busted' for running tests. This change adds
> support for running a test-runner, at first only 'busted' for now.
> Also a non-color and plaintext output will be used for the test-runner 'busted'.
>
> This is basically a copy of the test-runner section, written by mgorny,
> which already exists in 'distutils-r1', but modified and adapted to lua.
>
> In order to use this feature, you can define 'lua_enable_tests busted'
> to setup everything needed for tests and run them. By default,
> 'dev-lua/busted' assumes, that tests are in the 'spec' folder.
>
> If this is not the case, you can add a second argument to specify a
> different folder. For example, if the folder is called 'foo', you can
> just run 'lua_enable_tests busted foo'.
>
> More test-runners can be added in future, if needed.
>
> PATCH v2 has two changes:
> - removed EAPI condition, as lua-utils is EAPI=7 only.
> - make test_directoy as a local variable and use eval in src_test to
>    read it.
>
> PATCH v3 has the right patch, as v2 was wrong.

Merged!



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-01-20 21:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-08  0:14 [gentoo-dev] [PATCH v3] eclass/lua-utils.eclass: Add support for test-runners Conrad Kostecki
2021-01-20 21:27 ` Conrad Kostecki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox