-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathscenarios.erl
66 lines (59 loc) · 1.96 KB
/
scenarios.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
%%%----------------------------------------------------------------------
%%% Copyright (c) 2012, Alkis Gotovos <[email protected]>,
%%% Maria Christakis <[email protected]>
%%% and Kostis Sagonas <[email protected]>.
%%% All rights reserved.
%%%
%%% This file is distributed under the Simplified BSD License.
%%% Details can be found in the LICENSE file.
%%%----------------------------------------------------------------------
%%% Authors : Tsitsimpis Ilias <[email protected]>
%%% Description : Interface to extract scenarios from our tests
%%%----------------------------------------------------------------------
-module(scenarios).
-export([extract/1, exceptional/1]).
extract(Files) ->
S1 = lists:map(fun extractOne/1, Files),
S2 = lists:flatten(S1),
lists:foreach(fun(S) -> io:format("~w\n", [S]) end, S2).
extractOne(File) ->
Module = list_to_atom(filename:basename(File, ".erl")),
%% Get the scenarios for one module
try
Scenarios = Module:scenarios(),
%% Put module name to it
FunMap =
fun(Scenario) ->
list_to_tuple([Module | tuple_to_list(normalize(Scenario))])
end,
lists:map(FunMap, Scenarios)
catch
error:undef ->
io:format(standard_error, "No scenarios() function in ~s~n", [File]),
[];
{bad_scenario, S} ->
io:format(standard_error, "Bad scenario in ~s: ~w~n", [File, S]),
[]
end.
normalize(Atom) when is_atom(Atom) ->
normalize({Atom});
normalize({Fun}) ->
normalize({Fun, inf});
normalize({Fun, Bound}) ->
normalize({Fun, Bound, optimal});
normalize(Tuple) when is_tuple(Tuple) ->
Tuple;
normalize(Other) ->
throw({bad_scenario, Other}).
-spec exceptional([filename:filename()]) -> no_return().
exceptional([Name, Expected, Actual]) ->
Module = list_to_atom(Name),
%% Get the scenarios for one module
try
Fun = Module:exceptional(),
true = Fun(Expected, Actual),
halt(0)
catch
_:_ ->
halt(1)
end.