Skip to content

Commit

Permalink
Slightly better instantiable test tests, added some helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Jun 24, 2010
1 parent 60ae615 commit 71142c0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/epitest.hrl
@@ -1,7 +1,7 @@
-define(EUNIT_NOAUTO, 1).
-include_lib("eunit/include/eunit.hrl").
-ifndef(NO_AUTOIMPORT).
-import(epitest_helpers, [ok/0, pending/0, pending/1, make_pending/0, make_pending/1, fail/0, fail/1, pass/3, retr/2, instantiate/1]).
-import(epitest_helpers, [ok/0, pending/0, pending/1, make_pending/0, make_pending/1, fail/0, fail/1, pass/3, retr/2, instantiate/1, loc/1, signature/1, instantiate_signature/2]).
-endif.

-record(epistate, {
Expand Down
15 changes: 14 additions & 1 deletion src/epitest_helpers.erl
@@ -1,7 +1,7 @@
-module(epitest_helpers).
-define(NO_AUTOIMPORT, 1).
-include_lib("epitest/include/epitest.hrl").
-export([ok/0, pending/0, pending/1, make_pending/0, make_pending/1, fail/0, fail/1, pass/3, retr/2, instantiate/1]).
-export([ok/0, pending/0, pending/1, make_pending/0, make_pending/1, fail/0, fail/1, pass/3, retr/2, instantiate/1, loc/1, signature/1, instantiate_signature/2]).

ok() ->
fun () ->
Expand Down Expand Up @@ -41,3 +41,16 @@ retr(Name, #epistate{ id = ID, test_plan = Plan }) ->

instantiate(Test) ->
{'Instantiate', Test}.

instantiate_signature(S, Loc) when is_list(S) ->
lists:concat([S, " <- ", lists:flatten(io_lib:format("instantiated by ~p",[Loc]))]);
instantiate_signature({S, P}, Loc) when is_list(S) ->
{instantiate_signature(S, Loc), P}.

loc(#epistate{ test = Test }) ->
#test{ loc = Loc } = Test,
Loc.

signature(#epistate{ test = Test }) ->
#test{ signature = Signature } = Test,
Signature.
7 changes: 1 addition & 6 deletions src/epitest_mod_require.erl
Expand Up @@ -162,7 +162,7 @@ load_references([], _Loc) ->

query_references({'Instantiate', Ref}, Loc) ->
lists:map(fun (#test{ loc = TLoc, signature = Signature, descriptor = Descriptor}) ->
{ok, ID} = epitest_test_server:add(TLoc, instantiate_signature(Signature, lists:flatten(io_lib:format("instantiated by ~p",[Loc]))), filter_instantiable(Descriptor)),
{ok, ID} = epitest_test_server:add(TLoc, instantiate_signature(Signature, Loc), filter_instantiable(Descriptor)),
epitest_test_server:lookup(ID)
end,
query_references(Ref, Loc));
Expand Down Expand Up @@ -194,11 +194,6 @@ query_references({Module, Title, Args}, {module, {_Module0, _}, _Line0}) when is
query_references({Module, Title}, _Loc) when is_atom(Module) ->
?REFERENCE_QUERY(#test{ loc = {module, {Module, _}, _Line}, signature = Title}).

instantiate_signature(S, ID) when is_list(S) ->
lists:concat([S, " <- ", ID]);
instantiate_signature({S, P}, ID) when is_list(S) ->
{lists:concat([S, " <- ", ID]), P}.

filter_instantiable([instantiable|T]) ->
filter_instantiable(T);
filter_instantiable([hidden|T]) ->
Expand Down
12 changes: 6 additions & 6 deletions t/selftest.erl
Expand Up @@ -35,22 +35,22 @@ test("Require parametrized test with full module name") ->

%% Instantiation

test("Instantiatable test") ->
test("Instantiable test") ->
[instantiable,
fun (State) ->
pass(instantiated, true, State)
pass(instantiated, signature(State), State)
end];

test("Instantiation test #1") ->
[{require, [{success, [instantiate("Instantiatable test")]}]},
[{require, [{success, [instantiate("Instantiable test")]}]},
fun (State) ->
?assertEqual(true, retr(instantiated, State))
?assertEqual(instantiate_signature("Instantiable test",loc(State)), retr(instantiated, State))
end];

test("Instantiation test #2") ->
[{require, [{success, [instantiate("Instantiatable test")]}]},
[{require, [{success, [instantiate("Instantiable test")]}]},
fun (State) ->
?assertEqual(true, retr(instantiated, State))
?assertEqual(instantiate_signature("Instantiable test",loc(State)), retr(instantiated, State))
end];

%% Negative tests
Expand Down

0 comments on commit 71142c0

Please sign in to comment.