diff options
author | Florian Schmaus <flow@gentoo.org> | 2024-04-04 17:22:25 +0200 |
---|---|---|
committer | Florian Schmaus <flow@gentoo.org> | 2024-05-14 09:58:12 +0200 |
commit | fa90907e9d23cbbaa15567eb9924b604740aacd6 (patch) | |
tree | 8ec5cf05e3e19d47ad875f538970e49c924f8ca9 /eclass/tests | |
parent | net-misc/pedro: remove unused patch (diff) | |
download | gentoo-fa90907e9d23cbbaa15567eb9924b604740aacd6.tar.gz gentoo-fa90907e9d23cbbaa15567eb9924b604740aacd6.tar.bz2 gentoo-fa90907e9d23cbbaa15567eb9924b604740aacd6.zip |
edo.eclass: enhance edob for usage with noisy commands
Normally, edob can, or rather should, not be used with noisy commands,
i.e., commands that produce an output. This is because the output
destroys the concept of ebegin and eend, where the eend marker is shown
on the same line that is produced by ebegin.
However, it sometimes would be nice to use edob with noisy commands, but
this means to redirect stdout and stderr of those commands. Instead of
redirecting the output to /dev/null, we save the output in a log file
under T. This allows us to present the output to the user in case the
command fails, making it furthermore part of the build.log, which we
expect users to attach to bug reports.
Closes: https://github.com/gentoo/gentoo/pull/36117
Signed-off-by: Florian Schmaus <flow@gentoo.org>
Diffstat (limited to 'eclass/tests')
-rwxr-xr-x | eclass/tests/edo.sh | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/eclass/tests/edo.sh b/eclass/tests/edo.sh new file mode 100755 index 000000000000..cac03e0401ba --- /dev/null +++ b/eclass/tests/edo.sh @@ -0,0 +1,113 @@ +#!/bin/bash +# Copyright 1999-2024 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 +source tests-common.sh || exit + +inherit edo + +make_some_noise() { + echo "Here is some noise:" + echo "${1:?Must provide some noise}" + echo "EoN" +} + +test_edob_simple() { + tbegin "edob with output test" + ( + edob make_some_noise foo + eend $? + ) &> "${T}/edob.out" + local res=$? + if [[ $res -ne 0 ]]; then + tend $res + return 0 + fi + + local log_file="${T}/make_some_noise.log" + local second_line="$(sed -n '2p' "${log_file}")" + [[ "${second_line}" == "foo" ]]; + tend $? "Unexpected output, found \"${second_line}\", expected \"foo\"" + + rm "${log_file}" || die +} + +test_edob_explicit_log_name() { + tbegin "edob with explicit logfile name" + ( + edob -l mylog make_some_noise bar + eend $? + ) &> "${T}/edob.out" + local res=$? + if [[ $res -ne 0 ]]; then + cat "${T}/edob.out" + tend $res + return 0 + fi + + local log_file="${T}/mylog.log" + local second_line="$(sed -n '2p' "${log_file}")" + [[ "${second_line}" == "bar" ]]; + tend $? "Unexpected output, found \"${second_line}\", expected \"foo\"" + + rm "${log_file}" || die +} + +test_edob_explicit_message() { + tbegin "edob with explicit message" + ( + edob -m "Making some noise" make_some_noise baz + eend $? + ) &> "${T}/edob.out" + local res=$? + if [[ $res -ne 0 ]]; then + cat "${T}/edob.out" + tend $res + return 0 + fi + + local log_file="${T}/make_some_noise.log" + local second_line="$(sed -n '2p' "${log_file}")" + [[ "${second_line}" == "baz" ]]; + tend $? "Unexpected output, found \"${second_line}\", expected \"baz\"" + + rm "${log_file}" || die +} + +test_edob_failure() { + make_some_noise_and_fail() { + make_some_noise "$@" + return 1 + } + + tbegin "edob with failing command" + ( + edob -m "Making some noise" make_some_noise_and_fail quz + eend $? + ) &> "${T}/edob.out" + local res=$? + # Now, this time we expect res to be exactly '1'. + if [[ $res -ne 1 ]]; then + tend 1 + return 1 + fi + + local log_file="${T}/make_some_noise_and_fail.log" + local second_line="$(sed -n '2p' "${log_file}")" + [[ "${second_line}" == "quz" ]]; + tend $? "Unexpected output, found \"${second_line}\", expected \"quz\"" + + rm "${log_file}" || die + + local fourth_line_of_edob_out="$(sed -n '4p' "${T}/edob.out")" + [[ "${fourth_line_of_edob_out}" == "quz" ]]; + tend $? "Unexpected output, found \"${fourth_line_of_edob_out}\", expected \"quz\"" +} + +test_edob_simple +test_edob_explicit_log_name +test_edob_explicit_message +test_edob_failure + +texit |