Skip to content

Commit

Permalink
Merge pull request #49 from benningm/master
Browse files Browse the repository at this point in the history
passthrough unknown commandline options to allow use by Harness plugins
  • Loading branch information
Peter Sergeant committed Dec 23, 2014
2 parents 31c24ad + 4867678 commit da19744
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 13 deletions.
10 changes: 5 additions & 5 deletions lib/App/pherkin.pm
Expand Up @@ -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'} );

Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 {
Expand Down
57 changes: 49 additions & 8 deletions lib/Test/BDD/Cucumber/Harness/TermColor.pm
Expand Up @@ -22,6 +22,8 @@ use strict;
use warnings;
use Moose;

use Getopt::Long;

# Try and make the colors just work on Windows...
BEGIN {
if (
Expand Down Expand Up @@ -59,6 +61,42 @@ A filehandle to write output to; defaults to C<STDOUT>

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 {
Expand All @@ -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 || [] } ],
Expand All @@ -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,
Expand All @@ -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 ) {
Expand All @@ -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) {
Expand Down Expand Up @@ -187,7 +228,7 @@ sub _note_step_data {
$self->_display(
{
indent => 6 + $extra_indent,
color => 'bright_cyan',
color => $self->_colors->{'step_data'},
text => $text
}
);
Expand Down

0 comments on commit da19744

Please sign in to comment.