diff options
author | Henrik Nord <[email protected]> | 2011-08-30 11:28:41 +0200 |
---|---|---|
committer | Henrik Nord <[email protected]> | 2011-08-30 11:28:41 +0200 |
commit | db333803584b17b6f281c974f8f78034be60e010 (patch) | |
tree | 380c5ebb0a684fbc7d6e6a9ffac5641428d250e3 | |
parent | 1a2fbf178614f752f04fd5c7499bb659293adf10 (diff) | |
parent | 25543b7f0be1b87351d616143b5d149b1aed1cea (diff) | |
download | otp-db333803584b17b6f281c974f8f78034be60e010.tar.gz otp-db333803584b17b6f281c974f8f78034be60e010.tar.bz2 otp-db333803584b17b6f281c974f8f78034be60e010.zip |
Merge branch 'dev' into major
-rw-r--r-- | erts/epmd/src/epmd.c | 6 | ||||
-rw-r--r-- | erts/epmd/src/epmd_cli.c | 5 | ||||
-rw-r--r-- | lib/eunit/doc/overview.edoc | 2 | ||||
-rw-r--r-- | lib/eunit/include/eunit.hrl | 102 | ||||
-rw-r--r-- | lib/eunit/src/eunit.app.src | 16 | ||||
-rw-r--r-- | lib/eunit/src/eunit.erl | 2 | ||||
-rw-r--r-- | lib/eunit/src/eunit_data.erl | 70 | ||||
-rw-r--r-- | lib/eunit/src/eunit_server.erl | 7 | ||||
-rw-r--r-- | lib/eunit/src/eunit_surefire.erl | 2 | ||||
-rw-r--r-- | lib/eunit/src/eunit_test.erl | 72 | ||||
-rw-r--r-- | lib/eunit/src/eunit_tests.erl | 26 | ||||
-rw-r--r-- | lib/eunit/vsn.mk | 2 | ||||
-rw-r--r-- | lib/stdlib/doc/src/supervisor.xml | 9 | ||||
-rw-r--r-- | lib/stdlib/src/supervisor.erl | 7 | ||||
-rw-r--r-- | lib/stdlib/test/supervisor_SUITE.erl | 35 | ||||
-rw-r--r-- | lib/tools/emacs/erlang.el | 84 | ||||
-rw-r--r-- | system/doc/reference_manual/distributed.xml | 2 |
17 files changed, 376 insertions, 73 deletions
diff --git a/erts/epmd/src/epmd.c b/erts/epmd/src/epmd.c index 08576d923f..2267f9b12b 100644 --- a/erts/epmd/src/epmd.c +++ b/erts/epmd/src/epmd.c @@ -324,7 +324,11 @@ static void run_daemon(EpmdVars *g) } /* move cwd to root to make sure we are not on a mounted filesystem */ - chdir("/"); + if (chdir("/") < 0) + { + dbg_perror(g,"epmd: chdir() failed"); + epmd_cleanup_exit(g,1); + } umask(0); diff --git a/erts/epmd/src/epmd_cli.c b/erts/epmd/src/epmd_cli.c index ac55ba6bb6..2377c0dfe7 100644 --- a/erts/epmd/src/epmd_cli.c +++ b/erts/epmd/src/epmd_cli.c @@ -104,7 +104,10 @@ void epmd_call(EpmdVars *g,int what) fd = conn_to_epmd(g); put_int16(1,buf); buf[2] = what; - write(fd,buf,3); + if (write(fd, buf, 3) != 3) { + printf("epmd: Can't write to epmd\n"); + epmd_cleanup_exit(g,1); + } if (read(fd,(char *)&i,4) != 4) { if (!g->silent) printf("epmd: no response from local epmd\n"); diff --git a/lib/eunit/doc/overview.edoc b/lib/eunit/doc/overview.edoc index be05a13fba..2583f0be25 100644 --- a/lib/eunit/doc/overview.edoc +++ b/lib/eunit/doc/overview.edoc @@ -913,7 +913,7 @@ To make the descriptions simpler, we first list some definitions: <td>`CleanupX'</td><td>`(X::any(), R::any()) -> any()'</td> </tr> <tr> -<td>`Instantiator'</td><td>`((R::any()) -> Tests | {with, [AbstractTestFun::((any()) -> any())]}'</td> +<td>`Instantiator'</td><td>`((R::any()) -> Tests) | {with, [AbstractTestFun::((any()) -> any())]}'</td> </tr> <tr> <td>`Where'</td><td>`local | spawn | {spawn, Node::atom()}'</td> diff --git a/lib/eunit/include/eunit.hrl b/lib/eunit/include/eunit.hrl index 82ba982f03..493ba60a2d 100644 --- a/lib/eunit/include/eunit.hrl +++ b/lib/eunit/include/eunit.hrl @@ -39,6 +39,7 @@ -ifndef(EUNIT_HRL). -define(EUNIT_HRL, true). + %% allow defining TEST to override NOTEST -ifdef(TEST). -undef(NOTEST). @@ -164,7 +165,7 @@ %% This is mostly a convenience which gives more detailed reports. %% Note: Guard is a guarded pattern, and can not be used for value. -ifdef(NOASSERT). --define(assertMatch(Guard,Expr),ok). +-define(assertMatch(Guard, Expr), ok). -else. -define(assertMatch(Guard, Expr), ((fun () -> @@ -174,17 +175,37 @@ [{module, ?MODULE}, {line, ?LINE}, {expression, (??Expr)}, - {expected, (??Guard)}, + {pattern, (??Guard)}, {value, __V}]}) end end)())). -endif. -define(_assertMatch(Guard, Expr), ?_test(?assertMatch(Guard, Expr))). +%% This is the inverse case of assertMatch, for convenience. +-ifdef(NOASSERT). +-define(assertNotMatch(Guard, Expr), ok). +-else. +-define(assertNotMatch(Guard, Expr), + ((fun () -> + __V = (Expr), + case __V of + Guard -> .erlang:error({assertNotMatch_failed, + [{module, ?MODULE}, + {line, ?LINE}, + {expression, (??Expr)}, + {pattern, (??Guard)}, + {value, __V}]}); + _ -> ok + end + end)())). +-endif. +-define(_assertNotMatch(Guard, Expr), ?_test(?assertNotMatch(Guard, Expr))). + %% This is a convenience macro which gives more detailed reports when %% the expected LHS value is not a pattern, but a computed value -ifdef(NOASSERT). --define(assertEqual(Expect,Expr),ok). +-define(assertEqual(Expect, Expr), ok). -else. -define(assertEqual(Expect, Expr), ((fun (__X) -> @@ -201,9 +222,29 @@ -endif. -define(_assertEqual(Expect, Expr), ?_test(?assertEqual(Expect, Expr))). +%% This is the inverse case of assertEqual, for convenience. +-ifdef(NOASSERT). +-define(assertNotEqual(Unexpected, Expr), ok). +-else. +-define(assertNotEqual(Unexpected, Expr), + ((fun (__X) -> + case (Expr) of + __X -> .erlang:error({assertNotEqual_failed, + [{module, ?MODULE}, + {line, ?LINE}, + {expression, (??Expr)}, + {value, __X}]}); + _ -> ok + end + end)(Unexpected))). +-endif. +-define(_assertNotEqual(Unexpected, Expr), + ?_test(?assertNotEqual(Unexpected, Expr))). + %% Note: Class and Term are patterns, and can not be used for value. +%% Term can be a guarded pattern, but Class cannot. -ifdef(NOASSERT). --define(assertException(Class, Term, Expr),ok). +-define(assertException(Class, Term, Expr), ok). -else. -define(assertException(Class, Term, Expr), ((fun () -> @@ -212,7 +253,7 @@ [{module, ?MODULE}, {line, ?LINE}, {expression, (??Expr)}, - {expected, + {pattern, "{ "++(??Class)++" , "++(??Term) ++" , [...] }"}, {unexpected_success, __V}]}) @@ -223,7 +264,7 @@ [{module, ?MODULE}, {line, ?LINE}, {expression, (??Expr)}, - {expected, + {pattern, "{ "++(??Class)++" , "++(??Term) ++" , [...] }"}, {unexpected_exception, @@ -243,6 +284,43 @@ -define(_assertExit(Term, Expr), ?_assertException(exit, Term, Expr)). -define(_assertThrow(Term, Expr), ?_assertException(throw, Term, Expr)). +%% This is the inverse case of assertException, for convenience. +%% Note: Class and Term are patterns, and can not be used for value. +%% Both Class and Term can be guarded patterns. +-ifdef(NOASSERT). +-define(assertNotException(Class, Term, Expr), ok). +-else. +-define(assertNotException(Class, Term, Expr), + ((fun () -> + try (Expr) of + _ -> ok + catch + __C:__T -> + case __C of + Class -> + case __T of + Term -> + .erlang:error({assertNotException_failed, + [{module, ?MODULE}, + {line, ?LINE}, + {expression, (??Expr)}, + {pattern, + "{ "++(??Class)++" , " + ++(??Term)++" , [...] }"}, + {unexpected_exception, + {__C, __T, + .erlang:get_stacktrace() + }}]}); + _ -> ok + end; + _ -> ok + end + end + end)())). +-endif. +-define(_assertNotException(Class, Term, Expr), + ?_test(?assertNotException(Class, Term, Expr))). + %% Macros for running operating system commands. (Note that these %% require EUnit to be present at runtime, or at least eunit_lib.) @@ -267,7 +345,7 @@ %% these are only used for testing; they always return 'ok' on success, %% and have no effect if debugging/testing is turned off -ifdef(NOASSERT). --define(assertCmdStatus(N, Cmd),ok). +-define(assertCmdStatus(N, Cmd), ok). -else. -define(assertCmdStatus(N, Cmd), ((fun () -> @@ -285,7 +363,7 @@ -define(assertCmd(Cmd), ?assertCmdStatus(0, Cmd)). -ifdef(NOASSERT). --define(assertCmdOutput(T, Cmd),ok). +-define(assertCmdOutput(T, Cmd), ok). -else. -define(assertCmdOutput(T, Cmd), ((fun () -> @@ -313,11 +391,12 @@ -define(debugHere, ok). -define(debugFmt(S, As), ok). -define(debugVal(E), (E)). --define(debugTime(S,E), (E)). +-define(debugTime(S, E), (E)). -else. -define(debugMsg(S), (begin - .io:fwrite(user, <<"~s:~w: ~s\n">>, [?FILE, ?LINE, S]), + .io:fwrite(user, <<"~s:~w:~w: ~s\n">>, + [?FILE, ?LINE, self(), S]), ok end)). -define(debugHere, (?debugMsg("<-"))). @@ -327,7 +406,7 @@ ?debugFmt(<<"~s = ~P">>, [(??E), __V, 15]), __V end)(E))). --define(debugTime(S,E), +-define(debugTime(S, E), ((fun () -> {__T0, _} = statistics(wall_clock), __V = (E), @@ -337,4 +416,5 @@ end)())). -endif. + -endif. % EUNIT_HRL diff --git a/lib/eunit/src/eunit.app.src b/lib/eunit/src/eunit.app.src index 4fd76588c3..5e16dfa2ce 100644 --- a/lib/eunit/src/eunit.app.src +++ b/lib/eunit/src/eunit.app.src @@ -5,17 +5,17 @@ {vsn, "%VSN%"}, {modules, [eunit, eunit_autoexport, - eunit_striptests, - eunit_server, + eunit_data, + eunit_lib, + eunit_listener, eunit_proc, eunit_serial, + eunit_server, + eunit_striptests, + eunit_surefire, eunit_test, eunit_tests, - eunit_lib, - eunit_listener, - eunit_data, - eunit_tty, - eunit_surefire]}, + eunit_tty]}, {registered,[]}, - {applications, [stdlib]}, + {applications, [kernel,stdlib]}, {env, []}]}. diff --git a/lib/eunit/src/eunit.erl b/lib/eunit/src/eunit.erl index da35c5c2ec..15fc3bdf32 100644 --- a/lib/eunit/src/eunit.erl +++ b/lib/eunit/src/eunit.erl @@ -16,7 +16,7 @@ %% $Id: eunit.erl 339 2009-04-05 14:10:47Z rcarlsson $ %% %% @copyright 2004-2009 Micka�l R�mond, Richard Carlsson -%% @author Mickaël Rémond <[email protected]> +%% @author Micka�l R�mond <[email protected]> %% [http://www.process-one.net/] %% @author Richard Carlsson <[email protected]> %% [http://user.it.uu.se/~richardc/] diff --git a/lib/eunit/src/eunit_data.erl b/lib/eunit/src/eunit_data.erl index 0543b6c543..288dd74ddf 100644 --- a/lib/eunit/src/eunit_data.erl +++ b/lib/eunit/src/eunit_data.erl @@ -146,8 +146,10 @@ iter_next(I = #iter{next = [T | Ts]}) -> iter_prev(#iter{prev = []}) -> none; -iter_prev(#iter{prev = [T | Ts], next = Next, pos = Pos} = I) -> - {T, I#iter{prev = Ts, next = [T | Next], pos = Pos - 1}}. +iter_prev(#iter{prev = [T | Ts]} = I) -> + {T, I#iter{prev = Ts, + next = [T | I#iter.next], + pos = I#iter.pos - 1}}. %% --------------------------------------------------------------------- @@ -363,7 +365,8 @@ parse({file, F} = T) when is_list(F) -> parse({dir, D}=T) when is_list(D) -> case eunit_lib:is_string(D) of true -> - {data, {"directory \"" ++ D ++ "\"", get_directory_modules(D)}}; + {data, {"directory \"" ++ D ++ "\"", + get_directory_module_tests(D)}}; false -> bad_test(T) end; @@ -385,10 +388,10 @@ parse({S, T1} = T) when is_list(S) -> end; parse({S, T1}) when is_binary(S) -> group(#group{tests = T1, desc = S}); -parse(T) when tuple_size(T) > 2, is_list(element(1, T)) -> +parse(T) when is_tuple(T), size(T) > 2, is_list(element(1, T)) -> [S | Es] = tuple_to_list(T), parse({S, list_to_tuple(Es)}); -parse(T) when tuple_size(T) > 2, is_binary(element(1, T)) -> +parse(T) when is_tuple(T), size(T) > 2, is_binary(element(1, T)) -> [S | Es] = tuple_to_list(T), parse({S, list_to_tuple(Es)}); parse(M) when is_atom(M) -> @@ -596,7 +599,7 @@ testfuns(Es, M, TestSuffix, GeneratorSuffix) -> %% --------------------------------------------------------------------- -%% Getting a test set from a file +%% Getting a test set from a file (text file or object file) %% @throws {file_read_error, {Reason::atom(), Message::string(), %% fileName()}} @@ -625,17 +628,23 @@ get_file_tests(F) -> is_module_filename(F) -> filename:extension(F) =:= code:objfile_extension(). +objfile_test({M, File}) -> + {setup, + fun () -> + %% TODO: better error/stacktrace for this internal fun + code:purge(M), + {module,M} = code:load_abs(filename:rootname(File)), + ok + end, + {module, M}}; objfile_test(File) -> + objfile_test({objfile_module(File), File}). + +objfile_module(File) -> try - {module, M} = lists:keyfind(module, 1, beam_lib:info(File)), - {setup, - fun () -> - %% TODO: better error/stacktrace for this internal fun - code:purge(M), - {module,M} = code:load_abs(filename:rootname(File)), - ok - end, - {module, M}} + {value, {module, M}} = lists:keysearch(module, 1, + beam_lib:info(File)), + M catch _:_ -> throw({file_read_error, @@ -644,15 +653,34 @@ objfile_test(File) -> %% --------------------------------------------------------------------- -%% Getting a list of module names from object files in a directory - -%% @throws {file_read_error, {Reason::atom(), Message::string(), -%% fileName()}} +%% Getting a set of module tests from the object files in a directory + +%% @throws {file_read_error, +%% {Reason::atom(), Message::string(), fileName()}} + +get_directory_module_tests(D) -> + Ms = get_directory_modules(D), + %% for all 'm' in the set, remove 'm_tests' if present + F = fun ({M,_}, S) -> + Name = atom_to_list(M), + case lists:suffix(?DEFAULT_TESTMODULE_SUFFIX, Name) of + false -> + Name1 = Name ++ ?DEFAULT_TESTMODULE_SUFFIX, + M1 = list_to_atom(Name1), + dict:erase(M1, S); + true -> + S + end + end, + [objfile_test(Obj) + || Obj <- dict:to_list(lists:foldl(F, dict:from_list(Ms), Ms))]. %% TODO: handle packages (recursive search for files) - get_directory_modules(D) -> - [objfile_test(filename:join(D, F)) + [begin + F1 = filename:join(D, F), + {objfile_module(F1), F1} + end || F <- eunit_lib:list_dir(D), is_module_filename(F)]. diff --git a/lib/eunit/src/eunit_server.erl b/lib/eunit/src/eunit_server.erl index bf1bb9bcef..2cdfef2668 100644 --- a/lib/eunit/src/eunit_server.erl +++ b/lib/eunit/src/eunit_server.erl @@ -59,8 +59,9 @@ watch(Server, Module, Opts) when is_atom(Module) -> watch_path(Server, Path, Opts) -> command(Server, {watch, {path, filename:flatten(Path)}, Opts}). +%% note that the user must use $ at the end to match whole paths only watch_regexp(Server, Regex, Opts) -> - case regexp:parse(Regex) of + case re:compile(Regex,[anchored]) of {ok, R} -> command(Server, {watch, {regexp, R}, Opts}); {error, _}=Error -> @@ -278,8 +279,8 @@ is_watched(Path, St) -> match_any(sets:to_list(St#state.regexps), Path). match_any([R | Rs], Str) -> - case regexp:first_match(Str, R) of - {match, _, _} -> true; + case re:run(Str, R, [{capture,none}]) of + match -> true; _ -> match_any(Rs, Str) end; match_any([], _Str) -> false. diff --git a/lib/eunit/src/eunit_surefire.erl b/lib/eunit/src/eunit_surefire.erl index 25b5cde09c..6e0a447105 100644 --- a/lib/eunit/src/eunit_surefire.erl +++ b/lib/eunit/src/eunit_surefire.erl @@ -15,7 +15,7 @@ %% %% $Id: $ %% -%% @author Mickaël Rémond <[email protected]> +%% @author Micka�l R�mond <[email protected]> %% @copyright 2009 Micka�l R�mond, Paul Guyot %% @see eunit %% @doc Surefire reports for EUnit (Format used by Maven and Atlassian diff --git a/lib/eunit/src/eunit_test.erl b/lib/eunit/src/eunit_test.erl index d322c4b420..9ac1d1e7d9 100644 --- a/lib/eunit/src/eunit_test.erl +++ b/lib/eunit/src/eunit_test.erl @@ -131,12 +131,27 @@ macro_test_() -> [{module,_}, {line,_}, {expression,_}, - {expected,"[ _ ]"}, + {pattern,"[ _ ]"}, {value,[]}]}, _}} = run_testfun(F) end), ?_test(begin + {?LINE, F} = ?_assertNotMatch(ok, error), + {ok, ok} = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertNotMatch([_], [42]), + {error,{error,{assertNotMatch_failed, + [{module,_}, + {line,_}, + {expression,_}, + {pattern,"[ _ ]"}, + {value,[42]}]}, + _}} + = run_testfun(F) + end), + ?_test(begin {?LINE, F} = ?_assertEqual(ok, ok), {ok, ok} = run_testfun(F) end), @@ -152,6 +167,20 @@ macro_test_() -> = run_testfun(F) end), ?_test(begin + {?LINE, F} = ?_assertNotEqual(1, 0), + {ok, ok} = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertNotEqual(2, 1+1), + {error,{error,{assertNotEqual_failed, + [{module,_}, + {line,_}, + {expression,_}, + {value,2}]}, + _}} + = run_testfun(F) + end), + ?_test(begin {?LINE, F} = ?_assertException(error, badarith, erlang:error(badarith)), {ok, ok} = run_testfun(F) @@ -162,7 +191,7 @@ macro_test_() -> [{module,_}, {line,_}, {expression,_}, - {expected,_}, + {pattern,_}, {unexpected_success,ok}]}, _}} = run_testfun(F) @@ -174,15 +203,48 @@ macro_test_() -> [{module,_}, {line,_}, {expression,_}, - {expected,_}, + {pattern,_}, + {unexpected_exception, + {error,badarith,_}}]}, + _}} + = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertError(badarith, + erlang:error(badarith)), + {ok, ok} = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertExit(normal, exit(normal)), + {ok, ok} = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertThrow(foo, throw(foo)), + {ok, ok} = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertNotException(error, badarith, 42), + {ok, ok} = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertNotException(error, badarith, + erlang:error(badarg)), + {ok, ok} = run_testfun(F) + end), + ?_test(begin + {?LINE, F} = ?_assertNotException(error, badarith, + erlang:error(badarith)), + {error,{error,{assertNotException_failed, + [{module,_}, + {line,_}, + {expression,_}, + {pattern,_}, {unexpected_exception, {error,badarith,_}}]}, _}} = run_testfun(F) end) ]}. - -under_eunit_test() -> ?assert(?UNDER_EUNIT). -endif. diff --git a/lib/eunit/src/eunit_tests.erl b/lib/eunit/src/eunit_tests.erl index 37c0b4d6ae..a63d102d98 100644 --- a/lib/eunit/src/eunit_tests.erl +++ b/lib/eunit/src/eunit_tests.erl @@ -26,17 +26,17 @@ -include("eunit.hrl"). -ifdef(TEST). -%% Cause all the other modules to be tested as well as this one. -full_test_() -> - %%{application, eunit}. % this currently causes a loop - %% We use the below until loop detection is implemented - [eunit_autoexport, - eunit_striptests, - eunit_server, - eunit_proc, - eunit_serial, - eunit_test, - eunit_lib, - eunit_data, - eunit_tty]. +id(X) -> X. % for suppressing compiler warnings -endif. + +under_eunit_test() -> ?assert(?UNDER_EUNIT). + +let_test() -> ?assertEqual(42, ?LET(X, 17, X+25)). + +if_test_() -> + [?_assertEqual(17, ?IF(id(1) > 0, 17, 42)), + ?_assertEqual(42, ?IF(id(1) < 0, 17, 42))]. + +matches_test_() -> + [?_assert(?MATCHES("hel"++_, "hello")), + ?_assertNot(?MATCHES("hal"++_, "hello"))]. diff --git a/lib/eunit/vsn.mk b/lib/eunit/vsn.mk index d7edd7977b..d933085bbc 100644 --- a/lib/eunit/vsn.mk +++ b/lib/eunit/vsn.mk @@ -1 +1 @@ -EUNIT_VSN = 2.1.7 +EUNIT_VSN = 2.2.0 diff --git a/lib/stdlib/doc/src/supervisor.xml b/lib/stdlib/doc/src/supervisor.xml index 009aa60faa..edd119d37a 100644 --- a/lib/stdlib/doc/src/supervisor.xml +++ b/lib/stdlib/doc/src/supervisor.xml @@ -150,9 +150,12 @@ child_spec() = {Id,StartFunc,Restart,Shutdown,Type,Modules} <p><c>Restart</c> defines when a terminated child process should be restarted. A <c>permanent</c> child process should always be restarted, a <c>temporary</c> child process should - never be restarted and a <c>transient</c> child process - should be restarted only if it terminates abnormally, i.e. - with another exit reason than <c>normal</c>.</p> + never be restarted (even when the supervisor's restart strategy + is <c>rest_for_one</c> or <c>one_for_all</c> and a sibling's + death causes the temporary process to be terminated) and a + <c>transient</c> child process should be restarted only if + it terminates abnormally, i.e. with another exit reason + than <c>normal</c>.</p> </item> <item> <p><c>Shutdown</c> defines how a child process should be diff --git a/lib/stdlib/src/supervisor.erl b/lib/stdlib/src/supervisor.erl index 023183c5f0..36cc7f4f4b 100644 --- a/lib/stdlib/src/supervisor.erl +++ b/lib/stdlib/src/supervisor.erl @@ -738,6 +738,13 @@ restart(one_for_all, Child, State) -> terminate_children(Children, SupName) -> terminate_children(Children, SupName, []). +%% Temporary children should not be restarted and thus should +%% be skipped when building the list of terminated children, although +%% we do want them to be shut down as many functions from this module +%% use this function to just clear everything. +terminate_children([Child = #child{restart_type=temporary} | Children], SupName, Res) -> + do_terminate(Child, SupName), + terminate_children(Children, SupName, Res); terminate_children([Child | Children], SupName, Res) -> NChild = do_terminate(Child, SupName), terminate_children(Children, SupName, [NChild | Res]); diff --git a/lib/stdlib/test/supervisor_SUITE.erl b/lib/stdlib/test/supervisor_SUITE.erl index 7a75114cb6..2aa3131aeb 100644 --- a/lib/stdlib/test/supervisor_SUITE.erl +++ b/lib/stdlib/test/supervisor_SUITE.erl @@ -44,7 +44,7 @@ permanent_shutdown/1, transient_shutdown/1, temporary_shutdown/1, permanent_abnormal/1, transient_abnormal/1, - temporary_abnormal/1]). + temporary_abnormal/1, temporary_bystander/1]). %% Restart strategy tests -export([ one_for_one/1, @@ -77,7 +77,7 @@ all() -> {group, abnormal_termination}, child_unlink, tree, count_children_memory, do_not_save_start_parameters_for_temporary_children, do_not_save_child_specs_for_temporary_children, - simple_one_for_one_scale_many_temporary_children]. + simple_one_for_one_scale_many_temporary_children, temporary_bystander]. groups() -> [{sup_start, [], @@ -693,6 +693,37 @@ temporary_abnormal(Config) when is_list(Config) -> [0,0,0,0] = get_child_counts(sup_test). %%------------------------------------------------------------------------- +temporary_bystander(doc) -> + ["A temporary process killed as part of a rest_for_one or one_for_all " + "restart strategy should not be restarted given its args are not " + " saved. Otherwise the supervisor hits its limit and crashes."]; +temporary_bystander(suite) -> []; +temporary_bystander(_Config) -> + Child1 = {child1, {supervisor_1, start_child, []}, permanent, 100, + worker, []}, + Child2 = {child2, {supervisor_1, start_child, []}, temporary, 100, + worker, []}, + {ok, SupPid1} = supervisor:start_link(?MODULE, {ok, {{one_for_all, 2, 300}, []}}), + {ok, SupPid2} = supervisor:start_link(?MODULE, {ok, {{rest_for_one, 2, 300}, []}}), + unlink(SupPid1), % otherwise we crash with it + unlink(SupPid2), % otherwise we crash with it + {ok, CPid1} = supervisor:start_child(SupPid1, Child1), + {ok, _CPid2} = supervisor:start_child(SupPid1, Child2), + {ok, CPid3} = supervisor:start_child(SupPid2, Child1), + {ok, _CPid4} = supervisor:start_child(SupPid2, Child2), + terminate(SupPid1, CPid1, child1, normal), + terminate(SupPid2, CPid3, child1, normal), + timer:sleep(350), + catch link(SupPid1), + catch link(SupPid2), + %% The supervisor would die attempting to restart child2 + true = erlang:is_process_alive(SupPid1), + true = erlang:is_process_alive(SupPid2), + %% Child2 has not been restarted + [{child1, _, _, _}] = supervisor:which_children(SupPid1), + [{child1, _, _, _}] = supervisor:which_children(SupPid2). + +%%------------------------------------------------------------------------- one_for_one(doc) -> ["Test the one_for_one base case."]; one_for_one(suite) -> []; diff --git a/lib/tools/emacs/erlang.el b/lib/tools/emacs/erlang.el index 6728bef2a4..a8dd3ec3ac 100644 --- a/lib/tools/emacs/erlang.el +++ b/lib/tools/emacs/erlang.el @@ -523,6 +523,32 @@ This is an elisp list of options. Each option can be either: - a string Example: '(bin_opt_info (i . \"/path1/include\") (i . \"/path2/include\"))") +(defvar erlang-compile-command-function-alist + '((".erl\\'" . inferior-erlang-compute-erl-compile-command) + (".xrl\\'" . inferior-erlang-compute-leex-compile-command) + (".yrl\\'" . inferior-erlang-compute-yecc-compile-command) + ("." . inferior-erlang-compute-erl-compile-command)) + "*Alist of filename patterns vs corresponding compilation functions. +Each element looks like (REGEXP . FUNCTION). Compiling a file whose name +matches REGEXP specifies FUNCTION to use to compute the compilation +command. The FUNCTION will be called with two arguments: module name and +default compilation options, like output directory. The FUNCTION +is expected to return a string.") + +(defvar erlang-leex-compile-opts '() + "*Options to pass to leex when compiling xrl files. +This is an elisp list of options. Each option can be either: +- an atom +- a dotted pair +- a string") + +(defvar erlang-yecc-compile-opts '() + "*Options to pass to yecc when compiling yrl files. +This is an elisp list of options. Each option can be either: +- an atom +- a dotted pair +- a string") + (eval-and-compile (defvar erlang-regexp-modern-p (if (> erlang-emacs-major-version 21) t nil) @@ -5276,6 +5302,22 @@ unless the optional NO-DISPLAY is non-nil." (file-name-as-directory buffer-dir)))) (defun inferior-erlang-compute-compile-command (module-name opts) + (let ((ccfn erlang-compile-command-function-alist) + (res (inferior-erlang-compute-erl-compile-command module-name opts)) + ccfn-entry + done) + (if (not (null (buffer-file-name))) + (while (and (not done) (not (null ccfn))) + (setq ccfn-entry (car ccfn)) + (setq ccfn (cdr ccfn)) + (if (string-match (car ccfn-entry) (buffer-file-name)) + (let ((c-fn (cdr ccfn-entry))) + (setq done t) + (if (not (null c-fn)) + (setq result (funcall c-fn module-name opts))))))) + result)) + +(defun inferior-erlang-compute-erl-compile-command (module-name opts) (let* ((out-dir-opt (assoc 'outdir opts)) (out-dir (cdr out-dir-opt))) (if erlang-compile-use-outdir @@ -5299,6 +5341,48 @@ unless the optional NO-DISPLAY is non-nil." (remq out-dir-opt opts)) tmpvar tmpvar tmpvar2))))) +(defun inferior-erlang-compute-leex-compile-command (module-name opts) + (let ((file-name (buffer-file-name)) + (erl-compile-expr (inferior-erlang-remove-any-trailing-dot + (inferior-erlang-compute-erl-compile-command + module-name opts)))) + (format (concat "f(LErr1__), f(LErr2__), " + "case case leex:file(\"%s\", [%s]) of" + " ok -> ok;" + " {ok,_} -> ok;" + " {ok,_,_} -> ok;" + " LErr1__ -> LErr1__ " + "end of" + " ok -> %s;" + " LErr2__ -> LErr2__ " + "end.") + file-name + (inferior-erlang-format-comma-opts erlang-leex-compile-opts) + erl-compile-expr))) + +(defun inferior-erlang-compute-yecc-compile-command (module-name opts) + (let ((file-name (buffer-file-name)) + (erl-compile-expr (inferior-erlang-remove-any-trailing-dot + (inferior-erlang-compute-erl-compile-command + module-name opts)))) + (format (concat "f(YErr1__), f(YErr2__), " + "case case yecc:file(\"%s\", [%s]) of" + " {ok,_} -> ok;" + " {ok,_,_} -> ok;" + " YErr1__ -> YErr1__ " + "end of" + " ok -> %s;" + " YErr2__ -> YErr2__ " + "end.") + file-name + (inferior-erlang-format-comma-opts erlang-yecc-compile-opts) + erl-compile-expr))) + +(defun inferior-erlang-remove-any-trailing-dot (str) + (if (string= (substring str -1) ".") + (substring str 0 (1- (length str))) + str)) + (defun inferior-erlang-format-comma-opts (opts) (if (null opts) "" diff --git a/system/doc/reference_manual/distributed.xml b/system/doc/reference_manual/distributed.xml index 52222c6d9d..9c8e88250c 100644 --- a/system/doc/reference_manual/distributed.xml +++ b/system/doc/reference_manual/distributed.xml @@ -78,7 +78,7 @@ dilbert@uab</pre> using the command line flag <c>-connect_all false</c>, see <c>erl(1)</c>.</p> <p>If a node goes down, all connections to that node are removed. - Calling <c>erlang:disconnect(Node)</c> will force disconnection + Calling <c>erlang:disconnect_node(Node)</c> will force disconnection of a node.</p> <p>The list of (visible) nodes currently connected to is returned by <c>nodes()</c>.</p> |