diff options
author | Peter Andersson <[email protected]> | 2012-03-15 00:01:13 +0100 |
---|---|---|
committer | Peter Andersson <[email protected]> | 2012-03-19 14:06:57 +0100 |
commit | ea23dbfba71bf4bc17fb9c61b19dc3973ccc30f1 (patch) | |
tree | 335dce50e9392105a291a2f66827656288e4951e /lib/common_test | |
parent | 37827c8f57036cec67c4d9460c02c468aa615155 (diff) | |
download | otp-ea23dbfba71bf4bc17fb9c61b19dc3973ccc30f1.tar.gz otp-ea23dbfba71bf4bc17fb9c61b19dc3973ccc30f1.tar.bz2 otp-ea23dbfba71bf4bc17fb9c61b19dc3973ccc30f1.zip |
Run hooks for non-existing config functions
Diffstat (limited to 'lib/common_test')
-rw-r--r-- | lib/common_test/src/ct_framework.erl | 43 | ||||
-rw-r--r-- | lib/common_test/src/ct_hooks.erl | 22 | ||||
-rw-r--r-- | lib/common_test/src/ct_run.erl | 3 |
3 files changed, 46 insertions, 22 deletions
diff --git a/lib/common_test/src/ct_framework.erl b/lib/common_test/src/ct_framework.erl index cdd8a6a596..1536a5591e 100644 --- a/lib/common_test/src/ct_framework.erl +++ b/lib/common_test/src/ct_framework.erl @@ -29,7 +29,8 @@ -export([get_logopts/0, format_comment/1, get_html_wrapper/3]). --export([error_in_suite/1, ct_init_per_group/2, ct_end_per_group/2]). +-export([error_in_suite/1, init_per_suite/1, end_per_suite/1, + ct_init_per_group/2, ct_end_per_group/2]). -export([make_all_conf/3, make_conf/5]). @@ -69,14 +70,16 @@ init_tc(Mod,Func,Config) -> case ct_util:get_testdata(curr_tc) of {Suite,{suite0_failed,_}=Failure} -> {Failure,false}; - {?MODULE,_} -> % should not really happen - {false,false}; - {Suite,_} -> % Func is not 1st case in suite - {false,false}; - _ when Func == init_per_suite -> % defaults will be added anyway - {false,false}; - _ -> % first case in suite - {false,true} + {?MODULE,_} when Func == init_per_suite -> + {false,true}; % no init_per_suite in Mod + {?MODULE,_} -> + {false,false}; % should not really happen + {Suite,_} -> + {false,false}; % Func is not 1st case in suite + _ when Func == init_per_suite -> + {false,false}; % defaults will be added anyway + _ -> + {false,true} % first case in suite end, case InitFailed of false -> @@ -123,8 +126,9 @@ init_tc1(Mod,Func,[Config0],DoInit) when is_list(Config0) -> {{Mod,LastFunc},SavedConfig} -> % last testcase [{saved_config,{LastFunc,SavedConfig}} | lists:keydelete(saved_config,1,Config0)]; - {{LastSuite,InitOrEnd},SavedConfig} when InitOrEnd == init_per_suite ; - InitOrEnd == end_per_suite -> + {{LastSuite,InitOrEnd}, + SavedConfig} when InitOrEnd == init_per_suite ; + InitOrEnd == end_per_suite -> %% last suite [{saved_config,{LastSuite,SavedConfig}} | lists:keydelete(saved_config,1,Config0)]; @@ -259,7 +263,11 @@ init_tc2(Mod,Func,SuiteInfo,MergeResult,Config,DoInit) -> end. ct_suite_init(Mod, Func, [Config]) when is_list(Config) -> - case ct_hooks:init_tc( Mod, Func, Config) of + +%%! --- Thu Mar 15 15:16:17 2012 --- peppe was here! +%%!io:format(user, "+++ ct_suite_init ~p:~p -- ~p~n", [Mod,Func,Config]), + + case ct_hooks:init_tc(Mod, Func, Config) of NewConfig when is_list(NewConfig) -> {ok, [NewConfig]}; Else -> @@ -1470,6 +1478,16 @@ error_in_suite(Config) -> Reason = test_server:lookup_config(error,Config), exit(Reason). +%% if init_per_suite and end_per_suite are missing in the suite, +%% these will be called instead (without any trace of them in the +%% log files), only so that it's possible to call hook functions +%% for configuration +init_per_suite(Config) -> + Config. + +end_per_suite(_Config) -> + ok. + %% if the group config functions are missing in the suite, %% use these instead ct_init_per_group(GroupName, Config) -> @@ -1485,7 +1503,6 @@ ct_end_per_group(GroupName, _) -> "in suite, using default.", [GroupName]), ok. - %%%----------------------------------------------------------------- %%% @spec report(What,Data) -> ok diff --git a/lib/common_test/src/ct_hooks.erl b/lib/common_test/src/ct_hooks.erl index c42adbbdd9..026f86c8a7 100644 --- a/lib/common_test/src/ct_hooks.erl +++ b/lib/common_test/src/ct_hooks.erl @@ -70,8 +70,7 @@ terminate(Hooks) -> {skip, Reason :: term()} | {auto_skip, Reason :: term()} | {fail, Reason :: term()}. -init_tc(ct_framework, _Func, Args) -> - Args; + init_tc(Mod, init_per_suite, Config) -> Info = try proplists:get_value(ct_hooks, Mod:suite(),[]) of List when is_list(List) -> @@ -89,6 +88,11 @@ init_tc(Mod, {init_per_group, GroupName, Opts}, Config) -> call(fun call_generic/3, Config, [pre_init_per_group, GroupName]); init_tc(_Mod, {end_per_group, GroupName, _}, Config) -> call(fun call_generic/3, Config, [pre_end_per_group, GroupName]); +init_tc(Mod, {ct_init_per_group, GroupName, Opts}, Config) -> + maybe_start_locker(Mod, GroupName, Opts), + call(fun call_generic/3, Config, [pre_init_per_group, GroupName]); +init_tc(_Mod, {ct_end_per_group, GroupName, _}, Config) -> + call(fun call_generic/3, Config, [pre_end_per_group, GroupName]); init_tc(_Mod, TC, Config) -> call(fun call_generic/3, Config, [pre_init_per_testcase, TC]). @@ -104,27 +108,29 @@ init_tc(_Mod, TC, Config) -> {auto_skip, Reason :: term()} | {fail, Reason :: term()} | ok | '$ct_no_change'. -end_tc(ct_framework, _Func, _Args, Result, _Return) -> - Result; end_tc(Mod, init_per_suite, Config, _Result, Return) -> call(fun call_generic/3, Return, [post_init_per_suite, Mod, Config], '$ct_no_change'); - end_tc(Mod, end_per_suite, Config, Result, _Return) -> call(fun call_generic/3, Result, [post_end_per_suite, Mod, Config], '$ct_no_change'); - end_tc(_Mod, {init_per_group, GroupName, _}, Config, _Result, Return) -> call(fun call_generic/3, Return, [post_init_per_group, GroupName, Config], '$ct_no_change'); - end_tc(Mod, {end_per_group, GroupName, Opts}, Config, Result, _Return) -> Res = call(fun call_generic/3, Result, [post_end_per_group, GroupName, Config], '$ct_no_change'), maybe_stop_locker(Mod, GroupName,Opts), Res; - +end_tc(_Mod, {ct_init_per_group, GroupName, _}, Config, _Result, Return) -> + call(fun call_generic/3, Return, [post_init_per_group, GroupName, Config], + '$ct_no_change'); +end_tc(Mod, {ct_end_per_group, GroupName, Opts}, Config, Result, _Return) -> + Res = call(fun call_generic/3, Result, + [post_end_per_group, GroupName, Config], '$ct_no_change'), + maybe_stop_locker(Mod, GroupName,Opts), + Res; end_tc(_Mod, TC, Config, Result, _Return) -> call(fun call_generic/3, Result, [post_end_per_testcase, TC, Config], '$ct_no_change'). diff --git a/lib/common_test/src/ct_run.erl b/lib/common_test/src/ct_run.erl index 666eb3c988..d142bdaa81 100644 --- a/lib/common_test/src/ct_run.erl +++ b/lib/common_test/src/ct_run.erl @@ -1413,7 +1413,8 @@ do_run(Tests, Skip, Opts, Args) when is_record(Opts, opts) -> %% which framework it runs under. case os:getenv("TEST_SERVER_FRAMEWORK") of false -> - os:putenv("TEST_SERVER_FRAMEWORK", "ct_framework"); + os:putenv("TEST_SERVER_FRAMEWORK", "ct_framework"), + os:putenv("TEST_SERVER_FRAMEWORK_NAME", "common_test"); "ct_framework" -> ok; Other -> |