This bug aims to bring up discussion of introducing distutils-r1-like test runners to elisp-common eclass. This will reduce amount of redundant code for packages using ert, ert-runner and buttercup tools for tests. Rough draft: https://dev.gentoo.org/~xgqt/documentation/elisp-eclass-tests.org
* Support ** Buttercup #+BEGIN_SRC ebuild # @FUNCTION: elisp_test_buttercup # @USAGE: [test-subdirectory] [test-runner-opts] ... # @DESCRIPTION: # Run ELisp package tests using the buttercup test runner. elisp_test_buttercup() { debug-print-function ${FUNCNAME} "${@}" local test_dir="${1:-$(pwd)}" shift local -a myopts=( ${BYTECOMPFLAGS} ${EMACSFLAGS} --traceback full -L "${test_dir}" "${@}" ) edob buttercup "${myopts[@]}" "${test_dir}" } #+END_SRC ** Ert-runner #+BEGIN_SRC ebuild # @FUNCTION: elisp_test_ert-runner # @USAGE: [test-subdirectory] [test-runner-opts] ... # @DESCRIPTION: # Run ELisp package tests using the ert-runner test runner. elisp_test_ert-runner() { debug-print-function ${FUNCNAME} "${@}" local test_dir="${1:-$(pwd)}" shift local -a myopts=( ${BYTECOMPFLAGS} ${EMACSFLAGS} --no-win --reporter ert+duration --script -L "${test_dir}" "${@}" ) edob ert-runner "${myopts[@]}" "${test_dir}" } #+END_SRC ** Ert #+BEGIN_SRC ebuild # @FUNCTION: elisp_test_ert # @USAGE: [test-subdirectory] [test-runner-opts] ... # @DESCRIPTION: # Run ELisp package tests using ert, the Emacs's built-in test runner. elisp_test_ert() { debug-print-function ${FUNCNAME} "${@}" local test_dir="${1:-$(pwd)}" shift local -a extra_load=() local extra_load_file for extra_load_file in "${test_dir}"/?*-test.el ; do extra_load+=( -l "${extra_load_file}" ) done local -a myopts=( ${BYTECOMPFLAGS} ${EMACSFLAGS} -L "${test_dir}" "${extra_load[@]}" "${@}" -f ert-run-tests-batch-and-exit ) edob ${EMACS} "${myopts[@]}" } #+END_SRC * Enable #+BEGIN_SRC ebuild _ELISP_TEST_RUNNER="" _ELISP_TEST_OPTS="" # @FUNCTION: elisp_enable_tests # @USAGE: [--optional] <test-runner> [test-runner-options] ... # @DESCRIPTION: # Set up IUSE, RESTRICT, BDEPEND and test runner function for running tests # with the specified test runner. # # The test-runner argument must be one of: # # - buttercup: app-emacs/buttercup # # - ert-runner: app-emacs/ert-runner # # - ert: for built-in GNU Emacs test utility # # If the `--optional` flag is passed (before specifying the test runner), # then it is assumed that the ELisp package is a part of some project that # optionally enables GNU Emacs support. # In that case the elisp-test function has to be explicitly called # inside src_test. # # @CODE # inherit elisp-common # # elisp_enable_tests --optional ert-runner "${S}"/elisp -t "!org" # # src_test() { # emake -C tests test # elisp-test # } # @CODE elisp_enable_tests() { debug-print-function ${FUNCNAME} "${@}" local optional if [[ ${1} = --optional ]] ; then optional=YES shift fi local test_pkg local test_runner=${1} shift _ELISP_TEST_OPTS="${@}" case ${test_runner} in buttercup ) test_pkg="app-emacs/buttercup" ;; ert-runner ) test_pkg="app-emacs/ert-runner" ;; ert ) : ;; ,* ) die "elisp_enable_tests: unknown test runner, given: ${test_runner}" ;; esac _ELISP_TEST_RUNNER=${test_runner} if [[ ${test_pkg} ]] ; then IUSE+=" test " RESTRICT+=" !test? ( test ) " if [[ ${optional} ]] ; then BDEPEND+=" test? ( ${test_pkg} ) " else IUSE+=" emacs " BDEPEND+=" test? ( emacs? ( ${test_pkg} ) ) " fi fi return 0 } # @FUNCTION: elisp_src_test # @DESCRIPTION: # This function either calls a speficic test runner enabled by # `elisp_enable_tests` or the default src_test phase function. elisp_src_test() { if [[ ${_ELISP_TEST_RUNNER} ]] ; then "${_ELISP_TEST_RUNNER}" "${_ELISP_TEST_OPTS}" else default fi } #+END_SRC * Usage #+BEGIN_SRC bash elisp_enable_tests buttercup test #+END_SRC #+BEGIN_SRC bash elisp_enable_tests ert-runner "${S}" -L clients -t "!no-win" -t "!org" #+END_SRC
A branch for testing the new features: https://gitlab.com/xgqt/gentoo-private/-/commits/elisp_test_functions
The bug has been closed via the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=e1411e05184086ea6b91a20e5dc7bdd4795f3b5f commit e1411e05184086ea6b91a20e5dc7bdd4795f3b5f Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-03 16:38:32 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:46 +0000 eclass/elisp.eclass: add elisp_src_test Closes: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> eclass/elisp.eclass | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) Additionally, it has been referenced in the following commit(s): https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=dcc382c60effa87794113fb160e143c671622903 commit dcc382c60effa87794113fb160e143c671622903 Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-04 11:01:18 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:47 +0000 app-emacs/a: use elisp-enable-tests Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> app-emacs/a/a-1.0.0.ebuild | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a287a790b6a9cbd161414cad2be1d0e01a619572 commit a287a790b6a9cbd161414cad2be1d0e01a619572 Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-04 10:56:08 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:47 +0000 app-emacs/typescript-mode: use elisp-enable-tests Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> app-emacs/typescript-mode/typescript-mode-0.4.ebuild | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=985fc30ae5bbbdd11c1c8f321f8e9118aac64c47 commit 985fc30ae5bbbdd11c1c8f321f8e9118aac64c47 Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-04 10:52:57 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:47 +0000 app-emacs/doom-modeline: use elisp-enable-tests Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> app-emacs/doom-modeline/doom-modeline-3.3.2.ebuild | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=ce86dbf39676ef14fb30016fd101aff4579bfe2d commit ce86dbf39676ef14fb30016fd101aff4579bfe2d Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-04 10:44:25 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:46 +0000 app-emacs/bnf-mode: use elisp-enable-tests Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> app-emacs/bnf-mode/bnf-mode-0.4.5.ebuild | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=31294c5e6974ac9d9a1e7140946567c6374e4ea3 commit 31294c5e6974ac9d9a1e7140946567c6374e4ea3 Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-03 16:41:51 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:46 +0000 app-emacs/php-mode: use elisp-enable-tests Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> app-emacs/php-mode/php-mode-1.24.3.ebuild | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=8b9dec33a45387cd264637f208b2a559ae856df0 commit 8b9dec33a45387cd264637f208b2a559ae856df0 Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-03 16:41:33 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:46 +0000 app-emacs/lsp-mode: use elisp-enable-tests Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> app-emacs/lsp-mode/lsp-mode-8.0.0_p20220620.ebuild | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=9a9883c244fdf65103086300352d90031ab63339 commit 9a9883c244fdf65103086300352d90031ab63339 Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-03 16:39:11 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:46 +0000 app-emacs/fsharp-mode: use elisp-enable-tests Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> app-emacs/fsharp-mode/fsharp-mode-2.0.ebuild | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d8ac4fe35a9fb94bccf8fe3225ab3eeeabf6ee06 commit d8ac4fe35a9fb94bccf8fe3225ab3eeeabf6ee06 Author: Maciej Barć <xgqt@gentoo.org> AuthorDate: 2023-04-03 16:37:24 +0000 Commit: Maciej Barć <xgqt@gentoo.org> CommitDate: 2023-04-18 00:35:45 +0000 eclass/elisp-common.eclass: add elisp-enable-tests and elisp-test Bug: https://bugs.gentoo.org/898492 Signed-off-by: Maciej Barć <xgqt@gentoo.org> eclass/elisp-common.eclass | 200 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 200 insertions(+)