Gentoo Archives: gentoo-commits

From: Conrad Kostecki <conikost@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Wed, 20 Jan 2021 21:18:35
Message-Id: 1611177496.0ee2ce738bd38c7ffcdc69943e66273e38f5a189.conikost@gentoo
1 commit: 0ee2ce738bd38c7ffcdc69943e66273e38f5a189
2 Author: Conrad Kostecki <conikost <AT> gentoo <DOT> org>
3 AuthorDate: Mon Jan 4 13:15:19 2021 +0000
4 Commit: Conrad Kostecki <conikost <AT> gentoo <DOT> org>
5 CommitDate: Wed Jan 20 21:18:16 2021 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=0ee2ce73
7
8 eclass/lua-utils.eclass: Add support for test-runners
9
10 During migration of dev-lua/* ebuilds to slotted lua, I noticed, that
11 many ebuilds use 'dev-lua/busted' for running tests. This change adds
12 support for running a test-runner, at first only 'busted' for now.
13 Also a non-color and plaintext output will be used for the test-runner 'busted'.
14
15 This is basically a copy of the test-runner section, written by mgorny,
16 which already exists in 'distutils-r1', but modified and adapted to lua.
17
18 In order to use this feature, you can define 'lua_enable_tests busted'
19 to setup everything needed for tests and run them. By default,
20 'dev-lua/busted' assumes, that tests are in the 'spec' folder.
21
22 If this is not the case, you can add a second argument to specify a
23 different folder. For example, if the folder is called 'foo', you can
24 just run 'lua_enable_tests busted foo'.
25
26 More test-runners can be added in future, if needed.
27
28 Signed-off-by: Conrad Kostecki <conikost <AT> gentoo.org>
29
30 eclass/lua-utils.eclass | 70 +++++++++++++++++++++++++++++++++++++++++++++++++
31 1 file changed, 70 insertions(+)
32
33 diff --git a/eclass/lua-utils.eclass b/eclass/lua-utils.eclass
34 index 100be14cb08..0589318ef51 100644
35 --- a/eclass/lua-utils.eclass
36 +++ b/eclass/lua-utils.eclass
37 @@ -344,6 +344,76 @@ _lua_export() {
38 done
39 }
40
41 +# @FUNCTION: lua_enable_tests
42 +# @USAGE: <test-runner> <test-directory>
43 +# @DESCRIPTION:
44 +# Set up IUSE, RESTRICT, BDEPEND and src_test() for running tests
45 +# with the specified test runner. Also copies the current value
46 +# of RDEPEND to test?-BDEPEND. The test-runner argument must be one of:
47 +#
48 +# - busted: dev-lua/busted
49 +#
50 +# Additionally, a second argument can be passed after <test-runner>,
51 +# so <test-runner> will use that directory to search for tests.
52 +# If not passed, a default directory of <test-runner> will be used.
53 +#
54 +# - busted: spec
55 +#
56 +# This function is meant as a helper for common use cases, and it only
57 +# takes care of basic setup. You still need to list additional test
58 +# dependencies manually. If you have uncommon use case, you should
59 +# not use it and instead enable tests manually.
60 +#
61 +# This function must be called in global scope, after RDEPEND has been
62 +# declared. Take care not to overwrite the variables set by it.
63 +lua_enable_tests() {
64 + debug-print-function ${FUNCNAME} "${@}"
65 +
66 + [[ ${#} -ge 1 ]] || die "${FUNCNAME} takes at least one argument: test-runner (test-directory)"
67 + local test_directory
68 + local test_pkg
69 + case ${1} in
70 + busted)
71 + test_directory="${2:-spec}"
72 + test_pkg="dev-lua/busted"
73 + if [[ ! ${_LUA_SINGLE_R0} ]]; then
74 + eval "lua_src_test() {
75 + busted --lua=\"\${ELUA}\" --output=\"plainTerminal\" \"${test_directory}\" || die \"Tests fail with \${ELUA}\"
76 + }"
77 + src_test() {
78 + lua_foreach_impl lua_src_test
79 + }
80 + else
81 + eval "src_test() {
82 + busted --lua=\"\${ELUA}\" --output=\"plainTerminal\" \"${test_directory}\" || die \"Tests fail with \${ELUA}\"
83 + }"
84 + fi
85 + ;;
86 + *)
87 + die "${FUNCNAME}: unsupported argument: ${1}"
88 + esac
89 +
90 + local test_deps=${RDEPEND}
91 + if [[ -n ${test_pkg} ]]; then
92 + if [[ ! ${_LUA_SINGLE_R0} ]]; then
93 + test_deps+=" ${test_pkg}[${LUA_USEDEP}]"
94 + else
95 + test_deps+=" $(lua_gen_cond_dep "
96 + ${test_pkg}[\${LUA_USEDEP}]
97 + ")"
98 + fi
99 + fi
100 + if [[ -n ${test_deps} ]]; then
101 + IUSE+=" test"
102 + RESTRICT+=" !test? ( test )"
103 + BDEPEND+=" test? ( ${test_deps} )"
104 + fi
105 +
106 + # we need to ensure successful return in case we're called last,
107 + # otherwise Portage may wrongly assume sourcing failed
108 + return 0
109 +}
110 +
111 # @FUNCTION: lua_get_CFLAGS
112 # @USAGE: [<impl>]
113 # @DESCRIPTION: