Permalink
Browse files

Fix for typespec in OTP 19

  • Loading branch information...
1 parent 908a24f commit b572c398189072d7fcb59d393a0763200a15c65d silviu committed Jun 23, 2016
Showing with 43 additions and 43 deletions.
  1. +7 −7 src/hamcrest.erl
  2. +36 −36 src/hamcrest_matchers.erl
View
@@ -56,27 +56,27 @@
%% @doc Returns `true' if the specified term is a valid hamcrest matcher,
%% otherwise `false'.
--spec(is_matcher/1 :: (any()) -> boolean()).
+-spec(is_matcher(any()) -> boolean()).
is_matcher(Something) ->
erlang:is_record(Something, 'hamcrest.matchspec').
--spec(match/2 :: (term(), matchspec()) -> boolean()).
+-spec(match(term(), matchspec()) -> boolean()).
match(Value, MatchSpec) ->
match(Value, MatchSpec, fun() -> ok end).
--spec(match/3 :: (term(), matchspec(),
+-spec(match(term(), matchspec(),
fun(() -> any())) -> boolean()).
match(Value, MatchSpec, RunAfter) ->
(catch assert_that(Value, MatchSpec, RunAfter)) == true.
--spec(assert_that/3 :: (term(), matchspec(),
+-spec(assert_that(term(), matchspec(),
fun(() -> any())) -> 'true' | no_return()).
assert_that(Value, MatchSpec, RunAfter) when is_function(RunAfter, 0) ->
try assert_that(Value, MatchSpec)
after RunAfter()
end.
--spec(assert_that/2 :: (term(), matchspec()) -> 'true' | no_return()).
+-spec(assert_that(term(), matchspec()) -> 'true' | no_return()).
assert_that(Value, MatchSpec) ->
case check(Value, MatchSpec) of
{assertion_failed, _}=Failure ->
@@ -87,7 +87,7 @@ assert_that(Value, MatchSpec) ->
exit({what_the, Other})
end.
--spec(check/2 :: (term(), matchspec()) -> 'true' | {assertion_failed, term()}).
+-spec(check(term(), matchspec()) -> 'true' | {assertion_failed, term()}).
check(Value, #'hamcrest.matchspec'{ matcher=MatchFunc }=MatchSpec) ->
heckle(MatchSpec, Value),
try MatchFunc(Value) of
@@ -105,7 +105,7 @@ check(Value, #'hamcrest.matchspec'{ matcher=MatchFunc }=MatchSpec) ->
{assertion_failed, describe(MatchSpec, {Class, Reason})}
end.
--spec(heckle/2 :: (matchspec(), any()) -> any()).
+-spec(heckle(matchspec(), any()) -> any()).
heckle(MatchSpec, Actual) ->
case application:get_env(hamcrest, heckle) of
{ok, [M,F,A]} ->
@@ -81,7 +81,7 @@
%%% API
%%%============================================================================
--spec(will_fail/0 :: () -> hamcrest:matchspec()).
+-spec(will_fail() -> hamcrest:matchspec()).
will_fail() ->
%% Matcher :: fun((fun(() -> any())) -> boolean())
Matcher = fun(F) ->
@@ -95,7 +95,7 @@ will_fail() ->
expected = {oneof,{exit,error,exception}}
}.
--spec(will_fail/2 :: (atom(), term()) -> hamcrest:matchspec()).
+-spec(will_fail(atom(), term()) -> hamcrest:matchspec()).
will_fail(Type, Reason) ->
%% Matcher :: fun((fun(() -> any())) -> boolean())
Matcher = fun(F) ->
@@ -109,11 +109,11 @@ will_fail(Type, Reason) ->
expected = {Type, Reason}
}.
--spec(anything/0 :: () -> hamcrest:matchspec()).
+-spec(anything() -> hamcrest:matchspec()).
anything() ->
?MATCHER(fun(_) -> true end, any, anything).
--spec(foreach/1 :: (hamcrest:matchspec()) -> hamcrest:matchspec()).
+-spec(foreach(hamcrest:matchspec()) -> hamcrest:matchspec()).
foreach(M) when is_record(M, 'hamcrest.matchspec') ->
?MATCHER(fun(L) -> drop_matches(M, L) == [] end, M,
{foreach, M#'hamcrest.matchspec'.desc}).
@@ -126,7 +126,7 @@ drop_matches(Match, []) ->
drop_matches(Match, L) ->
lists:dropwhile(fun(E) -> hamcrest:match(E, Match) end, L).
--spec(any_of/1 :: (list(matchfun(term()))) -> hamcrest:matchspec();
+-spec(any_of(list(matchfun(term()))) -> hamcrest:matchspec();
(list(hamcrest:matchspec())) -> hamcrest:matchspec()).
any_of(Matchers) when is_list(Matchers) ->
MatchFun =
@@ -155,72 +155,72 @@ all_of(Matchers) when is_list(Matchers) ->
expected = {all, Matchers}
}.
--spec(equal_to/1 :: (term()) -> hamcrest:matchspec()).
+-spec(equal_to(term()) -> hamcrest:matchspec()).
equal_to(Y) ->
#'hamcrest.matchspec'{
matcher = fun(X) -> X == Y end,
desc = equal_to,
expected = Y
}.
--spec(exactly_equal_to/1 :: (term()) -> hamcrest:matchspec()).
+-spec(exactly_equal_to(term()) -> hamcrest:matchspec()).
exactly_equal_to(X) ->
#'hamcrest.matchspec'{
matcher = fun(Y) -> X =:= Y end,
desc = exactly_equal_to,
expected = X
}.
--spec(is/1 :: (matchfun(term())) -> hamcrest:matchspec();
- (hamcrest:matchspec()) -> hamcrest:matchspec();
- (any()) -> hamcrest:matchspec()).
+-spec(is(matchfun(term())) -> hamcrest:matchspec();
+ (hamcrest:matchspec()) -> hamcrest:matchspec();
+ (any()) -> hamcrest:matchspec()).
is(Matcher) when is_record(Matcher, 'hamcrest.matchspec') ->
Matcher;
is(Term) ->
equal_to(Term).
--spec(is_true/0 :: () -> hamcrest:matchspec()).
+-spec(is_true() -> hamcrest:matchspec()).
is_true() ->
equal_to(true).
--spec(is_false/0 :: () -> hamcrest:matchspec()).
+-spec(is_false() -> hamcrest:matchspec()).
is_false() ->
is_not(equal_to(true)).
--spec(is_not/1 :: (matchfun(term())) -> hamcrest:matchspec();
- (hamcrest:matchspec()) -> hamcrest:matchspec();
- (term()) -> hamcrest:matchspec()).
+-spec(is_not(matchfun(term())) -> hamcrest:matchspec();
+ (hamcrest:matchspec()) -> hamcrest:matchspec();
+ (term()) -> hamcrest:matchspec()).
is_not(#'hamcrest.matchspec'{ matcher=MatchFun }=MatchSpec)
when is_record(MatchSpec, 'hamcrest.matchspec') ->
MatchSpec#'hamcrest.matchspec'{ matcher = (fun(X) -> not(MatchFun(X)) end) };
is_not(Term) ->
is_not(equal_to(Term)).
--spec(greater_than/1 :: (number()) -> hamcrest:matchspec()).
+-spec(greater_than(number()) -> hamcrest:matchspec()).
greater_than(X) ->
#'hamcrest.matchspec'{
matcher = fun(Y) -> Y > X end,
desc = greater_than,
expected = X
}.
--spec(greater_than_or_equal_to/1 :: (number()) -> hamcrest:matchspec()).
+-spec(greater_than_or_equal_to(number()) -> hamcrest:matchspec()).
greater_than_or_equal_to(X) ->
#'hamcrest.matchspec'{
matcher = fun(Y) -> Y >= X end,
desc = greater_than_or_equal_to,
expected = X
}.
--spec(less_than/1 :: (number()) -> hamcrest:matchspec()).
+-spec(less_than(number()) -> hamcrest:matchspec()).
less_than(X) ->
#'hamcrest.matchspec'{
matcher = fun(Y) -> Y < X end,
desc = less_than,
expected = X
}.
--spec(less_than_or_equal_to/1 :: (number()) -> hamcrest:matchspec()).
+-spec(less_than_or_equal_to(number()) -> hamcrest:matchspec()).
less_than_or_equal_to(X) ->
#'hamcrest.matchspec'{
matcher = fun(Y) -> Y =< X end,
@@ -230,20 +230,20 @@ less_than_or_equal_to(X) ->
%% fun((string()) -> boolean()) matchers...
--spec(contains_string/1 :: (string()) -> hamcrest:matchspec()).
+-spec(contains_string(string()) -> hamcrest:matchspec()).
contains_string([_|_]=X) ->
?MATCHER(fun(Y) -> string:str(Y, X) > 0 end, X, {contains_string, X}).
--spec(starts_with/1 :: (string()) -> hamcrest:matchspec()).
+-spec(starts_with(string()) -> hamcrest:matchspec()).
starts_with(X) ->
?MATCHER(fun(Y) -> string:str(Y, X) == 1 end, X, {starts_with, X}).
--spec(ends_with/1 :: (string()) -> hamcrest:matchspec()).
+-spec(ends_with(string()) -> hamcrest:matchspec()).
ends_with(X) ->
?MATCHER(fun(Y) -> string:equal(string:right(Y, length(X)), X) end,
X, {ends_with, X}).
--spec(matches_regex/1 :: (string()) -> hamcrest:matchspec()).
+-spec(matches_regex(string()) -> hamcrest:matchspec()).
matches_regex(Rx) ->
#'hamcrest.matchspec'{
matcher =
@@ -257,59 +257,59 @@ matches_regex(Rx) ->
expected = Rx
}.
--spec(match_mfa/3 :: (module(), atom(), list(term())) -> hamcrest:matchspec()).
+-spec(match_mfa(module(), atom(), list(term())) -> hamcrest:matchspec()).
match_mfa(Mod, Func, Args) ->
#'hamcrest.matchspec'{
matcher = fun(X) -> catch(apply(Mod, Func, Args ++ [X])) == true end,
desc = {eval, [Mod, Func, Args]},
expected = true
}.
--spec(match_mfa/4 :: (module(), atom(),
- list(term()), term()) -> hamcrest:matchspec()).
+-spec(match_mfa(module(), atom(),
+ list(term()), term()) -> hamcrest:matchspec()).
match_mfa(Mod, Func, Args, Desc) ->
MS = match_mfa(Mod, Func, Args),
MS#'hamcrest.matchspec'{desc=Desc}.
--spec(reverse_match_mfa/3 :: (module(), atom(),
- list(term())) -> hamcrest:matchspec()).
+-spec(reverse_match_mfa(module(), atom(),
+ list(term())) -> hamcrest:matchspec()).
reverse_match_mfa(Mod, Func, Args) when is_list(Args) ->
#'hamcrest.matchspec'{
matcher = fun(X) -> catch(apply(Mod, Func, [X|Args])) == true end,
desc = {eval, [Mod, Func, lists:reverse(Args)]},
expected = true
}.
--spec(reverse_match_mfa/4 :: (module(), atom(),
- list(term()), term()) -> hamcrest:matchspec()).
+-spec(reverse_match_mfa(module(), atom(),
+ list(term()), term()) -> hamcrest:matchspec()).
reverse_match_mfa(Mod, Func, Args, Desc) ->
MS = reverse_match_mfa(Mod, Func, Args),
MS#'hamcrest.matchspec'{desc=Desc}.
--spec(isalive/0 :: () -> hamcrest:matchspec()).
+-spec(isalive() -> hamcrest:matchspec()).
isalive() ->
MS = match_mfa(erlang, is_process_alive, []),
MS#'hamcrest.matchspec'{desc=is_process_alive, expected=true}.
--spec(isdead/0 :: () -> hamcrest:matchspec()).
+-spec(isdead() -> hamcrest:matchspec()).
isdead() ->
#'hamcrest.matchspec'{
matcher = fun(X) -> not erlang:is_process_alive(X) end,
desc = is_process_alive,
expected = false
}.
--spec(has_length/1 :: (number()) -> hamcrest:matchspec()).
+-spec(has_length(number()) -> hamcrest:matchspec()).
has_length(Size) when is_number(Size) ->
?MATCHER(fun(XS) -> length(XS) == Size end,
Size, {length, Size}).
--spec(has_same_contents_as/1 :: (container_t()) -> hamcrest:matchspec()).
+-spec(has_same_contents_as(container_t()) -> hamcrest:matchspec()).
has_same_contents_as(Container) when is_list(Container) ->
MS = foreach(match_mfa(?MODULE, check_member, [Container])),
MS#'hamcrest.matchspec'{desc=has_same_contents_as, expected=Container}.
--spec(contains_member/1 :: (term()) -> hamcrest:matchspec()).
+-spec(contains_member(term()) -> hamcrest:matchspec()).
contains_member(E) ->
reverse_match_mfa(?MODULE, check_member, [E]).
@@ -337,7 +337,7 @@ check_member(Container, E) ->
end
end.
--spec(isempty/0 :: () -> hamcrest:matchspec()).
+-spec(isempty() -> hamcrest:matchspec()).
isempty() ->
match_mfa(?MODULE, check_isempty, []).

0 comments on commit b572c39

Please sign in to comment.