Skip to content

Commit

Permalink
Get rid of pre-OTP 21 test code workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
paulo-ferraz-oliveira committed Feb 24, 2021
1 parent dae8efc commit f2ae8fe
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 26 deletions.
1 change: 0 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

{erl_opts, [
{lager_extra_sinks, ['__lager_test_sink']},
{platform_define, "^(19|20|21|22|23|24)", test_statem},
{platform_define, "^18", 'FUNCTION_NAME', unavailable},
{platform_define, "^18", 'FUNCTION_ARITY', 0},
debug_info,
Expand Down
9 changes: 0 additions & 9 deletions test/crash_statem.erl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-module(crash_statem).
%% we're only going to compile this on OTP 19+
-ifdef(test_statem).
-behaviour(gen_statem).

-export([
Expand Down Expand Up @@ -45,11 +44,3 @@ handle_event({call, _From}, timeout, _Arg, _Data) ->
{keep_state_and_data, [{state_timeout, 0, timeout}]};
handle_event({call, _From}, {stop, Reason}, state1, _Data) ->
{stop, Reason}.

-else.
-export([start/0, crash/0]).

start() -> ok.
crash() -> ok.

-endif.
24 changes: 8 additions & 16 deletions test/pr_stacktrace_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@

-compile([{parse_transform, lager_transform}]).

-ifdef(OTP_RELEASE). %% this implies 21 or higher
-define(EXCEPTION(Class, Reason, Stacktrace), Class:Reason:Stacktrace).
-define(GET_STACK(Stacktrace), Stacktrace).
-else.
-define(EXCEPTION(Class, Reason, _), Class:Reason).
-define(GET_STACK(_), erlang:get_stacktrace()).
-endif.

-include_lib("eunit/include/eunit.hrl").

make_throw() ->
Expand All @@ -25,8 +17,8 @@ pr_stacktrace_throw_test() ->
Got = try
make_throw()
catch
?EXCEPTION(Class, Reason, Stacktrace) ->
lager:pr_stacktrace(?GET_STACK(Stacktrace), {Class, Reason})
Class:Reason:Stacktrace ->
lager:pr_stacktrace(Stacktrace, {Class, Reason})
end,
Want = "pr_stacktrace_test:pr_stacktrace_throw_test/0 line 26\n pr_stacktrace_test:make_throw/0 line 16\nthrow:{test,exception}",
?assertNotEqual(nomatch, string:find(Got, Want)).
Expand All @@ -35,8 +27,8 @@ pr_stacktrace_bad_arg_test() ->
Got = try
bad_arg()
catch
?EXCEPTION(Class, Reason, Stacktrace) ->
lager:pr_stacktrace(?GET_STACK(Stacktrace), {Class, Reason})
Class:Reason:Stacktrace ->
lager:pr_stacktrace(Stacktrace, {Class, Reason})
end,
Want = "pr_stacktrace_test:pr_stacktrace_bad_arg_test/0 line 36\n pr_stacktrace_test:bad_arg/0 line 22\nerror:badarg",
?assertNotEqual(nomatch, string:find(Got, Want)).
Expand All @@ -45,8 +37,8 @@ pr_stacktrace_bad_arity_test() ->
Got = try
bad_arity()
catch
?EXCEPTION(Class, Reason, Stacktrace) ->
lager:pr_stacktrace(?GET_STACK(Stacktrace), {Class, Reason})
Class:Reason:Stacktrace ->
lager:pr_stacktrace(Stacktrace, {Class, Reason})
end,
Want = "pr_stacktrace_test:pr_stacktrace_bad_arity_test/0 line 46\n lists:concat([], [])\nerror:undef",
?assertNotEqual(nomatch, string:find(Got, Want)).
Expand All @@ -56,8 +48,8 @@ pr_stacktrace_no_reverse_test() ->
Got = try
bad_arity()
catch
?EXCEPTION(Class, Reason, Stacktrace) ->
lager:pr_stacktrace(?GET_STACK(Stacktrace), {Class, Reason})
Class:Reason:Stacktrace ->
lager:pr_stacktrace(Stacktrace, {Class, Reason})
end,
Want = "error:undef\n lists:concat([], [])\n pr_stacktrace_test:pr_stacktrace_bad_arity_test/0 line 57",
?assertEqual(nomatch, string:find(Got, Want)).

0 comments on commit f2ae8fe

Please sign in to comment.