diff options
Diffstat (limited to 'lib/eunit/src/eunit_proc.erl')
-rw-r--r-- | lib/eunit/src/eunit_proc.erl | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/eunit/src/eunit_proc.erl b/lib/eunit/src/eunit_proc.erl index 6e702543d0..fb6619a6d4 100644 --- a/lib/eunit/src/eunit_proc.erl +++ b/lib/eunit/src/eunit_proc.erl @@ -29,7 +29,7 @@ -include("eunit.hrl"). -include("eunit_internal.hrl"). --export([start/4]). +-export([start/4, get_output/0]). %% This must be exported; see new_group_leader/1 for details. -export([group_leader_process/1]). @@ -52,6 +52,18 @@ start(Tests, Order, Super, Reference) order = Order}, spawn_group(local, #group{tests = Tests}, St). +%% Fetches the output captured by the eunit group leader. This is +%% provided to allow test cases to check the captured output. + +-spec get_output() -> string(). +get_output() -> + group_leader() ! {get_output, self()}, + receive + {output, Output} -> Output + after 100 -> + %% The group leader is not an eunit_proc + abort_task(get_output) + end. %% Status messages sent to the supervisor process. (A supervisor does %% not have to act on these messages - it can e.g. just log them, or @@ -594,6 +606,9 @@ group_leader_loop(Runner, Wait, Buf) -> receive after 2 -> ok end, process_flag(priority, low), group_leader_loop(Runner, 0, Buf); + {get_output, From} -> + From ! {output, lists:flatten(lists:reverse(Buf))}, + group_leader_loop(Runner, Wait, Buf); _ -> %% discard any other messages group_leader_loop(Runner, Wait, Buf) @@ -669,4 +684,9 @@ io_error_test_() -> [?_assertMatch({error, enotsup}, io:getopts()), ?_assertMatch({error, enotsup}, io:columns()), ?_assertMatch({error, enotsup}, io:rows())]. + +get_output_test() -> + io:format("Hello"), + Output = get_output(), + ?assertEqual("Hello", Output). -endif. |