Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 722418 - src_test: default is not as documented
Summary: src_test: default is not as documented
Status: RESOLVED FIXED
Alias: None
Product: Documentation
Classification: Unclassified
Component: Devmanual (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Devmanual Team
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2020-05-11 09:21 UTC by Manuel Mommertz
Modified: 2020-08-28 19:02 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
ebuild-writing/functions/src_test: Add nonfatal to if conditions. (0001-ebuild-writing-functions-src_test-Add-nonfatal-to-if.patch,1.12 KB, patch)
2020-08-14 12:17 UTC, Ulrich Müller
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Manuel Mommertz 2020-05-11 09:21:49 UTC
The documentation at [1] states that the default src_test is this:

src_test() {
	if emake check -n &> /dev/null; then
		emake check
	elif emake test -n &> /dev/null; then
		emake test
	fi
}

But when I create an ebuild with a src_test as above, tests fail if the Makefile does not provide tests. The reason is that emake forces the ebuild to die if it fails. Therefore emake must not be used for tests like above.



[1] https://devmanual.gentoo.org/ebuild-writing/functions/src_test/index.html

Reproducible: Always
Comment 1 Ulrich Müller gentoo-dev 2020-08-14 09:13:59 UTC
@mgorny: The code snippet for src_test() originates from this commit of yours:
https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=96ce954fee8e464edadc473a5ba2da8b8352b6cb

PMS doesn't provide a default implementation, but only says:
"The default implementation used when the ebuild lacks the src_test function must, if tests are enabled, run emake check if and only if such a target is available, or if not run emake test if and only if such a target is available. In both cases, if emake returns non-zero the build must be aborted."

The implementation in Portage's phase-helpers.sh is this:

__eapi0_src_test() {
	# Since we don't want emake's automatic die
	# support (EAPI 4 and later), and we also don't
	# want the warning messages that it produces if
	# we call it in 'nonfatal' mode, we use emake_cmd
	# to emulate the desired parts of emake behavior.
	local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
	local internal_opts=
	if ___eapi_default_src_test_disables_parallel_jobs; then
		internal_opts+=" -j1"
	fi
	if $emake_cmd ${internal_opts} check -n &> /dev/null; then
		__vecho "${emake_cmd} ${internal_opts} check" >&2
		$emake_cmd ${internal_opts} check || \
			die "Make check failed. See above for details."
	elif $emake_cmd ${internal_opts} test -n &> /dev/null; then
		__vecho "${emake_cmd} ${internal_opts} test" >&2
		$emake_cmd ${internal_opts} test || \
			die "Make test failed. See above for details."
	fi
}

This is too long (and too clumsy) and therefore unsuitable for the devmanual, but note its introductory comment. So, how about the following, which should be equivalent to the above except for its output?

src_test() {
	if nonfatal emake check -n &> /dev/null; then
		emake check
	elif nonfatal emake test -n &> /dev/null; then
		emake test
	fi
}
Comment 2 Michał Górny archtester Gentoo Infrastructure gentoo-dev Security 2020-08-14 09:43:04 UTC
Yes, that makes sense.
Comment 3 Ulrich Müller gentoo-dev 2020-08-14 12:17:40 UTC
Created attachment 654616 [details, diff]
ebuild-writing/functions/src_test: Add nonfatal to if conditions.
Comment 4 Larry the Git Cow gentoo-dev 2020-08-28 19:02:01 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=929b5a3a85c3cf34cf967db579a45d8f3ee88564

commit 929b5a3a85c3cf34cf967db579a45d8f3ee88564
Author:     Ulrich Müller <ulm@gentoo.org>
AuthorDate: 2020-08-14 12:15:27 +0000
Commit:     Ulrich Müller <ulm@gentoo.org>
CommitDate: 2020-08-28 18:59:51 +0000

    ebuild-writing/functions/src_test: Add nonfatal to if conditions.
    
    Closes: https://bugs.gentoo.org/722418
    Signed-off-by: Ulrich Müller <ulm@gentoo.org>

 ebuild-writing/functions/src_test/text.xml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)