Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/eunit/src/eunit.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@
{registered,[]},
{applications, [kernel,stdlib]},
{env, []},
{runtime_dependencies, ["stdlib-6.0","kernel-5.3","erts-9.0"]}]}.
{runtime_dependencies, ["stdlib-6.0","kernel-8.3","erts-9.0"]}]}.
91 changes: 50 additions & 41 deletions lib/eunit/src/eunit_data.erl
Original file line number Diff line number Diff line change
Expand Up @@ -375,49 +375,58 @@ parse({node, N, T}, Options) when is_atom(N) ->
parse({node, N, "", T}, Options);
parse({node, N, A, T1}=T, Options) when is_atom(N) ->
case eunit_lib:is_string(A) of
true ->
%% TODO: better stack traces for internal funs like these
parse({setup,
fun () ->
%% TODO: auto-start net_kernel if needed
StartedNet = false,
%% The following is commented out because of problems when running
%% eunit as part of the init sequence (from the command line):
%% StartedNet =
%% case whereis(net_kernel) of
%% undefined ->
%% M = list_to_atom(atom_to_list(N)
%% ++ "_master"),
%% case net_kernel:start([M]) of
%% {ok, _} ->
%% true;
%% {error, E} ->
%% throw({net_kernel_start, E})
%% end;
%% _ -> false
%% end,
%% ?debugVal({started, StartedNet}),
{Name, Host} = eunit_lib:split_node(N),
{ok, Node} = case peer:start_link(#{
true ->
%% TODO: better stack traces for internal funs like these
%% Wrap T1 so the instantiator receives the node name
T2 = case T1 of
F when is_function(F, 1) ->
fun({_Peer, NodeName, _}) -> F(NodeName) end;
{with, As} when is_list(As) ->
fun({_Peer, NodeName, _}) ->
{with, NodeName, As}
end;
_ ->
T1
end,
parse({setup,
fun () ->
{Name, Host} = eunit_lib:split_node(N),
StartedNet =
case node() of
'nonode@nohost' ->
M = list_to_atom(atom_to_list(Name)
++ "_master"),
case net_kernel:start(M, #{name_domain => shortnames}) of
{ok, _} ->
true;
{error, E} ->
throw({net_kernel_start, E})
end;
_ -> false
end,
PathArgs = lists:flatmap(
fun(P) -> ["-pa", P] end,
code:get_path()),
{ok, Peer, NodeName} = case peer:start_link(#{
host => atom_to_list(Host),
name => Name, args => parse_peer_args(A)}) of
{ok, Pid} -> {ok, Pid};
{ok, Pid, _Node} -> {ok, Pid};
name => Name,
args => PathArgs ++ parse_peer_args(A)}) of
{ok, Pid, Node0} -> {ok, Pid, Node0};
{error, Rsn} -> throw({peer_start, Rsn})
end,
{Node, StartedNet}
end,
fun ({Node, StopNet}) ->
%% ?debugVal({stop, StopNet}),
peer:stop(Node),
case StopNet of
true -> net_kernel:stop();
false -> ok
end
end,
T1}, Options);
false ->
bad_test(T)
{Peer, NodeName, StartedNet}
end,
fun ({Peer, _NodeName, StopNet}) ->
%% ?debugVal({stop, StopNet}),
peer:stop(Peer),
case StopNet of
true -> net_kernel:stop();
false -> ok
end
end,
T2}, Options);
false ->
bad_test(T)
end;
parse({module, M}, Options) when is_atom(M) ->
{data, {"module '" ++ atom_to_list(M) ++ "'", get_module_tests(M, Options)}};
Expand Down Expand Up @@ -833,7 +842,7 @@ data_test_() ->
?_assertMatch(ok, eunit:test({spawn, Tests})),
?_assertMatch(ok, eunit:test({setup, Setup, Cleanup,
fun (P) -> ?_test(ok = ping(P)) end})),
%%?_assertMatch(ok, eunit:test({node, test@localhost, Tests})),
?_assertMatch(ok, eunit:test({node, test@localhost, Tests})),
?_assertMatch(ok, eunit:test({module, eunit_lib})),
?_assertMatch(ok, eunit:test(eunit_lib)),
?_assertMatch(ok, eunit:test("examples/tests.txt"))
Expand Down
64 changes: 61 additions & 3 deletions lib/eunit/test/eunit_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
-export([all/0, suite/0, groups/0, init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2,
app_test/1, appup_test/1, eunit_test/1, eunit_exact_test/1,
fixture_test/1, primitive_test/1, surefire_utf8_test/1,
fixture_test/1, node_test/1, primitive_test/1, surefire_utf8_test/1,
surefire_latin_test/1, surefire_c0_test/1, surefire_ensure_dir_test/1,
stacktrace_at_timeout_test/1, scale_timeouts_test/1,
report_failed_setup_inparallel_test/1, parse_commandline_test/1]).
Expand All @@ -42,8 +42,8 @@ suite() -> [{ct_hooks,[ts_install_cth]}].

