/usr/share/perl5/App/pherkin.pm is in libtest-bdd-cucumber-perl 0.17-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | package App::pherkin;
{
$App::pherkin::VERSION = '0.17';
}
use strict;
use warnings;
use FindBin::libs;
use Getopt::Long;
use Moose;
has 'tags' => ( is => 'rw', isa => 'ArrayRef', required => 0 );
has 'tag_scheme' => ( is => 'rw', isa => 'ArrayRef', required => 0 );
=head1 NAME
App::pherkin - Run Cucumber tests from the command line
=head1 VERSION
version 0.17
=head1 SYNOPSIS
pherkin
pherkin some/path/features/
=head1 DESCRIPTION
C<pherkin> will search the directory specified (or C<./features/>) for
feature files (any file matching C<*.feature>) and step definition files (any
file matching C<*_steps.pl>), loading the step definitions and then executing
the features.
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;
=head1 METHODS
=head2 run
The C<App::pherkin> class, which is what the C<pherkin> command uses, makes
use of the C<run()> method, which accepts currently a single path as a string,
or nothing.
Returns a L<Test::BDD::Cucumber::Model::Result> object for all steps run.
=cut
sub run {
my ( $self, @arguments ) = @_;
my ($options, @feature_files) = $self->_process_arguments(@arguments);
my ( $executor, @features ) = Test::BDD::Cucumber::Loader->load(
$feature_files[0] || './features/', $self->tag_scheme
);
die "No feature files found" unless @features;
eval "require $options->{'harness'}" || die $@;
my $harness = $options->{'harness'}->new();
$harness->startup();
my $tag_spec;
if ($self->tag_scheme) {
$tag_spec = Test::BDD::Cucumber::Model::TagSpec->new({ tags => $self->tag_scheme });
}
$executor->execute( $_, $harness, $tag_spec ) for @features;
$harness->shutdown();
return $harness->result;
}
sub _process_arguments {
my ( $self, @args ) = @_;
local @ARGV = @args;
# Allow -Ilib, -bl
Getopt::Long::Configure('bundling');
my $includes = [];
my $tags = [];
GetOptions(
'I=s@' => \$includes,
'l|lib' => \(my $add_lib),
'b|blib' => \(my $add_blib),
'o|output=s' => \(my $harness),
't|tags=s@' => \$tags,
);
unshift @$includes, 'lib' if $add_lib;
unshift @$includes, 'blib/lib', 'blib/arch' if $add_blib;
# Munge the output harness
$harness //= "TermColor";
$harness = "Test::BDD::Cucumber::Harness::$harness" unless
$harness =~ m/\:\:/;
lib->import(@$includes) if @$includes;
# Store our TagSpecScheme
$self->tag_scheme( $self->_process_tags( @{$tags} ) );
return ({ harness => $harness }, @ARGV);
}
sub _process_tags {
my ( $self, @tags ) = @_;
# This is a bit faffy and possibly suboptimal.
my $tag_scheme = [];
my @ands = ();
# Iterate over our commandline tag strings.
foreach my $tag (@tags) {
my @parts = ();
foreach my $part (split(',', $tag)) {
# Trim any @ or ~@ from the front of the tag
$part =~ s/^(~?)@//;
# ~@tag => "NOT tag" => [ not => tag ]
if (defined $1 and $1 eq '~') {
push @parts, [ not => $part ];
} else {
push @parts, $part;
}
}
# @tag,@cow => "@tag OR @cow" => [ or => tag, cow ]
# (It's simpler to always stick an 'or' on the front.)
push @ands, [ or => @parts ];
}
# -t @tag -t @cow => "@tag AND @cow" => [ and => tag, cow ]
# (It's simpler to always stick an 'and' on the front.)
$tag_scheme = [ and => @ands ];
return $tag_scheme;
}
=head1 AUTHOR
Peter Sergeant C<pete@clueball.com>
=head1 LICENSE
Copyright 2011, Peter Sergeant; Licensed under the same terms as Perl
=cut
1;
|