aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-04-26 15:13:24 +0200
committerLoïc Hoguin <[email protected]>2013-04-26 15:13:24 +0200
commit9ccfbb66ef24c84f34b3248057fe461f751389d5 (patch)
treed42fbfacb7dfc05e4bdbfcc100e60452890e7e78 /src
parent5291c3eb0ac421994fb3046fc0fcd603b4ea2a64 (diff)
parent3bf5b46786136a004b4085098c9b46cd47295774 (diff)
downloadcowboy-9ccfbb66ef24c84f34b3248057fe461f751389d5.tar.gz
cowboy-9ccfbb66ef24c84f34b3248057fe461f751389d5.tar.bz2
cowboy-9ccfbb66ef24c84f34b3248057fe461f751389d5.zip
Merge branch 'remove_asserts' of git://github.com/Egobrain/cowboy
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_bstr.erl4
-rw-r--r--src/cowboy_clock.erl4
-rw-r--r--src/cowboy_http.erl79
-rw-r--r--src/cowboy_multipart.erl11
-rw-r--r--src/cowboy_req.erl40
-rw-r--r--src/cowboy_router.erl4
-rw-r--r--src/cowboy_static.erl2
7 files changed, 63 insertions, 81 deletions
diff --git a/src/cowboy_bstr.erl b/src/cowboy_bstr.erl
index 01ed9ae..0c1f66a 100644
--- a/src/cowboy_bstr.erl
+++ b/src/cowboy_bstr.erl
@@ -24,10 +24,6 @@
-export([char_to_lower/1]).
-export([char_to_upper/1]).
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
-
%% @doc Capitalize a token.
%%
%% The first letter and all letters after a dash are capitalized.
diff --git a/src/cowboy_clock.erl b/src/cowboy_clock.erl
index 71bcb21..f21616c 100644
--- a/src/cowboy_clock.erl
+++ b/src/cowboy_clock.erl
@@ -45,10 +45,6 @@
-define(SERVER, ?MODULE).
-define(TABLE, ?MODULE).
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
-
%% API.
%% @private
diff --git a/src/cowboy_http.erl b/src/cowboy_http.erl
index b958020..c4d3d3d 100644
--- a/src/cowboy_http.erl
+++ b/src/cowboy_http.erl
@@ -60,10 +60,6 @@
-export_type([headers/0]).
-export_type([status/0]).
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
-
%% Parsing.
%% @doc Parse a non-empty list of the given type.
@@ -1319,40 +1315,53 @@ x_www_form_urlencoded_test_() ->
[{Qs, fun() -> R = x_www_form_urlencoded(Qs) end} || {Qs, R} <- Tests].
urldecode_test_() ->
- U = fun urldecode/2,
- [?_assertEqual(<<" ">>, U(<<"%20">>, crash)),
- ?_assertEqual(<<" ">>, U(<<"+">>, crash)),
- ?_assertEqual(<<0>>, U(<<"%00">>, crash)),
- ?_assertEqual(<<255>>, U(<<"%fF">>, crash)),
- ?_assertEqual(<<"123">>, U(<<"123">>, crash)),
- ?_assertEqual(<<"%i5">>, U(<<"%i5">>, skip)),
- ?_assertEqual(<<"%5">>, U(<<"%5">>, skip)),
- ?_assertError(badarg, U(<<"%i5">>, crash)),
- ?_assertError(badarg, U(<<"%5">>, crash))
- ].
+ F = fun(Qs, O) ->
+ try urldecode(Qs, O) of
+ R ->
+ {ok, R}
+ catch _:E ->
+ {error, E}
+ end
+ end,
+ Tests = [
+ {<<"%20">>, crash, {ok, <<" ">>}},
+ {<<"+">>, crash, {ok, <<" ">>}},
+ {<<"%00">>, crash, {ok, <<0>>}},
+ {<<"%fF">>, crash, {ok, <<255>>}},
+ {<<"123">>, crash, {ok, <<"123">>}},
+ {<<"%i5">>, skip, {ok, <<"%i5">>}},
+ {<<"%5">>, skip, {ok, <<"%5">>}},
+ {<<"%i5">>, crash, {error, badarg}},
+ {<<"%5">>, crash, {error, badarg}}
+ ],
+ [{Qs, fun() -> R = F(Qs,O) end} || {Qs, O, R} <- Tests].
urlencode_test_() ->
- U = fun urlencode/2,
- [?_assertEqual(<<"%ff%00">>, U(<<255,0>>, [])),
- ?_assertEqual(<<"%FF%00">>, U(<<255,0>>, [upper])),
- ?_assertEqual(<<"+">>, U(<<" ">>, [])),
- ?_assertEqual(<<"%20">>, U(<<" ">>, [noplus])),
- ?_assertEqual(<<"aBc">>, U(<<"aBc">>, [])),
- ?_assertEqual(<<".-~_">>, U(<<".-~_">>, [])),
- ?_assertEqual(<<"%ff+">>, urlencode(<<255, " ">>))
- ].
+ Tests = [
+ {<<255,0>>, [], <<"%ff%00">>},
+ {<<255,0>>, [upper], <<"%FF%00">>},
+ {<<" ">>, [], <<"+">>},
+ {<<" ">>, [noplus], <<"%20">>},
+ {<<"aBc">>, [], <<"aBc">>},
+ {<<".-~_">>, [], <<".-~_">>}
+ ],
+ Tests2 = [{<<255, " ">>,<<"%ff+">>}],
+ [{V, fun() -> R = urlencode(V, O) end} || {V, O, R} <- Tests] ++
+ [{V, fun() -> R = urlencode(V) end} || {V, R} <- Tests2].
http_authorization_test_() ->
- [?_assertEqual({<<"basic">>, {<<"Alladin">>, <<"open sesame">>}},
- authorization(<<"QWxsYWRpbjpvcGVuIHNlc2FtZQ==">>, <<"basic">>)),
- ?_assertEqual({error, badarg},
- authorization(<<"dXNlcm5hbWUK">>, <<"basic">>)),
- ?_assertEqual({error, badarg},
- authorization(<<"_[]@#$%^&*()-AA==">>, <<"basic">>)),
- ?_assertEqual({error, badarg},
- authorization(<<"dXNlcjpwYXNzCA==">>, <<"basic">>)), %% user:pass\010
- ?_assertEqual({<<"bearer">>,<<"some_secret_key">>},
- authorization(<<" some_secret_key">>, <<"bearer">>))
- ].
+ Tests = [
+ {<<"basic">>, <<"QWxsYWRpbjpvcGVuIHNlc2FtZQ==">>,
+ {<<"basic">>, {<<"Alladin">>, <<"open sesame">>}}},
+ {<<"basic">>, <<"dXNlcm5hbWUK">>,
+ {error, badarg}},
+ {<<"basic">>, <<"_[]@#$%^&*()-AA==">>,
+ {error, badarg}},
+ {<<"basic">>, <<"dXNlcjpwYXNzCA==">>,
+ {error, badarg}},
+ {<<"bearer">>, <<" some_secret_key">>,
+ {<<"bearer">>,<<"some_secret_key">>}}
+ ],
+ [{V, fun() -> R = authorization(V,T) end} || {T, V, R} <- Tests].
-endif.
diff --git a/src/cowboy_multipart.erl b/src/cowboy_multipart.erl
index 4e8fff0..4df5a27 100644
--- a/src/cowboy_multipart.erl
+++ b/src/cowboy_multipart.erl
@@ -30,10 +30,6 @@
-type end_of_part() :: {end_of_part, cont(more(part_result()))}.
-type disposition() :: {binary(), [{binary(), binary()}]}.
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
-
%% API.
%% @doc Return a multipart parser for the given boundary.
@@ -298,8 +294,7 @@ title(Bin) ->
iolist_to_binary(Title).
suffix_test_() ->
- [?_assertEqual(Part, suffix_match(Packet, pattern(Boundary))) ||
- {Part, Packet, Boundary} <- [
+ Tests = [
{nomatch, <<>>, <<"ABC">>},
{{0, 1}, <<"\r">>, <<"ABC">>},
{{0, 2}, <<"\r\n">>, <<"ABC">>},
@@ -311,6 +306,8 @@ suffix_test_() ->
{{1, 1}, <<"1\r">>, <<"ABC">>},
{{2, 2}, <<"12\r\n">>, <<"ABC">>},
{{3, 4}, <<"123\r\n--">>, <<"ABC">>}
- ]].
+ ],
+ [fun() -> Part = suffix_match(Packet, pattern(Boundary)) end ||
+ {Part, Packet, Boundary} <- Tests].
-endif.
diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl
index 11b0e26..552048a 100644
--- a/src/cowboy_req.erl
+++ b/src/cowboy_req.erl
@@ -115,10 +115,6 @@
-export([lock/1]).
-export([to_list/1]).
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
-
-type cookie_option() :: {max_age, non_neg_integer()}
| {domain, binary()} | {path, binary()}
| {secure, boolean()} | {http_only, boolean()}.
@@ -1471,26 +1467,20 @@ connection_to_atom_test_() ->
[{lists:flatten(io_lib:format("~p", [T])),
fun() -> R = connection_to_atom(T) end} || {T, R} <- Tests].
-merge_headers_test() ->
- Left0 = [{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
- Right0 = [{<<"set-cookie">>,<<"foo=bar">>},{<<"content-length">>,<<"11">>}],
-
- ?assertMatch(
- [{<<"set-cookie">>,<<"foo=bar">>},
- {<<"content-length">>,<<"13">>},
- {<<"server">>,<<"Cowboy">>}],
- merge_headers(Left0, Right0)),
-
- Left1 = [{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
- Right1 = [{<<"set-cookie">>,<<"foo=bar">>},{<<"set-cookie">>,<<"bar=baz">>}],
-
- ?assertMatch(
- [{<<"set-cookie">>,<<"bar=baz">>},
- {<<"set-cookie">>,<<"foo=bar">>},
- {<<"content-length">>,<<"13">>},
- {<<"server">>,<<"Cowboy">>}],
- merge_headers(Left1, Right1)),
-
- ok.
+merge_headers_test_() ->
+ Tests = [
+ {[{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
+ [{<<"set-cookie">>,<<"foo=bar">>},{<<"content-length">>,<<"11">>}],
+ [{<<"set-cookie">>,<<"foo=bar">>},
+ {<<"content-length">>,<<"13">>},
+ {<<"server">>,<<"Cowboy">>}]},
+ {[{<<"content-length">>,<<"13">>},{<<"server">>,<<"Cowboy">>}],
+ [{<<"set-cookie">>,<<"foo=bar">>},{<<"set-cookie">>,<<"bar=baz">>}],
+ [{<<"set-cookie">>,<<"bar=baz">>},
+ {<<"set-cookie">>,<<"foo=bar">>},
+ {<<"content-length">>,<<"13">>},
+ {<<"server">>,<<"Cowboy">>}]}
+ ],
+ [fun() -> Res = merge_headers(L,R) end || {L, R, Res} <- Tests].
-endif.
diff --git a/src/cowboy_router.erl b/src/cowboy_router.erl
index 91912d8..e52b70b 100644
--- a/src/cowboy_router.erl
+++ b/src/cowboy_router.erl
@@ -51,10 +51,6 @@
-opaque dispatch_rules() :: [dispatch_rule()].
-export_type([dispatch_rules/0]).
--ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--endif.
-
%% @doc Compile a list of routes into the dispatch format used
%% by Cowboy's routing.
-spec compile(routes()) -> dispatch_rules().
diff --git a/src/cowboy_static.erl b/src/cowboy_static.erl
index ae0f9e6..fd5654e 100644
--- a/src/cowboy_static.erl
+++ b/src/cowboy_static.erl
@@ -422,8 +422,6 @@ attr_etag_function(Args, Attrs) ->
{strong, list_to_binary([H|T])}.
-ifdef(TEST).
--include_lib("eunit/include/eunit.hrl").
--define(_eq(E, I), ?_assertEqual(E, I)).
directory_path_test_() ->
PL = fun(D) -> length(filename:split(directory_path(D))) end,