all() ->
[app_test, appup_test, eunit_test, eunit_exact_test, primitive_test,
fixture_test, surefire_utf8_test, surefire_latin_test, surefire_c0_test,
surefire_ensure_dir_test, stacktrace_at_timeout_test,
fixture_test, node_test, surefire_utf8_test, surefire_latin_test,
surefire_c0_test, surefire_ensure_dir_test, stacktrace_at_timeout_test,
scale_timeouts_test, report_failed_setup_inparallel_test,
parse_commandline_test].

Expand Down Expand Up @@ -155,6 +155,64 @@ fixture_test(Config) when is_list(Config) ->
[{1, fun(_A, _B) -> fun() -> a_test end end}]}),
ok.

node_test(Config) when is_list(Config) ->
T = fun() -> ok end,
%% Plain tests
ok = eunit:test({node, eunit_node_plain, [T, T, T]}),
%% Instantiator receives node name as atom
ok = eunit:test(
{node, eunit_node_inst, fun(Node) ->
true = is_atom(Node),
{spawn, Node, [
fun() -> Node = node() end
]}
end}),
%% With extra args
ok = eunit:test(
{node, eunit_node_args, "+S 1", fun(Node) ->
true = is_atom(Node),
{spawn, Node, [T]}
end}),
%% Test {node, ...} during system initialization (non-distributed).
%% Verifies that auto-starting net_kernel is safe with -eval, -s,
%% -run, and -S flags as described in init(3).
PrivDir = proplists:get_value(priv_dir, Config, "."),
HelperMod = eunit_node_init_test,
HelperSrc = filename:join(PrivDir, atom_to_list(HelperMod) ++ ".erl"),
ok = file:write_file(HelperSrc,
"-module(" ++ atom_to_list(HelperMod) ++ ").\n"
"-export([start/0, start/1]).\n"
"start() -> start([]).\n"
"start(_) ->\n"
" ok = eunit:test({node, init_test, fun() -> ok end}),\n"
" halt(0).\n"),
{ok, HelperMod} = compile:file(HelperSrc, [{outdir, PrivDir}]),
[Exec | ExecArgs] = string:split(ct:get_progname(), " ", all),
Erl = os:find_executable(Exec),
BaseArgs = ExecArgs ++ ["-noshell"],
%% -eval
0 = run_erl_cmd(Erl, BaseArgs ++ ["-eval",
"ok = eunit:test({node, init_eval, fun() -> ok end}), halt(0)."]),
%% -s
0 = run_erl_cmd(Erl, BaseArgs ++ ["-pa", PrivDir,
"-s", atom_to_list(HelperMod), "start"]),
%% -run
0 = run_erl_cmd(Erl, BaseArgs ++ ["-pa", PrivDir,
"-run", atom_to_list(HelperMod), "start"]),
%% -S
0 = run_erl_cmd(Erl, BaseArgs ++ ["-pa", PrivDir,
"-S", atom_to_list(HelperMod), "start"]),
ok.

run_erl_cmd(Erl, Args) ->
Port = open_port({spawn_executable, Erl},
[{args, Args}, stderr_to_stdout, exit_status, hide]),
receive
{Port, {exit_status, Status}} -> Status
after 30_000 ->
ct:fail({erl_timeout, Args})
end.

check_test_results(Primitive, Expected) ->
receive
{test_report, TestReport} ->
Expand Down
Loading