25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Suppress warnings in Elixir test

This commit is contained in:
Mickaël Rémond 2015-03-08 18:22:14 +01:00
parent 750fefcd6d
commit 6b0bcfa5d7

View File

@ -46,7 +46,7 @@ defmodule EjabberdHooksTest do
hookname = :test_mod_hook hookname = :test_mod_hook
callback = :hook_callback callback = :hook_callback
:ok = :ejabberd_hooks.add(hookname, @host, @self, callback, 40) :ok = :ejabberd_hooks.add(hookname, @host, @self, callback, 40)
[{40, @self, callback}] = :ejabberd_hooks.get_handlers(hookname, @host) [{40, @self, _callback}] = :ejabberd_hooks.get_handlers(hookname, @host)
end end
test "An anonymous function can be removed from hook handlers" do test "An anonymous function can be removed from hook handlers" do
@ -90,7 +90,7 @@ defmodule EjabberdHooksTest do
:ok = :ejabberd_hooks.run(hookname, @host, [:hook_params]) :ok = :ejabberd_hooks.run(hookname, @host, [:hook_params])
# callback2 is never run: # callback2 is never run:
[{_pid, {modulename, callback, [:hook_params]}, :stop}] = :meck.history(modulename) [{_pid, {^modulename, _callback, [:hook_params]}, :stop}] = :meck.history(modulename)
end end
test "Run fold hooks accumulate state in correct order through handlers" do test "Run fold hooks accumulate state in correct order through handlers" do
@ -110,8 +110,8 @@ defmodule EjabberdHooksTest do
# setup test # setup test
hookname = :test_mod_hook hookname = :test_mod_hook
modulename = :hook_module modulename = :hook_module
mock(modulename, :hook_callback1, fn(acc) -> :first end) mock(modulename, :hook_callback1, fn(_acc) -> :first end)
mock(modulename, :hook_callback2, fn(acc) -> :second end) mock(modulename, :hook_callback2, fn(_acc) -> :second end)
:ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback2, 50) :ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback2, 50)
:ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback1, 40) :ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback1, 40)
@ -126,27 +126,27 @@ defmodule EjabberdHooksTest do
# setup test # setup test
hookname = :test_mod_hook hookname = :test_mod_hook
modulename = :hook_module modulename = :hook_module
mock(modulename, :hook_callback1, fn(acc) -> :stop end) mock(modulename, :hook_callback1, fn(_acc) -> :stop end)
mock(modulename, :hook_callback2, fn(acc) -> :executed end) mock(modulename, :hook_callback2, fn(_acc) -> :executed end)
:ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback1, 40) :ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback1, 40)
:ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback2, 50) :ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback2, 50)
:stopped = :ejabberd_hooks.run_fold(hookname, @host, :started, []) :stopped = :ejabberd_hooks.run_fold(hookname, @host, :started, [])
# Only one module has been called # Only one module has been called
[{_pid, {modulename, :hook_callback1, [started]}, :stop}] = :meck.history(modulename) [{_pid, {^modulename, :hook_callback1, [:started]}, :stop}] = :meck.history(modulename)
end end
test "Error in run_fold is ignored" do test "Error in run_fold is ignored" do
run_fold_crash(fn(acc) -> raise :crashed end) run_fold_crash(fn(_acc) -> raise "crashed" end)
end end
test "Throw in run_fold is ignored" do test "Throw in run_fold is ignored" do
run_fold_crash(fn(acc) -> throw :crashed end) run_fold_crash(fn(_acc) -> throw :crashed end)
end end
test "Exit in run_fold is ignored" do test "Exit in run_fold is ignored" do
run_fold_crash(fn(acc) -> exit :crashed end) run_fold_crash(fn(_acc) -> exit :crashed end)
end end
# test for run hook with various number of params # test for run hook with various number of params
@ -160,7 +160,7 @@ defmodule EjabberdHooksTest do
# Then check # Then check
:ok = :ejabberd_hooks.add(hookname, @host, modulename, callback, 40) :ok = :ejabberd_hooks.add(hookname, @host, modulename, callback, 40)
:ok = :ejabberd_hooks.run(hookname, @host, params) :ok = :ejabberd_hooks.run(hookname, @host, params)
[{_pid, {modulename, callback, params}, result}] = :meck.history(modulename) [{_pid, {^modulename, ^callback, ^params}, ^result}] = :meck.history(modulename)
end end
def run_fold_crash(crash_fun) do def run_fold_crash(crash_fun) do
@ -168,7 +168,7 @@ defmodule EjabberdHooksTest do
hookname = :test_mod_hook hookname = :test_mod_hook
modulename = :hook_module modulename = :hook_module
mock(modulename, :hook_callback1, crash_fun) mock(modulename, :hook_callback1, crash_fun)
mock(modulename, :hook_callback2, fn(acc) -> :final end) mock(modulename, :hook_callback2, fn(_acc) -> :final end)
:ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback1, 40) :ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback1, 40)
:ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback2, 50) :ok = :ejabberd_hooks.add(hookname, @host, modulename, :hook_callback2, 50)