diff options
author | Loïc Hoguin <[email protected]> | 2018-10-31 10:50:57 +0100 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2018-10-31 10:50:57 +0100 |
commit | a8335c63df31f21d88e9d7d1f2b64d32a674cd7a (patch) | |
tree | 2c8adc564263b49621ed969e0e08976258a35ffa | |
parent | 07078eb47bfc2a774e4ce00d2a215c301f4f4ea7 (diff) | |
download | cowboy-a8335c63df31f21d88e9d7d1f2b64d32a674cd7a.tar.gz cowboy-a8335c63df31f21d88e9d7d1f2b64d32a674cd7a.tar.bz2 cowboy-a8335c63df31f21d88e9d7d1f2b64d32a674cd7a.zip |
Always dialyze tests and fix some cowboy_req specs
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/cowboy_req.erl | 6 | ||||
-rw-r--r-- | src/cowboy_websocket.erl | 2 | ||||
-rw-r--r-- | test/handlers/resp_h.erl | 4 | ||||
-rw-r--r-- | test/handlers/resp_iolist_body_h.erl | 2 | ||||
-rw-r--r-- | test/handlers/stream_handler_h.erl | 1 | ||||
-rw-r--r-- | test/handlers/switch_protocol_flush_h.erl | 2 | ||||
-rw-r--r-- | test/handlers/ws_terminate_h.erl | 3 | ||||
-rw-r--r-- | test/old_http_SUITE.erl | 8 | ||||
-rw-r--r-- | test/old_http_SUITE_data/http_errors.erl | 2 | ||||
-rw-r--r-- | test/static_handler_SUITE.erl | 4 |
11 files changed, 25 insertions, 11 deletions
@@ -49,7 +49,7 @@ app:: rebar.config # Dialyze the tests. -# DIALYZER_OPTS += --src -r test +DIALYZER_OPTS += --src -r test # h2spec setup. diff --git a/src/cowboy_req.erl b/src/cowboy_req.erl index 2857c75..dad923f 100644 --- a/src/cowboy_req.erl +++ b/src/cowboy_req.erl @@ -535,13 +535,13 @@ read_and_match_urlencoded_body(Fields, Req0, Opts) -> %% Multipart. -spec read_part(Req) - -> {ok, cow_multipart:headers(), Req} | {done, Req} + -> {ok, cowboy:http_headers(), Req} | {done, Req} when Req::req(). read_part(Req) -> read_part(Req, #{length => 64000, period => 5000}). -spec read_part(Req, read_body_opts()) - -> {ok, #{binary() => binary()}, Req} | {done, Req} + -> {ok, cowboy:http_headers(), Req} | {done, Req} when Req::req(). read_part(Req, Opts) -> case maps:is_key(multipart, Req) of @@ -822,7 +822,7 @@ stream_trailers(Trailers, #{pid := Pid, streamid := StreamID, has_sent_resp := h Pid ! {{Pid, StreamID}, {trailers, Trailers}}, ok. --spec push(binary(), cowboy:http_headers(), req()) -> ok. +-spec push(iodata(), cowboy:http_headers(), req()) -> ok. push(Path, Headers, Req) -> push(Path, Headers, Req, #{}). diff --git a/src/cowboy_websocket.erl b/src/cowboy_websocket.erl index 0e88fc4..913c116 100644 --- a/src/cowboy_websocket.erl +++ b/src/cowboy_websocket.erl @@ -31,7 +31,7 @@ -export([system_terminate/4]). -export([system_code_change/4]). --type commands() :: [cow_ws:frame()]. +-type commands() :: [cow_ws:frame() | {active, boolean()}]. -export_type([commands/0]). -type call_result(State) :: {commands(), State} | {commands(), State, hibernate}. diff --git a/test/handlers/resp_h.erl b/test/handlers/resp_h.erl index 625a2ea..bfcb95c 100644 --- a/test/handlers/resp_h.erl +++ b/test/handlers/resp_h.erl @@ -2,6 +2,10 @@ -module(resp_h). +%% @todo Probably should have a separate handler for errors, +%% so that we can dialyze all the other correct calls. +-dialyzer({nowarn_function, do/3}). + -export([init/2]). init(Req, Opts) -> diff --git a/test/handlers/resp_iolist_body_h.erl b/test/handlers/resp_iolist_body_h.erl index 938f561..d8989b5 100644 --- a/test/handlers/resp_iolist_body_h.erl +++ b/test/handlers/resp_iolist_body_h.erl @@ -2,6 +2,8 @@ -module(resp_iolist_body_h). +-dialyzer(no_improper_lists). + -export([init/2]). init(Req0, State) -> diff --git a/test/handlers/stream_handler_h.erl b/test/handlers/stream_handler_h.erl index 0f245c6..2196be3 100644 --- a/test/handlers/stream_handler_h.erl +++ b/test/handlers/stream_handler_h.erl @@ -107,6 +107,7 @@ early_error(StreamID, Reason, PartialReq, Resp, Opts) -> end. %% @todo It would be good if we could allow this function to return normally. +-spec takeover(_, _, _, _, _, _, _) -> no_return(). takeover(Parent, Ref, Socket, Transport, Opts, Buffer, State=#state{pid=Pid}) -> Pid ! {Pid, self(), takeover, Parent, Ref, Socket, Transport, Opts, Buffer, State}, exit(normal). diff --git a/test/handlers/switch_protocol_flush_h.erl b/test/handlers/switch_protocol_flush_h.erl index 3d525ee..1b06df2 100644 --- a/test/handlers/switch_protocol_flush_h.erl +++ b/test/handlers/switch_protocol_flush_h.erl @@ -27,6 +27,8 @@ info(_, _, State) -> terminate(_, _, _) -> ok. +%% @todo It would be good if we could allow this function to return normally. +-spec takeover(_, _, _, _, _, _, _) -> no_return(). takeover(_, _, _, _, _, _, Pid) -> Msgs = receive_all([]), Pid ! {Pid, Msgs}, diff --git a/test/handlers/ws_terminate_h.erl b/test/handlers/ws_terminate_h.erl index 4621df6..12e6d1a 100644 --- a/test/handlers/ws_terminate_h.erl +++ b/test/handlers/ws_terminate_h.erl @@ -31,4 +31,5 @@ websocket_info(_, State) -> {ok, State}. terminate(Reason, Req, #state{pid=Pid}) -> - Pid ! {terminate, Reason, Req}. + Pid ! {terminate, Reason, Req}, + ok. diff --git a/test/old_http_SUITE.erl b/test/old_http_SUITE.erl index 8e31ec1..affc3e7 100644 --- a/test/old_http_SUITE.erl +++ b/test/old_http_SUITE.erl @@ -181,7 +181,7 @@ http10_hostless(Config) -> tcp -> {ranch_tcp, cowboy_clear}; ssl -> {ranch_ssl, cowboy_tls} end, - ranch:start_listener(Name, 5, Transport, + {ok, _} = ranch:start_listener(Name, 5, Transport, config(opts, Config) ++ [{port, Port10}], Protocol, #{ env =>#{dispatch => cowboy_router:compile([ @@ -197,7 +197,7 @@ http10_keepalive_default(Config) -> Normal = "GET / HTTP/1.0\r\nhost: localhost\r\n\r\n", Client = raw_open(Config), ok = raw_send(Client, Normal), - case catch raw_recv_head(Client) of + _ = case catch raw_recv_head(Client) of {'EXIT', _} -> error(closed); Data -> %% Cowboy always advertises itself as HTTP/1.1. @@ -215,7 +215,7 @@ http10_keepalive_forced(Config) -> Keepalive = "GET / HTTP/1.0\r\nhost: localhost\r\nConnection: keep-alive\r\n\r\n", Client = raw_open(Config), ok = raw_send(Client, Keepalive), - case catch raw_recv_head(Client) of + _ = case catch raw_recv_head(Client) of {'EXIT', _} -> error(closed); Data -> %% Cowboy always advertises itself as HTTP/1.1. @@ -268,7 +268,7 @@ do_nc(Config, Input) -> _Good -> %% Throw garbage at the server then check if it's still up. StrPort = integer_to_list(config(port, Config)), - [os:cmd("cat " ++ Input ++ " | nc localhost " ++ StrPort) + _ = [os:cmd("cat " ++ Input ++ " | nc localhost " ++ StrPort) || _ <- lists:seq(1, 100)], 200 = do_get("/", Config) end. diff --git a/test/old_http_SUITE_data/http_errors.erl b/test/old_http_SUITE_data/http_errors.erl index 14e3d09..9e376a2 100644 --- a/test/old_http_SUITE_data/http_errors.erl +++ b/test/old_http_SUITE_data/http_errors.erl @@ -4,10 +4,12 @@ -export([init/2]). +-spec init(_, _) -> no_return(). init(Req, _Opts) -> #{'case' := Case} = cowboy_req:match_qs(['case'], Req), case_init(Case, Req). +-spec case_init(_, _) -> no_return(). case_init(<<"init_before_reply">> = Case, _Req) -> ct_helper_error_h:ignore(?MODULE, case_init, 2), error(Case); diff --git a/test/static_handler_SUITE.erl b/test/static_handler_SUITE.erl index 43085b8..9b7a1dc 100644 --- a/test/static_handler_SUITE.erl +++ b/test/static_handler_SUITE.erl @@ -80,7 +80,7 @@ end_per_suite(Config) -> %% Special directory. CharDir = config(char_dir, Config), _ = [file:delete(CharDir ++ [$/, C]) || C <- lists:seq(0, 127)], - file:del_dir(CharDir), + _ = file:del_dir(CharDir), %% Static directories. StaticDir = config(static_dir, Config), PrivDir = code:priv_dir(ct_helper) ++ "/static", @@ -162,6 +162,7 @@ init_dispatch(Config) -> %% Internal functions. +-spec do_etag_crash(_, _, _) -> no_return(). do_etag_crash(_, _, _) -> ct_helper_error_h:ignore(?MODULE, do_etag_crash, 3), exit(crash). @@ -169,6 +170,7 @@ do_etag_crash(_, _, _) -> do_etag_custom(_, _, _) -> {strong, <<"etag">>}. +-spec do_mime_crash(_) -> no_return(). do_mime_crash(_) -> ct_helper_error_h:ignore(?MODULE, do_mime_crash, 1), exit(crash). |