You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
946 B

  1. -module(crash_statem).
  2. %% we're only going to compile this on OTP 19+
  3. -ifdef(test_statem).
  4. -behaviour(gen_statem).
  5. -export([
  6. start/0,
  7. crash/0,
  8. handle_event/4
  9. ]).
  10. -export([terminate/3,code_change/4,init/1,callback_mode/0]).
  11. start() ->
  12. gen_statem:start({local,?MODULE}, ?MODULE, [], []).
  13. crash() ->
  14. gen_statem:call(?MODULE, boom).
  15. %% Mandatory callback functions
  16. terminate(_Reason, _State, _Data) -> ok.
  17. code_change(_Vsn, State, Data, _Extra) -> {ok,State,Data}.
  18. init([]) ->
  19. %% insert rant here about breaking changes in minor versions...
  20. case erlang:system_info(version) of
  21. "8.0" -> {callback_mode(),state1,undefined};
  22. _ -> {ok, state1, undefined}
  23. end.
  24. callback_mode() -> handle_event_function.
  25. %%% state callback(s)
  26. handle_event({call, _From}, state1, _Arg, Data) ->
  27. {next_state, state1, Data}.
  28. -else.
  29. -export([start/0, crash/0]).
  30. start() -> ok.
  31. crash() -> ok.
  32. -endif.