From 4c747daecf8bfd22dafaf0e0d649ad02ec813f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Fri, 26 Aug 2011 14:43:27 +0200 Subject: test_server: Show line number for caller of test_server:fail() Showing the line number of fail/{1,2} in the test_server module is not especially useful. --- lib/test_server/src/test_server.erl | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/test_server/src/test_server.erl b/lib/test_server/src/test_server.erl index 04f92c5738..2cb33a9a69 100644 --- a/lib/test_server/src/test_server.erl +++ b/lib/test_server/src/test_server.erl @@ -1716,7 +1716,16 @@ adjusted_sleep(MSecs) -> %% to read when using this function, rather than exit directly. fail(Reason) -> comment(cast_to_list(Reason)), - exit({suite_failed,Reason}). + try + exit({suite_failed,Reason}) + catch + Class:R -> + case erlang:get_stacktrace() of + [{?MODULE,fail,1,_}|Stk] -> ok; + Stk -> ok + end, + erlang:raise(Class, R, Stk) + end. cast_to_list(X) when is_list(X) -> X; cast_to_list(X) when is_atom(X) -> atom_to_list(X); @@ -1730,7 +1739,16 @@ cast_to_list(X) -> lists:flatten(io_lib:format("~p", [X])). %% Immediately calls exit. Included because test suites are easier %% to read when using this function, rather than exit directly. fail() -> - exit(suite_failed). + try + exit(suite_failed) + catch + Class:R -> + case erlang:get_stacktrace() of + [{?MODULE,fail,0,_}|Stk] -> ok; + Stk -> ok + end, + erlang:raise(Class, R, Stk) + end. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% break(Comment) -> ok -- cgit v1.2.3 From c5eb04243f480d860626e955c1d6b82b938cdf02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 13 Sep 2011 09:49:49 +0200 Subject: beam_lib_SUITE: Don't assume that "Abst" is the last chunk "Line" is now the last chunk in a BEAM file, causing beam_lib_SUITE:error/1 to fail. To avoid being bitten by this problem again, don't simply change "Abst" to "Line", but use beam_lib:info/1 to find out the name of the last chunk. --- lib/stdlib/test/beam_lib_SUITE.erl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/stdlib/test/beam_lib_SUITE.erl b/lib/stdlib/test/beam_lib_SUITE.erl index b7fb1f618f..1788dcc85e 100644 --- a/lib/stdlib/test/beam_lib_SUITE.erl +++ b/lib/stdlib/test/beam_lib_SUITE.erl @@ -181,7 +181,8 @@ error(Conf) when is_list(Conf) -> ?line verify(not_a_beam_file, beam_lib:info(<<"short">>)), ?line {Binary1, _} = split_binary(Binary, byte_size(Binary)-10), - ?line verify(chunk_too_big, beam_lib:chunks(Binary1, ["Abst"])), + LastChunk = last_chunk(Binary), + ?line verify(chunk_too_big, beam_lib:chunks(Binary1, [LastChunk])), ?line Chunks = chunk_info(Binary), ?line {value, {_, AbstractStart, _}} = lists:keysearch("Abst", 1, Chunks), ?line {Binary2, _} = split_binary(Binary, AbstractStart), @@ -205,6 +206,12 @@ error(Conf) when is_list(Conf) -> ?line file:delete(ACopy), ok. +last_chunk(Bin) -> + L = beam_lib:info(Bin), + {chunks,Chunks} = lists:keyfind(chunks, 1, L), + {Last,_,_} = lists:last(Chunks), + Last. + do_error(BeamFile, ACopy) -> % evil tests ?line Chunks = chunk_info(BeamFile), -- cgit v1.2.3