diff --git a/lib/App/pherkin.pm b/lib/App/pherkin.pm index b87e628..7a5a843 100644 --- a/lib/App/pherkin.pm +++ b/lib/App/pherkin.pm @@ -57,10 +57,10 @@ sub run { my ( $options, @feature_files ) = $self->_process_arguments(@arguments); + my $features_path = $feature_files[0] || './features/'; my ( $executor, @features ) = - Test::BDD::Cucumber::Loader->load( $feature_files[0] || './features/', - $self->tag_scheme ); - die "No feature files found" unless @features; + Test::BDD::Cucumber::Loader->load( $features_path, $self->tag_scheme ); + die "No feature files found in $features_path" unless @features; my $harness = $self->_load_harness( $options->{'harness'} ); @@ -97,7 +97,7 @@ sub _process_arguments { local @ARGV = @args; # Allow -Ilib, -bl - Getopt::Long::Configure('bundling'); + Getopt::Long::Configure('bundling', 'pass_through'); my $includes = []; my $tags = []; @@ -133,7 +133,7 @@ sub _process_arguments { # Store our TagSpecScheme $self->tag_scheme( $self->_process_tags( @{$tags} ) ); - return ( { harness => $harness }, @ARGV ); + return ( { harness => $harness }, pop @ARGV ); } sub _process_tags { diff --git a/lib/Test/BDD/Cucumber/Harness/TermColor.pm b/lib/Test/BDD/Cucumber/Harness/TermColor.pm index 4d38f5f..d920a7d 100644 --- a/lib/Test/BDD/Cucumber/Harness/TermColor.pm +++ b/lib/Test/BDD/Cucumber/Harness/TermColor.pm @@ -22,6 +22,8 @@ use strict; use warnings; use Moose; +use Getopt::Long; + # Try and make the colors just work on Windows... BEGIN { if ( @@ -59,6 +61,42 @@ A filehandle to write output to; defaults to C has 'fh' => ( is => 'rw', isa => 'FileHandle', default => sub { \*STDOUT } ); +has theme => ( 'is' => 'ro', isa => 'Str', lazy => 1, default => sub { + my $theme = 'dark'; + Getopt::Long::Configure('pass_through'); + GetOptions ("c|theme=s" => \$theme); + return($theme); +} ); + +has _themes => ( is => 'ro', isa => 'HashRef[HashRef]', lazy => 1, default => sub {{ + dark => { + 'feature' => 'bright_white', + 'scenario' => 'bright_white', + 'scenario_name' => 'bright_blue', + 'pending' => 'yellow', + 'passing' => 'green', + 'failed' => 'red', + 'step_data' => 'bright_cyan', + }, + light => { + 'feature' => 'reset', + 'scenario' => 'black', + 'scenario_name' => 'blue', + 'pending' => 'yellow', + 'passing' => 'green', + 'failed' => 'red', + 'step_data' => 'cyan', + }, +}} ); + +has _colors => ( is => 'ro', isa => 'HashRef', lazy => 1, default => sub { + my $self = shift; + if( ! defined $self->_themes->{$self->theme} ) { + die('unknown color theme '.$self->theme.'!'); + } + return( $self->_themes->{$self->theme} ); +} ); + my $margin = 2; sub BUILD { @@ -80,7 +118,7 @@ sub feature { $self->_display( { indent => 0, - color => 'bright_white', + color => $self->_colors->{'feature'}, text => $feature->name, follow_up => [ map { $_->content } @{ $feature->satisfaction || [] } ], @@ -97,12 +135,13 @@ sub feature_done { sub scenario { my ( $self, $scenario, $dataset, $longest ) = @_; - my $text = "Scenario: " . color('bright_blue') . ( $scenario->name || '' ); + my $text = "Scenario: " . color($self->_colors->{'scenario_name'}) + .( $scenario->name || '' ); $self->_display( { indent => 2, - color => 'bright_white', + color => $self->_colors->{'scenario'}, text => $text, follow_up => [], trailing => 0, @@ -125,13 +164,15 @@ sub step_done { my $color; my $follow_up = []; my $status = $result->result; + my $failed = 0; if ( $status eq 'undefined' || $status eq 'pending' ) { - $color = 'yellow'; + $color = $self->_colors->{'pending'}; } elsif ( $status eq 'passing' ) { - $color = 'green'; + $color = $self->_colors->{'passing'}; } else { - $color = 'red'; + $failed = 1; + $color = $self->_colors->{'failed'}; $follow_up = [ split( /\n/, $result->{'output'} ) ]; if ( !$context->is_hook ) { @@ -146,7 +187,7 @@ sub step_done { my $text; if ( $context->is_hook ) { - $color eq 'red' or return; + $failed or return; $text = 'In ' . ucfirst( $context->verb ) . ' Hook'; undef $highlights; } elsif ($highlights) { @@ -187,7 +228,7 @@ sub _note_step_data { $self->_display( { indent => 6 + $extra_indent, - color => 'bright_cyan', + color => $self->_colors->{'step_data'}, text => $text } );