Skip to content

Instantly share code, notes, and snippets.

@andytill
Created September 9, 2015 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andytill/0da8b9b62261b37b4446 to your computer and use it in GitHub Desktop.
Save andytill/0da8b9b62261b37b4446 to your computer and use it in GitHub Desktop.
Erlang macro to run some eunit test code inside its own process and wait for that process to complete before returning. This is useful when testing resources which get cleaned up when the current process completes like ets tables.
%%% MACRO
-define(in_process(TestCode),
Self = self(),
spawn_link(
fun() ->
TestCode,
Self ! test_ok
end),
receive
test_ok -> ok
end
).
%%% USAGE
my_test() ->
?in_process(
begin
?assertEqual(
[3,2,1],
lists:reverse([1,2,3])
)
end).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment