I have fixed two bugs #11

Closed
wants to merge 8 commits into
from
View
@@ -2,4 +2,6 @@ ebin
erl_crash.dump
**.cov.html
*~
-cucumberl
+cucumberl
+.eunit
+*.swp
View
@@ -30,7 +30,7 @@ run(FilePath)
run(FilePath, FeatureModule)
when is_list(FilePath), is_atom(FeatureModule) ->
- {_, Tree} = cucumber_parser:parse(FilePath),
+ {_, Tree} = cucumberl_parser:parse(FilePath),
run_tree(Tree, FeatureModule).
run_tree(Tree, FeatureModule) ->
@@ -54,12 +54,12 @@ run_tree(Tree, FeatureModule) ->
catch
Err:Reason ->
%% something else went wrong, which means fail
- io:format("Feature Failed: ~p:~p ~p",
+ io:format("\e[31mFeature Failed: ~p:~p ~p",
[Err, Reason,
erlang:get_stacktrace()]),
failed
end,
- case Result of
+ Verdict = case Result of
#cucumberl_stats{scenarios = NScenarios,
steps = NSteps,
failures = []} ->
@@ -69,12 +69,15 @@ run_tree(Tree, FeatureModule) ->
#cucumberl_stats{scenarios = NScenarios,
steps = NSteps,
failures = Failures} ->
- io:format("~n~p scenarios~n~p steps~n~p failures ~n~n",
+ io:format("~n~p scenarios~n~p steps~n\e[31m~p failures ~n~n",
[NScenarios, NSteps, erlang:length(Failures)]),
{failed, Result};
_ ->
failed
- end.
+ end,
+ io:format("\e[39m"),
+ Verdict.
+
process_line({Type, LineNum, Tokens, Line},
{SkipScenario, State,
@@ -84,7 +87,7 @@ process_line({Type, LineNum, Tokens, Line},
FeatureModule) ->
%% GWT stands for given-when-then.
%% GWT is the previous line's given-when-then atom.
- io:format("~s:~s ~n",
+ io:format("\e[32m~s:~s ~n",
[string:left(Line, 65),
string:left(integer_to_list(LineNum), 4)]),
@@ -95,9 +98,11 @@ process_line({Type, LineNum, Tokens, Line},
{_, feature} ->
{false, {ok, State}, Stats};
{_, scenario} ->
+ call_scenario_setup(FeatureModule),
{false, {ok, State},
Stats#cucumberl_stats{scenarios = NScenarios + 1}};
{_, scenario_outline} ->
+ call_scenario_setup(FeatureModule),
{false, {ok, State},
Stats#cucumberl_stats{scenarios = NScenarios + 1}};
{false, {action, G}} ->
@@ -107,11 +112,11 @@ process_line({Type, LineNum, Tokens, Line},
catch
error:function_clause ->
%% we don't have a matching function clause
- io:format("~nSTEP ~s is *not* implemented: ~p ~n",
+ io:format("~n\e[31mSTEP ~s is *not* implemented: ~p ~n",
[Line, Tokens]),
{failed, {unimplemented, Tokens}};
Err:Reason ->
- io:format("~nSTEP: ~s FAILED: ~n ~p:~p ~p~n",
+ io:format("~n\e[31mSTEP: ~s FAILED: ~n ~p:~p ~p~n",
[Line, Err, Reason,
erlang:get_stacktrace()]),
%% something else went wrong, which means fail
@@ -136,14 +141,14 @@ process_line({Type, LineNum, Tokens, Line},
skipped ->
{SkipScenario2, State, Stats2};
missing ->
- io:format("---------NO-STEP--------~n~n"),
- io:format("a step definition snippet...~n"),
+ io:format("\e[31m---------NO-STEP--------~n~n"),
+ io:format("\e[31ma step definition snippet...~n"),
format_missing_step(G1, Tokens),
{true, undefined, undefined, State,
Stats2#cucumberl_stats{failures = [{missing, G1}
| FailedSoFar] }};
FailedResult ->
- io:format("-------FAIL------- ~n~n"),
+ io:format("\e[31m-------FAIL------- ~n~n"),
{true, State,
Stats2#cucumberl_stats{ failures = [{FailedResult, Result}
|FailedSoFar] }}
@@ -174,9 +179,9 @@ check_step({failed, _}) -> failed;
check_step(_) -> invalid_result.
format_missing_step('when', Tokens) ->
- io:format("'when'(~p, State, _) ->~n undefined.~n~n", [Tokens]);
+ io:format("\e[31m'when'(~p, State, _) ->~n undefined.~n~n", [Tokens]);
format_missing_step(GWT, Tokens) ->
- io:format("~p(~p, State, _) ->~n undefined.~n~n", [GWT, Tokens]).
+ io:format("\e[31m~p(~p, State, _) ->~n undefined.~n~n", [GWT, Tokens]).
call_setup(FeatureModule) ->
case erlang:function_exported(FeatureModule, setup, 0) of
@@ -187,9 +192,17 @@ call_setup(FeatureModule) ->
end.
call_teardown(FeatureModule, State) ->
- case erlang:function_exported(FeatureModule, teardown, 0) of
+ case erlang:function_exported(FeatureModule, teardown, 1) of
true ->
FeatureModule:teardown(State);
false ->
undefined
end.
+
+call_scenario_setup(FeatureModule) ->
+ case erlang:function_exported(FeatureModule, scenario_setup, 0) of
+ true ->
+ FeatureModule:scenario_setup();
+ false ->
+ undefined
+ end.