2015-02-22 17:41:17 +01:00
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
%%% @author Mickael Remond <mremond@process-one.net>
|
2016-01-13 12:29:14 +01:00
|
|
|
%%% @copyright (C) 2002-2016, ProcessOne
|
2015-02-22 17:41:17 +01:00
|
|
|
%%% @doc
|
|
|
|
%%% This is a common test wrapper to run our ejabberd tests written in
|
|
|
|
%%% Elixir from standard common test code.
|
|
|
|
%%%
|
|
|
|
%%% Example: Is run with:
|
2015-02-22 17:45:25 +01:00
|
|
|
%%% ./rebar skip_deps=true ct suites=elixir
|
|
|
|
%%% or from ejabber overall test suite:
|
2016-03-15 22:42:07 +01:00
|
|
|
%%% make quicktest
|
2015-02-22 17:41:17 +01:00
|
|
|
%%% @end
|
|
|
|
%%% Created : 19 Feb 2015 by Mickael Remond <mremond@process-one.net>
|
|
|
|
%%%-------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(elixir_SUITE).
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
2016-03-15 22:42:07 +01:00
|
|
|
init_per_suite(Config) ->
|
|
|
|
check_meck(),
|
2016-03-31 13:53:31 +02:00
|
|
|
code:add_pathz(filename:join(test_dir(), "../include")),
|
2016-03-15 22:42:07 +01:00
|
|
|
Config.
|
|
|
|
|
2015-02-22 17:41:17 +01:00
|
|
|
init_per_testcase(_TestCase, Config) ->
|
|
|
|
process_flag(error_handler, ?MODULE),
|
|
|
|
Config.
|
|
|
|
|
|
|
|
all() ->
|
|
|
|
case is_elixir_available() of
|
2016-03-31 13:53:31 +02:00
|
|
|
true ->
|
|
|
|
Dir = test_dir(),
|
2016-04-06 17:55:56 +02:00
|
|
|
filelib:fold_files(Dir, ".*test\.exs$", false,
|
2016-03-31 13:53:31 +02:00
|
|
|
fun(Filename, Acc) -> [list_to_atom(filename:basename(Filename)) | Acc] end,
|
|
|
|
[]);
|
|
|
|
false ->
|
|
|
|
[]
|
2015-02-22 17:41:17 +01:00
|
|
|
end.
|
|
|
|
|
2016-03-15 22:42:07 +01:00
|
|
|
check_meck() ->
|
|
|
|
case catch meck:module_info(module) of
|
|
|
|
meck ->
|
|
|
|
ok;
|
|
|
|
{'EXIT',{undef, _}} ->
|
|
|
|
ct:print("meck is not available. Please make sure you configured ejabberd with --enable-elixir --enable-tools"),
|
|
|
|
ok
|
|
|
|
end.
|
|
|
|
|
2015-02-22 17:41:17 +01:00
|
|
|
is_elixir_available() ->
|
|
|
|
case catch elixir:module_info() of
|
|
|
|
{'EXIT',{undef,_}} ->
|
2016-03-15 22:42:07 +01:00
|
|
|
ct:print("ejabberd has not been build with Elixir support, skipping Elixir tests."),
|
2015-02-22 17:41:17 +01:00
|
|
|
false;
|
|
|
|
ModInfo when is_list(ModInfo) ->
|
|
|
|
true
|
|
|
|
end.
|
|
|
|
|
|
|
|
undefined_function(?MODULE, Func, Args) ->
|
|
|
|
case lists:suffix(".exs", atom_to_list(Func)) of
|
2016-03-31 13:53:31 +02:00
|
|
|
true ->
|
|
|
|
run_elixir_test(Func);
|
|
|
|
false ->
|
|
|
|
error_handler:undefined_function(?MODULE, Func, Args)
|
2015-02-22 17:41:17 +01:00
|
|
|
end;
|
|
|
|
undefined_function(Module, Func, Args) ->
|
|
|
|
error_handler:undefined_function(Module, Func,Args).
|
|
|
|
|
2015-03-07 11:49:37 +01:00
|
|
|
run_elixir_test(Func) ->
|
2016-03-30 13:59:01 +02:00
|
|
|
%% Elixir tests can be tagged as follow to be ignored (place before test start)
|
|
|
|
%% @tag pending: true
|
2016-04-06 17:55:56 +02:00
|
|
|
'Elixir.ExUnit':start([{exclude, [{pending, true}]}, {formatters, ['Elixir.ExUnit.CLIFormatter', 'Elixir.ExUnit.CTFormatter']}]),
|
2016-03-31 22:01:57 +02:00
|
|
|
|
|
|
|
filelib:fold_files(test_dir(), ".*mock\.exs\$", true,
|
|
|
|
fun (File, N) ->
|
|
|
|
'Elixir.Code':load_file(list_to_binary(File)),
|
|
|
|
N+1
|
|
|
|
end, 0),
|
|
|
|
|
2015-03-07 11:49:37 +01:00
|
|
|
'Elixir.Code':load_file(list_to_binary(filename:join(test_dir(), atom_to_list(Func)))),
|
2015-03-07 12:31:11 +01:00
|
|
|
%% I did not use map syntax, so that this file can still be build under R16
|
|
|
|
ResultMap = 'Elixir.ExUnit':run(),
|
2016-03-15 22:42:07 +01:00
|
|
|
case maps:find(failures, ResultMap) of
|
|
|
|
{ok, 0} ->
|
|
|
|
%% Zero failures
|
|
|
|
ok;
|
|
|
|
{ok, Failures} ->
|
2016-04-06 17:55:56 +02:00
|
|
|
ct:print("Tests failed in module '~s': ~.10B failures.~nSee logs for details", [Func, Failures]),
|
|
|
|
ct:fail(elixir_test_failure),
|
|
|
|
error
|
2016-03-15 22:42:07 +01:00
|
|
|
end.
|
2015-03-07 11:49:37 +01:00
|
|
|
|
2015-02-22 17:41:17 +01:00
|
|
|
test_dir() ->
|
|
|
|
{ok, CWD} = file:get_cwd(),
|
|
|
|
filename:join(CWD, "../../test").
|