Skip to content

Commit fa41136

Browse files
authored
Merge pull request #17 from antedeguemon/vm-fixes-handle-call-warning
Fixes compilation warning from Instance.handle_call/3
2 parents a96d916 + 590815a commit fa41136

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
otp-version: ${{matrix.version.otp}}
2929
elixir-version: ${{matrix.version.elixir}}
3030
- run: mix deps.get
31+
- run: MIX_ENV=test mix compile --warnings-as-errors
3132
- run: HTTP_SERVER=${{matrix.http_server}} mix test
3233
- run: MIX_ENV=test mix credo
3334
deploy:

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# Changelog
2+
3+
## v0.1.14 (TBA)
4+
5+
- Fixed compiler warning in `TestServer.Instance`
6+
7+
18
## v0.1.13 (2023-08-26)
29

310
- Fixed controlling process issues related to using the Bandit HTTP/2 adapter calling `Plug.Conn` functions in plug callbacks

lib/test_server/instance.ex

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -213,36 +213,6 @@ defmodule TestServer.Instance do
213213
{:reply, {:ok, plug}, %{state | plugs: state.plugs ++ [plug]}}
214214
end
215215

216-
defp build_match_function(uri, methods) do
217-
{method_match, guards} =
218-
case methods do
219-
["*"] ->
220-
{quote(do: _), true}
221-
222-
methods ->
223-
var = quote do: method
224-
guards = quote(do: unquote(var) in unquote(methods))
225-
226-
{var, guards}
227-
end
228-
229-
{_params, path_match, guards, _post_match} = Plug.Router.Utils.build_path_clause(uri, guards)
230-
231-
{match_fn, []} =
232-
Code.eval_quoted(
233-
quote do
234-
fn
235-
_conn, unquote(method_match), unquote(path_match), _host when unquote(guards) -> true
236-
_conn, _method, _path, _host -> false
237-
end
238-
end
239-
)
240-
241-
fn conn ->
242-
match_fn.(conn, conn.method, Plug.Router.Utils.decode_path_info!(conn), conn.host)
243-
end
244-
end
245-
246216
def handle_call(
247217
{:register, {:websocket, {_instance, route_ref}, {:handle, options, stacktrace}}},
248218
_from,
@@ -310,6 +280,36 @@ defmodule TestServer.Instance do
310280
{:reply, res, state}
311281
end
312282

283+
defp build_match_function(uri, methods) do
284+
{method_match, guards} =
285+
case methods do
286+
["*"] ->
287+
{quote(do: _), true}
288+
289+
methods ->
290+
var = quote do: method
291+
guards = quote(do: unquote(var) in unquote(methods))
292+
293+
{var, guards}
294+
end
295+
296+
{_params, path_match, guards, _post_match} = Plug.Router.Utils.build_path_clause(uri, guards)
297+
298+
{match_fn, []} =
299+
Code.eval_quoted(
300+
quote do
301+
fn
302+
_conn, unquote(method_match), unquote(path_match), _host when unquote(guards) -> true
303+
_conn, _method, _path, _host -> false
304+
end
305+
end
306+
)
307+
308+
fn conn ->
309+
match_fn.(conn, conn.method, Plug.Router.Utils.decode_path_info!(conn), conn.host)
310+
end
311+
end
312+
313313
defp run_plugs(conn, state) do
314314
state.plugs
315315
|> case do

0 commit comments

Comments
 (0)