Created
September 9, 2015 09:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% 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