2015-02-22 17:41:17 +01:00
|
|
|
%%%-------------------------------------------------------------------
|
2017-01-03 15:58:52 +01:00
|
|
|
%%% Author : Mickael Remond <mremond@process-one.net>
|
|
|
|
%%% Created : 19 Feb 2015 by Mickael Remond <mremond@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
|
|
|
%%% ejabberd, Copyright (C) 2002-2017 ProcessOne
|
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
|
|
|
%%%
|
|
|
|
%%% You should have received a copy of the GNU General Public License along
|
|
|
|
%%% with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
%%% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
%%%
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
2015-02-22 17:41:17 +01:00
|
|
|
%%% 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
|
|
|
|
|
|
|
-module(elixir_SUITE).
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
2016-03-15 22:42:07 +01:00
|
|
|
init_per_suite(Config) ->
|
2016-05-30 23:05:45 +02:00
|
|
|
suite:setup_ejabberd_lib_path(Config),
|
2016-03-15 22:42:07 +01:00
|
|
|
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
|
2017-06-09 12:59:47 +02:00
|
|
|
'Elixir.ExUnit':start([{exclude, [{pending, true}]},
|
|
|
|
{formatters,
|
|
|
|
['Elixir.ExUnit.CLIFormatter',
|
|
|
|
'Elixir.ExUnit.CTFormatter']},
|
|
|
|
{autorun, false}]),
|
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
|
2017-06-14 14:56:42 +02:00
|
|
|
catch 'Elixir.ExUnit.Server':cases_loaded(),
|
2015-03-07 12:31:11 +01:00
|
|
|
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").
|