[libtest-bdd-cucumber-perl] 07/09: Add a test for Paul Cochrane's earlier patch

Intrigeri intrigeri at moszumanska.debian.org
Thu Jun 19 10:18:51 UTC 2014


This is an automated email from the git hooks/post-receive script.

intrigeri pushed a commit to annotated tag 0.24
in repository libtest-bdd-cucumber-perl.

commit 2cb411adacc1b5cc3e51fdf5f1518898ef97350b
Author: Peter Sergeant <pete at clueball.com>
Date:   Sat Jun 7 11:02:57 2014 +0100

    Add a test for Paul Cochrane's earlier patch
---
 lib/App/pherkin.pm            | 32 +++++++++++++++++++++-----------
 t/400_app_pherkin_harnesses.t | 26 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 11 deletions(-)

diff --git a/lib/App/pherkin.pm b/lib/App/pherkin.pm
index 78b989b..cc9b003 100644
--- a/lib/App/pherkin.pm
+++ b/lib/App/pherkin.pm
@@ -5,9 +5,12 @@ use warnings;
 
 use FindBin::libs;
 use Getopt::Long;
-use Test::BDD::Cucumber::I18n qw(languages langdef readable_keywords keyword_to_subname);
+use Module::Runtime qw(use_module);
 use List::Util qw(max);
 
+use Test::BDD::Cucumber::I18n qw(languages langdef readable_keywords keyword_to_subname);
+use Test::BDD::Cucumber::Loader;
+
 use Moose;
 has 'tags' => ( is => 'rw', isa => 'ArrayRef', required => 0 );
 has 'tag_scheme' => ( is => 'rw', isa => 'ArrayRef', required => 0 );
@@ -32,11 +35,6 @@ Steps that pass will be printed in green, those that fail in red, and those
 for which there is no step definition as yellow (for TODO), assuming you're
 using the default output harness.
 
-=cut
-
-use Test::BDD::Cucumber::Loader;
-use Module::Runtime qw(use_module);
-
 =head1 METHODS
 
 =head2 run
@@ -62,9 +60,7 @@ sub run {
     );
     die "No feature files found" unless @features;
 
-    eval { use_module($options->{'harness'}) } || die $@;
-    my $harness  = $options->{'harness'}->new();
-    $harness->startup();
+    my $harness = $self->_load_harness( $options->{'harness'} );
 
     my $tag_spec;
     if ($self->tag_scheme) {
@@ -77,6 +73,22 @@ sub run {
     return $harness->result;
 }
 
+sub _load_harness {
+    my ( $self, $harness_module ) = @_;
+
+    unless ( $harness_module =~ m/::/ ) {
+        $harness_module = "Test::BDD::Cucumber::Harness::" . $harness_module;
+    }
+
+    eval { use_module( $harness_module ) } ||
+        die "Unable to load harness [$harness_module]: $@";
+
+    my $harness = $harness_module->new();
+    $harness->startup();
+
+    return $harness;
+}
+
 sub _process_arguments {
     my ( $self, @args ) = @_;
     local @ARGV = @args;
@@ -105,8 +117,6 @@ sub _process_arguments {
 
     # Munge the output harness
     $harness //= "TermColor";
-    $harness = "Test::BDD::Cucumber::Harness::$harness" unless
-        $harness =~ m/\:\:/;
 
     lib->import(@$includes) if @$includes;
 
diff --git a/t/400_app_pherkin_harnesses.t b/t/400_app_pherkin_harnesses.t
new file mode 100644
index 0000000..217209e
--- /dev/null
+++ b/t/400_app_pherkin_harnesses.t
@@ -0,0 +1,26 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+my @known_harnesses = (
+    "Data", # Short form
+    "Test::BDD::Cucumber::Harness::TermColor", # Long form
+    "Test::BDD::Cucumber::Harness::TestBuilder"
+);
+
+use_ok("App::pherkin");
+
+for my $harness ( @known_harnesses ) {
+    my $app = App::pherkin->new();
+    my $object = $app->_load_harness( $harness );
+    isa_ok(
+        $object,
+        "Test::BDD::Cucumber::Harness",
+        "Loaded harness by name: [$harness] -> [" . (ref $object) . "]"
+    );
+}
+
+done_testing();
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libtest-bdd-cucumber-perl.git



More information about the Pkg-perl-cvs-commits mailing list