4
%% Copyright Ericsson AB 2010. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
22
%% Modules or suites can be shortcuts, for example server expands to reltool_server_SUITE.
24
%% t(Tests) run reltool testcases.
25
%% Tests can be module, {module, test_case} or [module|{module,test_case}]
32
t(Mod, TC) when is_atom(Mod), is_atom(TC) ->
34
t(all, Config) when is_list(Config) ->
35
Fs = filelib:wildcard("reltool_*_SUITE.erl"),
36
t([list_to_atom(filename:rootname(File)) || File <- Fs], Config);
37
t(Test,Config) when is_list(Config) ->
38
Tests = resolve(Test),
39
write_test_case(Test),
40
Res = reltool_test_lib:run_test(Tests, Config),
41
append_test_case_info(Test, Res).
44
user(read_test_case()).
46
t(Mod, [{user,step}]).
47
user(Mod,Tc) when is_atom(Tc) ->
48
t({Mod,Tc}, [{user,step}]).
50
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51
%% Resolves the name of test suites and test cases
52
%% according to the alias definitions. Single atoms
53
%% are assumed to be the name of a test suite.
55
resolve(Suite0) when is_atom(Suite0) ->
57
Suite when is_atom(Suite) ->
62
resolve({Suite0, Case}) when is_atom(Suite0), is_atom(Case) ->
64
Suite when is_atom(Suite) ->
69
resolve(List) when is_list(List) ->
70
[resolve(Case) || Case <- List].
72
alias(Suite) when is_atom(Suite) ->
73
Str = atom_to_list(Suite),
74
case {Str, lists:reverse(Str)} of
75
{"reltool" ++ _, "ETIUS" ++ _} ->
78
list_to_atom("reltool_" ++ Str ++ "_SUITE")
81
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
"reltool_test_case_config".
86
%% Read default config file
88
Fname = config_fname(),
89
reltool_test_lib:log("Consulting file ~s...~n", [Fname]),
90
case file:consult(Fname) of
92
reltool_test_lib:log("Read config ~w~n", [Config]),
95
Config = reltool_test_lib:default_config(),
96
reltool_test_lib:log("<>WARNING<> Using default config: ~w~n", [Config]),
100
%% Write new default config file
101
write_config(Config) when is_list(Config) ->
102
Fname = config_fname(),
103
{ok, Fd} = file:open(Fname, write),
104
write_list(Fd, Config),
107
write_list(Fd, [H | T]) ->
108
ok = io:format(Fd, "~p.~n",[H]),
114
"reltool_test_case_info".
116
%% Read name of test case
118
Fname = test_case_fname(),
119
case file:open(Fname, [read]) of
121
Res = io:read(Fd, []),
125
reltool_test_lib:log("Using test case ~w from file ~s~n",
129
default_test_case(Fname)
132
default_test_case(Fname)
135
default_test_case(Fname) ->
137
reltool_test_lib:log("<>WARNING<> Cannot read file ~s, "
138
"using default test case: ~w~n",
142
write_test_case(TestCase) ->
143
Fname = test_case_fname(),
144
{ok, Fd} = file:open(Fname, write),
145
ok = io:format(Fd, "~p.~n",[TestCase]),
148
append_test_case_info(TestCase, TestCaseInfo) ->
149
Fname = test_case_fname(),
150
{ok, Fd} = file:open(Fname, [read, write]),
151
ok = io:format(Fd, "~p.~n",[TestCase]),
152
ok = io:format(Fd, "~p.~n",[TestCaseInfo]),