Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added colorization of output and scenario setup functionality #14

Open
wants to merge 10 commits into from

1 participant

@khellan

I have added colorized output indicating success with green output and failure with red output. The color is returned to the default at the end.

I have also added support for scenario_setup run for each scenario if present to clear any states from earlier scenarios in the same feature test.

Hope this is useful.

khellan added some commits
@khellan khellan Fixed teardown bug
The test for teardown looked for teardown/0, but attempted to call
teardown/1. This fix looks for teardown/1 as well
b9e2721
@khellan khellan Bugfix typo
Attempted to call a function in cucumber_parser. Corrected this to 
cucuberl_parser.
331e7b7
@khellan khellan Color coding output
Red for indicating failure
Green for indicating normal
983c509
@khellan khellan Ignoring test tmp dir and vi swp-files 7b2ec5d
@khellan khellan Feature scenario setup support
Add support for scenario_setup functions that is run at the beginning of
each scenario.
c65b27d
@khellan khellan Merge branch 'membase_original' into head_merge 60d43c4
@khellan khellan Add colorization
Add red color to the not implemented message
321d6a6
@khellan khellan Bugfix set default text color at the end a15244e
@khellan khellan Bugfix scenario setup
Keeps scenario setup result in State
32c197c
@khellan khellan New rebar from basho d3c3d50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 3, 2011
  1. @khellan

    Fixed teardown bug

    khellan authored
    The test for teardown looked for teardown/0, but attempted to call
    teardown/1. This fix looks for teardown/1 as well
  2. @khellan

    Bugfix typo

    khellan authored
    Attempted to call a function in cucumber_parser. Corrected this to 
    cucuberl_parser.
  3. @khellan

    Color coding output

    khellan authored
    Red for indicating failure
    Green for indicating normal
Commits on Oct 12, 2011
  1. @khellan
Commits on Mar 6, 2012
  1. @khellan

    Feature scenario setup support

    khellan authored
    Add support for scenario_setup functions that is run at the beginning of
    each scenario.
  2. @khellan
  3. @khellan

    Add colorization

    khellan authored
    Add red color to the not implemented message
  4. @khellan
Commits on Apr 23, 2012
  1. @khellan

    Bugfix scenario setup

    khellan authored
    Keeps scenario setup result in State
  2. @khellan

    New rebar from basho

    khellan authored
This page is out of date. Refresh to see the latest.
Showing with 30 additions and 17 deletions.
  1. +3 −1 .gitignore
  2. BIN  rebar
  3. +27 −16 src/cucumberl.erl
View
4 .gitignore
@@ -2,4 +2,6 @@ ebin
erl_crash.dump
**.cov.html
*~
-cucumberl
+cucumberl
+.eunit
+*.swp
View
BIN  rebar
Binary file not shown
View
43 src/cucumberl.erl
@@ -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,10 +98,10 @@ process_line({Type, LineNum, Tokens, Line},
{_, feature} ->
{false, {ok, State}, Stats};
{_, scenario} ->
- {false, {ok, State},
+ {false, {ok, call_scenario_setup(FeatureModule)},
Stats#cucumberl_stats{scenarios = NScenarios + 1}};
{_, scenario_outline} ->
- {false, {ok, State},
+ {false, {ok, call_scenario_setup(FeatureModule)},
Stats#cucumberl_stats{scenarios = NScenarios + 1}};
{false, {action, G}} ->
R = try
@@ -107,11 +110,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 +139,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 +177,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 +190,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.
Something went wrong with that request. Please try again.