From 510a717dbb2f45431c2bcc3b22138ebe6cb43532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Re=CC=81mond?= Date: Sun, 22 Feb 2015 17:41:17 +0100 Subject: [PATCH 1/2] Support for running Elixir ExUnit tests from Common Test --- test/elixir_SUITE.erl | 55 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 test/elixir_SUITE.erl diff --git a/test/elixir_SUITE.erl b/test/elixir_SUITE.erl new file mode 100644 index 000000000..70500b162 --- /dev/null +++ b/test/elixir_SUITE.erl @@ -0,0 +1,55 @@ +%%%------------------------------------------------------------------- +%%% @author Mickael Remond +%%% @copyright (C) 2002-2015, ProcessOne +%%% @doc +%%% This is a common test wrapper to run our ejabberd tests written in +%%% Elixir from standard common test code. +%%% +%%% Example: Is run with: +%%% ./rebar skip_deps=true ct suites=test/elixir_SUITE +%%% @end +%%% Created : 19 Feb 2015 by Mickael Remond +%%%------------------------------------------------------------------- + +-module(elixir_SUITE). + +-compile(export_all). + +init_per_testcase(_TestCase, Config) -> + process_flag(error_handler, ?MODULE), + Config. + +all() -> + case is_elixir_available() of + true -> + Dir = test_dir(), + filelib:fold_files(Dir, ".*\.exs", false, + fun(Filename, Acc) -> [list_to_atom(filename:basename(Filename)) | Acc] end, + []); + false -> + [] + end. + +is_elixir_available() -> + case catch elixir:module_info() of + {'EXIT',{undef,_}} -> + false; + ModInfo when is_list(ModInfo) -> + true + end. + +undefined_function(?MODULE, Func, Args) -> + case lists:suffix(".exs", atom_to_list(Func)) of + true -> + 'Elixir.ExUnit':start([]), + 'Elixir.Code':load_file(list_to_binary(filename:join(test_dir(), atom_to_list(Func)))), + 'Elixir.ExUnit':run(); + false -> + error_handler:undefined_function(?MODULE, Func, Args) + end; +undefined_function(Module, Func, Args) -> + error_handler:undefined_function(Module, Func,Args). + +test_dir() -> + {ok, CWD} = file:get_cwd(), + filename:join(CWD, "../../test"). From 17be6a303ba4bfbf773d0f0c7aa9e4d6ecc0d837 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mickae=CC=88l=20Re=CC=81mond?= Date: Sun, 22 Feb 2015 17:45:25 +0100 Subject: [PATCH 2/2] Improve comments for running Elixir tests --- test/elixir_SUITE.erl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/elixir_SUITE.erl b/test/elixir_SUITE.erl index 70500b162..ec5dc5ec6 100644 --- a/test/elixir_SUITE.erl +++ b/test/elixir_SUITE.erl @@ -6,7 +6,9 @@ %%% Elixir from standard common test code. %%% %%% Example: Is run with: -%%% ./rebar skip_deps=true ct suites=test/elixir_SUITE +%%% ./rebar skip_deps=true ct suites=elixir +%%% or from ejabber overall test suite: +%%% make test %%% @end %%% Created : 19 Feb 2015 by Mickael Remond %%%-------------------------------------------------------------------