| 1 | package Test::Pcuke; | ||||||||||||
| 2 | |||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | 2 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 2 | ▶ | use Encode qw{encode}; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 2 | ▶ | use Test::Pcuke::Gherkin; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 2 | ▶ | use Test::Pcuke::Gherkin::I18n; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | 2 | ▶ | use Test::Pcuke::Report; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 2 | ▶ | use Test::Pcuke::Executor; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 2 | ▶ | use File::Find; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | =head1 NAME | ||||||||||||
| 17 | |||||||||||||
| 18 | Test::Pcuke - Cucumber for Perl 5 | ||||||||||||
| 19 | |||||||||||||
| 20 | =head1 VERSION | ||||||||||||
| 21 | |||||||||||||
| 22 | Version 0.0.4 | ||||||||||||
| 23 | |||||||||||||
| 24 | =cut | ||||||||||||
| 25 | |||||||||||||
| 26 | 2 | our $VERSION = '0.000006'; | |||||||||||
| 27 | |||||||||||||
| 28 | |||||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||||
| 30 | |||||||||||||
| 31 | Provides functionality for the pcuke command which is an implementation | ||||||||||||
| 32 | of cucumber in Perl 5, and the command itself | ||||||||||||
| 33 | |||||||||||||
| 34 | If you are interested in pcuke command, please read L<Test::Pcuke::Manual> | ||||||||||||
| 35 | |||||||||||||
| 36 | B<There are some bugs lurking around. Please report if you find any!> | ||||||||||||
| 37 | |||||||||||||
| 38 | use Test::Pcuke; | ||||||||||||
| 39 | |||||||||||||
| 40 | my $conf = { ... }; | ||||||||||||
| 41 | my $runner = Test::Pcuke->new( $config ); | ||||||||||||
| 42 | |||||||||||||
| 43 | $runner->run(); | ||||||||||||
| 44 | |||||||||||||
| 45 | As to v. 0.0.2 only utf-8 encoding is supported! | ||||||||||||
| 46 | |||||||||||||
| 47 | To see the list of languages that pcuke supports use a command: | ||||||||||||
| 48 | |||||||||||||
| 49 | $ pcuke --i18n help | ||||||||||||
| 50 | |||||||||||||
| 51 | To see the information on a language, 'ru' for example, use: | ||||||||||||
| 52 | |||||||||||||
| 53 | $ pcuke --i18n ru | ||||||||||||
| 54 | |||||||||||||
| 55 | |||||||||||||
| 56 | |||||||||||||
| 57 | =head1 METHODS | ||||||||||||
| 58 | |||||||||||||
| 59 | =head2 new $conf | ||||||||||||
| 60 | |||||||||||||
| 61 | Creates an instance of Test::Pcuke, a I<runner>. | ||||||||||||
| 62 | |||||||||||||
| 63 | =cut | ||||||||||||
| 64 | |||||||||||||
| 65 | 1 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 66 | 1 | my ($class, $args) = @_; | |||||||||||
| 67 | |||||||||||||
| 68 | 1 | my $conf = $class->_translate_cmdline_args( $args ); | |||||||||||
| 69 | |||||||||||||
| 70 | 1 | bless $conf, $class; | |||||||||||
| 71 | |||||||||||||
| 72 | 1 | return $conf; | |||||||||||
| 73 | } | ||||||||||||
| 74 | |||||||||||||
| 75 | 1 | ▶ | sub _translate_cmdline_args { | ||||||||||
|
Subroutine
_translate_cmdline_args: called CC=4 SCAR=17.2
| |||||||||||||
| 76 | 1 | my ($class, $args) = @_; | |||||||||||
| 77 | 1 | my $conf = { | |||||||||||
| 78 | encoding => 'utf8' | ||||||||||||
| 79 | }; | ||||||||||||
| 80 | |||||||||||||
| 81 | 0 | ▶ | my @keys = map { ( /^--([-\w]+)$/ ) ? ($1) : () } keys %$args; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 82 | 1 | foreach ( @keys ) { | |||||||||||
| 83 | 0 | $conf->{$_} = $args->{"--$_"}; | |||||||||||
| 84 | } | ||||||||||||
| 85 | |||||||||||||
| 86 | 1 | ▶ | if ( $args->{'<filename>'} ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 87 | 0 | $conf->{features} = $args->{'<filename>'}; | |||||||||||
| 88 | } | ||||||||||||
| 89 | |||||||||||||
| 90 | 1 | return $conf; | |||||||||||
| 91 | } | ||||||||||||
| 92 | |||||||||||||
| 93 | =head2 run | ||||||||||||
| 94 | |||||||||||||
| 95 | Starts the process | ||||||||||||
| 96 | |||||||||||||
| 97 | =cut | ||||||||||||
| 98 | |||||||||||||
| 99 | 0 | ▶ | sub run { | ||||||||||
|
Subroutine
run: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||
| 100 | 0 | my ($self) = @_; | |||||||||||
| 101 | 0 | my $features; | |||||||||||
| 102 | |||||||||||||
| 103 | 0 | ▶ | return $self->i18n() if $self->{i18n}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 104 | |||||||||||||
| 105 | 0 | $self->{_executor} = Test::Pcuke::Executor->new( $self->{encoding} ); | |||||||||||
| 106 | |||||||||||||
| 107 | 0 | $self->load_step_definitions(); | |||||||||||
| 108 | 0 | $self->process_features(); | |||||||||||
| 109 | |||||||||||||
| 110 | my $report = Test::Pcuke::Report->new( | ||||||||||||
| 111 | features => $self->{_executed_features}, | ||||||||||||
| 112 | 0 | ); | |||||||||||
| 113 | |||||||||||||
| 114 | 0 | my $output = $report->build(); | |||||||||||
| 115 | |||||||||||||
| 116 | $output = encode($self->{encoding}, $output) | ||||||||||||
| 117 | 0 | ▶ | if $self->{encoding}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 118 | |||||||||||||
| 119 | 0 | print $output; | |||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | 0 | ▶ | sub i18n { | ||||||||||
|
Subroutine
i18n: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 123 | 0 | my ($self) = @_; | |||||||||||
| 124 | |||||||||||||
| 125 | 0 | ▶ | if ( my $lang = $self->{i18n} =~ /^help$/i ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 126 | print join "\n", map { | ||||||||||||
| 127 | 0 | Encode::encode($self->{encoding},$_) | |||||||||||
| 128 | 0 | } @{ Test::Pcuke::Gherkin::I18n->languages }, "\n"; | |||||||||||
| 129 | } | ||||||||||||
| 130 | else { | ||||||||||||
| 131 | 0 | my $info = Test::Pcuke::Gherkin::I18n->language_info( $self->{i18n} ); | |||||||||||
| 132 | 0 | foreach (@$info) { | |||||||||||
| 133 | print join( " -> ", | ||||||||||||
| 134 | Encode::encode($self->{encoding}, $_->[0]), | ||||||||||||
| 135 | 0 | Encode::encode($self->{encoding}, $_->[1]) | |||||||||||
| 136 | ),"\n"; | ||||||||||||
| 137 | } | ||||||||||||
| 138 | } | ||||||||||||
| 139 | } | ||||||||||||
| 140 | |||||||||||||
| 141 | 0 | ▶ | sub executor { $_[0]->{_executor} } | ||||||||||
|
Subroutine
executor: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 142 | |||||||||||||
| 143 | 0 | ▶ | sub process_features { | ||||||||||
|
Subroutine
process_features: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 144 | 0 | my ($self) = @_; | |||||||||||
| 145 | 0 | my $files; | |||||||||||
| 146 | |||||||||||||
| 147 | 0 | ▶ | if ( ref $self->{features} eq 'ARRAY') { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 148 | 0 | $files = $self->{features}; | |||||||||||
| 149 | } | ||||||||||||
| 150 | else { | ||||||||||||
| 151 | 0 | $files = $self->scan_dir('features'); | |||||||||||
| 152 | } | ||||||||||||
| 153 | |||||||||||||
| 154 | 0 | foreach ( @$files ) { | |||||||||||
| 155 | 0 | my $content = $self->get_file_content($_); | |||||||||||
| 156 | 0 | my $feature = Test::Pcuke::Gherkin->compile($content, $self->executor); | |||||||||||
| 157 | 0 | $feature->execute; | |||||||||||
| 158 | 0 | $self->collect_feature($feature); | |||||||||||
| 159 | } | ||||||||||||
| 160 | } | ||||||||||||
| 161 | |||||||||||||
| 162 | |||||||||||||
| 163 | 0 | ▶ | sub get_file_content { | ||||||||||
|
Subroutine
get_file_content: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 164 | 0 | my ($self, $fn) = @_; | |||||||||||
| 165 | |||||||||||||
| 166 | 0 | ▶ | my $encoding = $self->{encoding} || 'utf-8'; | ||||||||||
|
Condition0%0/2
$self->{'encoding'} || 'utf-8'
MC/DC0%0/1
$self->{'encoding'} || 'utf-8'
$self->{'encoding'}
Truth table0%0/2
A
A= $self->{'encoding'}
| |||||||||||||
| 167 | |||||||||||||
| 168 | 0 | local $/; | |||||||||||
| 169 | |||||||||||||
| 170 | 0 | my ($fh, $content); | |||||||||||
| 171 | |||||||||||||
| 172 | 0 | ▶ | open( $fh, "<:encoding($encoding)", $fn ) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 173 | or confess "Can't open $fn for reading"; | ||||||||||||
| 174 | 0 | $content = <$fh>; | |||||||||||
| 175 | 0 | close $fh; | |||||||||||
| 176 | |||||||||||||
| 177 | 0 | return $content; | |||||||||||
| 178 | } | ||||||||||||
| 179 | |||||||||||||
| 180 | 0 | ▶ | sub scan_dir { | ||||||||||
|
Subroutine
scan_dir: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 181 | 0 | my ($self, $dir) = @_; | |||||||||||
| 182 | 0 | ▶ | $dir ||= 'features'; | ||||||||||
|
Condition0%0/2
$dir ||= "features"
MC/DC0%0/1
$dir ||= "features"
$dir
Truth table0%0/2
A
A= $dir
| |||||||||||||
| 183 | |||||||||||||
| 184 | 0 | my $files; | |||||||||||
| 185 | |||||||||||||
| 186 | 0 | ▶ | find( sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 187 | 0 | ▶ | return unless /\.feature$/i; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 188 | 0 | push @$files, $File::Find::name; | |||||||||||
| 189 | 0 | }, $dir ); | |||||||||||
| 190 | |||||||||||||
| 191 | 0 | return $files; | |||||||||||
| 192 | } | ||||||||||||
| 193 | |||||||||||||
| 194 | 0 | ▶ | sub collect_feature { | ||||||||||
|
Subroutine
collect_feature: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 195 | 0 | my ($self, $feature) = @_; | |||||||||||
| 196 | 0 | push @{ $self->{_executed_features} }, $feature; | |||||||||||
| 197 | } | ||||||||||||
| 198 | |||||||||||||
| 199 | 0 | ▶ | sub load_step_definitions { | ||||||||||
|
Subroutine
load_step_definitions: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||
| 200 | 0 | my ($self) = @_; | |||||||||||
| 201 | 0 | ▶ | my $dir ||= 'features'; | ||||||||||
|
Condition0%0/2
my $dir ||= "features"
MC/DC0%0/1
my $dir ||= "features"
my $dir
Truth table0%0/2
A
A= my $dir
| |||||||||||||
| 202 | |||||||||||||
| 203 | 0 | my @step_definitions = (); | |||||||||||
| 204 | |||||||||||||
| 205 | 0 | ▶ | find( sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 206 | 0 | ▶ | push @step_definitions, $File::Find::name | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 207 | if /\.pm$/i; | ||||||||||||
| 208 | 0 | }, $dir ); | |||||||||||
| 209 | |||||||||||||
| 210 | 0 | foreach (@step_definitions) { | |||||||||||
| 211 | 0 | require "$_"; | |||||||||||
| 212 | } | ||||||||||||
| 213 | |||||||||||||
| 214 | } | ||||||||||||
| 215 | |||||||||||||
| 216 | 2 | 1; # End of Test::Pcuke | |||||||||||
| 217 | __END__ | ||||||||||||