From a7f0e9be4ce149a5fa062a4061228f2b39763a7c Mon Sep 17 00:00:00 2001 From: Paul Guyot Date: Sun, 24 Aug 2025 06:54:07 +0200 Subject: [PATCH] eunit: allow execution of a single test with `eunit:test/1` Ensure `eunit:test/1` works with any list of tests, and if there is no module or test case, the report does not fail. Signed-off-by: Paul Guyot --- libs/etest/src/eunit.erl | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/etest/src/eunit.erl b/libs/etest/src/eunit.erl index 97f001858..d1ea138d5 100644 --- a/libs/etest/src/eunit.erl +++ b/libs/etest/src/eunit.erl @@ -219,8 +219,16 @@ module_tests(Module, [_ | Tail], Acc) -> module_tests(Module, Tail, Acc). report(Progress, Identification) -> - {module, Module} = lists:keyfind(module, 1, Identification), - {test_case, TestCase} = lists:keyfind(test_case, 1, Identification), + ModuleString = + case lists:keyfind(module, 1, Identification) of + false -> ""; + {module, Module} -> io_lib:format("~s:", [Module]) + end, + TestCaseString = + case lists:keyfind(test_case, 1, Identification) of + false -> ""; + {test_case, TestCase} -> TestCase + end, LineString = case lists:keyfind(line, 1, Identification) of false -> ""; @@ -239,7 +247,9 @@ report(Progress, Identification) -> {exit, Reason} -> io_lib:format(":FAIL:exited with ~p", [Reason]); timeout -> ":FAIL:timeout" end, - io:format("~s:~s ~s~s~s\n", [Module, LineString, TestCase, TitleString, ProgressString]). + io:format("~s:~s ~s~s~s\n", [ + ModuleString, LineString, TestCaseString, TitleString, ProgressString + ]). run_test(Identification, TestFun, #state{total = Total} = State0) -> report(start, Identification),