Skip to content
Browse files

Tagging 3.09, version bump

  • Loading branch information...
1 parent ea3a0fe commit 76b0815de26387f0c66ca7d7df2c6d2699e011f6 @AndyA AndyA committed Feb 10, 2008
Showing with 192 additions and 31 deletions.
  1. +3 −1 Changes
  2. +2 −1 HACKING.pod
  3. +2 −0 MANIFEST
  4. +11 −0 bin/prove
  5. +2 −3 lib/App/Prove.pm
  6. +5 −1 lib/TAP/Harness.pm
  7. +0 −7 lib/TAP/Parser.pm
  8. +8 −7 lib/TAP/Parser/Source/Perl.pm
  9. +72 −0 lib/TAP/Parser/Utils.pm
  10. +20 −10 lib/Test/Harness.pm
  11. +2 −1 t/000-load.t
  12. +65 −0 t/utils.t
View
4 Changes
@@ -1,8 +1,10 @@
Revision history for Test-Harness
-3.09 2008-02-09
+3.09 2008-02-10
- support for HARNESS_PERL_SWITCHES containing things like
'-e "system(shift)"'.
+ - set HARNESS_IS_VERBOSE during verbose testing.
+ - documentation fixes.
3.08 2008-02-08
- added support for 'out' option to
View
3 HACKING.pod
@@ -13,7 +13,8 @@ This is the guide for TAP::Harness internals contributors (developers,
testers, documenters.)
If you are looking for more information on how to I<use> TAP::Harness,
-you probably want the L<TAP::Harness::Cookbook> instead.
+you probably want
+L<http://testanything.org/wiki/index.php/TAP::Parser_Cookbook> instead.
=head1 Getting Started
View
2 MANIFEST
@@ -41,6 +41,7 @@ lib/TAP/Parser/Result/Version.pm
lib/TAP/Parser/Result/YAML.pm
lib/TAP/Parser/Source.pm
lib/TAP/Parser/Source/Perl.pm
+lib/TAP/Parser/Utils.pm
lib/TAP/Parser/YAMLish/Reader.pm
lib/TAP/Parser/YAMLish/Writer.pm
lib/Test/Harness.pm
@@ -156,6 +157,7 @@ t/streams.t
t/taint.t
t/testargs.t
t/unicode.t
+t/utils.t
t/yamlish-output.t
t/yamlish-writer.t
t/yamlish.t
View
11 bin/prove
@@ -240,6 +240,17 @@ The C<--state> switch may be used more than once.
$ prove -b --state=hot --state=all,save
+=head2 Taint Mode
+
+Normally when a Perl program is run in taint mode the contents of the
+C<PERL5LIB> environment variable do not appear in C<@INC>.
+
+Because C<PERL5LIB> is often used during testing to add build directories
+to C<@INC> prove (actually L<TAP::Parser::Source::Perl>) passes the
+names of any directories found in C<PERL5LIB> as -I switches. The net
+effect of this is that C<PERL5LIB> is honoured even when prove is run in
+taint mode.
+
=cut
# vim:ts=4:sw=4:et:sta
View
5 lib/App/Prove.pm
@@ -2,6 +2,7 @@ package App::Prove;
use strict;
use TAP::Harness;
+use TAP::Parser::Utils qw( split_shell );
use File::Spec;
use Getopt::Long;
use App::Prove::State;
@@ -462,9 +463,7 @@ sub _get_switches {
push @switches, '-w';
}
- if ( defined( my $hps = $ENV{HARNESS_PERL_SWITCHES} ) ) {
- push @switches, $hps;
- }
+ push @switches, split_shell( $ENV{HARNESS_PERL_SWITCHES} );
return @switches ? \@switches : ();
}
View
6 lib/TAP/Harness.pm
@@ -484,7 +484,7 @@ Each elements of the @tests array is either
When you supply a separate display name it becomes possible to run a
test more than once; the display name is effectively the alias by which
the test is known inside the harness. The harness doesn't care if it
-runs the same script more than once along as each invocation uses a
+runs the same script more than once when each invocation uses a
different name.
=cut
@@ -496,6 +496,10 @@ sub aggregate_tests {
my @expanded = map { 'ARRAY' eq ref $_ ? $_ : [ $_, $_ ] } @tests;
+ # #12458
+ local $ENV{HARNESS_IS_VERBOSE} = 1
+ if $self->formatter->verbosity > 0;
+
# Formatter gets only names
$self->formatter->prepare( map { $_->[1] } @expanded );
View
7 lib/TAP/Parser.pm
@@ -506,13 +506,6 @@ C<$result> object.
This is merely a synonym for C<as_string>.
-=head3 C<tests_planned>
-
- my $planned = $result->tests_planned;
-
-Returns the number of tests planned. For example, a plan of C<1..17> will
-cause this method to return '17'.
-
=head3 C<directive>
my $directive = $result->directive;
View
15 lib/TAP/Parser/Source/Perl.pm
@@ -255,13 +255,14 @@ sub _switches {
my $taint = $self->get_taint($shebang);
push @switches, "-$taint" if defined $taint;
- # Hacky bodge. We split any switches that contain a double quote
- # followed by w/s so that, e.g., '-e "print"' turns into '- e',
- # 'print', then quote each switch if there's any whitespace in it,
- # or if we're VMS, since VMS requires all parms quoted. Also, don't
- # quote it if it's already quoted.
- return map { ( ( /\s/ || IS_VMS ) && !/^".*"$/ ) ? qq["$_"] : $_ }
- map { /^(-\S+)\s+"(.*?)"$/ ? ( $1, $2 ) : ($_) } @switches;
+ # Quote the argument if there's any whitespace in it, or if
+ # we're VMS, since VMS requires all parms quoted. Also, don't quote
+ # it if it's already quoted.
+ for (@switches) {
+ $_ = qq["$_"] if ( ( /\s/ || IS_VMS ) && !/^".*"$/ );
+ }
+
+ return @switches;
}
sub _get_perl {
View
72 lib/TAP/Parser/Utils.pm
@@ -0,0 +1,72 @@
+package TAP::Parser::Utils;
+
+use strict;
+use Exporter;
+use vars qw($VERSION @ISA @EXPORT_OK);
+
+@ISA = qw( Exporter );
+@EXPORT_OK = qw( split_shell );
+
+=head1 NAME
+
+TAP::Parser::Utils - Internal TAP::Parser utilities
+
+=head1 VERSION
+
+Version 3.09
+
+=cut
+
+$VERSION = '3.09';
+
+=head1 SYNOPSIS
+
+ use TAP::Parser::Utils qw( split_shell )
+ my @switches = split_shell( $arg );
+
+=head1 DESCRIPTION
+
+B<FOR INTERNAL USE ONLY!>
+
+=head2 INTERFACE
+
+=head3 C<split_shell>
+
+Shell style argument parsing. Handles backslash escaping, single and
+double quoted strings but not shell substitutions.
+
+Pass one or more strings containing shell escaped arguments. The return
+value is an array of arguments parsed from the input strings according
+to (approximate) shell parsing rules. It's legal to pass C<undef> in
+which case an empty array will be returned. That makes it possible to
+
+ my @args = split_shell( $ENV{SOME_ENV_VAR} );
+
+without worrying about whether the environment variable exists.
+
+This is used to split HARNESS_PERL_ARGS into individual switches.
+
+=cut
+
+sub split_shell {
+ my @parts = ();
+
+ for my $switch ( grep defined && length, @_ ) {
+ push @parts, $1 while $switch =~ /
+ (
+ (?: [^\\"'\s]+
+ | \\.
+ | " (?: \\. | [^"] )* "
+ | ' (?: \\. | [^'] )* '
+ )+
+ ) /xg;
+ }
+
+ for (@parts) {
+ s/ \\(.) | ['"] /defined $1 ? $1 : ''/exg;
+ }
+
+ return @parts;
+}
+
+1;
View
30 lib/Test/Harness.pm
@@ -11,6 +11,8 @@ use TAP::Harness ();
use TAP::Parser::Aggregator ();
use TAP::Parser::Source::Perl ();
+use TAP::Parser::Utils qw( split_shell );
+
use Config;
use Exporter;
@@ -93,7 +95,8 @@ pluggable 'Straps' interface that previous versions of L<Test::Harness>
supported is not reproduced here. Straps is now available as a stand
alone module: L<Test::Harness::Straps>.
-See L<TAP::Parser> for the main documentation for this distribution.
+See L<TAP::Parser>, L<TAP::Harness> for the main documentation for this
+distribution.
=head1 FUNCTIONS
@@ -221,15 +224,10 @@ sub _canon {
sub _new_harness {
my $sub_args = shift || {};
- # TODO: $Switches is supposed to /override/ HARNESS_PERL_SWITCHES
- if ( defined( my $env_sw = $ENV{HARNESS_PERL_SWITCHES} ) ) {
- $Switches .= ' ' . $env_sw if ( length($env_sw) );
- }
-
- # This is a bit crufty. The switches have all been joined into a
- # single string so we have to try and recover them.
my ( @lib, @switches );
- for my $opt ( split( /\s+(?=-)/, $Switches ) ) {
+ for my $opt (
+ split_shell( $Switches, $ENV{HARNESS_PERL_SWITCHES} ) )
+ {
if ( $opt =~ /^ -I (.*) $ /x ) {
push @lib, $1;
}
@@ -557,6 +555,17 @@ Multiple options may be separated by colons:
=back
+=head1 Taint Mode
+
+Normally when a Perl program is run in taint mode the contents of the
+C<PERL5LIB> environment variable do not appear in C<@INC>.
+
+Because C<PERL5LIB> is often used during testing to add build
+directories to C<@INC> C<Test::Harness> (actually
+L<TAP::Parser::Source::Perl>) passes the names of any directories found
+in C<PERL5LIB> as -I switches. The net effect of this is that
+C<PERL5LIB> is honoured even in taint mode.
+
=head1 SEE ALSO
L<TAP::Harness>
@@ -573,7 +582,8 @@ as I make changes.
Andy Armstrong C<< <andy@hexten.net> >>
-L<Test::Harness> (on which this module is based) has this attribution:
+L<Test::Harness> 2.64 (maintained by Andy Lester and on which this
+module is based) has this attribution:
Either Tim Bunce or Andreas Koenig, we don't know. What we know for
sure is, that it was inspired by Larry Wall's F<TEST> script that came
View
3 t/000-load.t
@@ -3,7 +3,7 @@
use strict;
use lib 't/lib';
-use Test::More tests => 58;
+use Test::More tests => 60;
BEGIN {
@@ -37,6 +37,7 @@ BEGIN {
TAP::Parser::Source
TAP::Parser::YAMLish::Reader
TAP::Parser::YAMLish::Writer
+ TAP::Parser::Utils
Test::Harness
);
View
65 t/utils.t
@@ -0,0 +1,65 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+ chdir 't' and @INC = '../lib' if $ENV{PERL_CORE};
+}
+
+use strict;
+use lib 't/lib';
+
+use TAP::Parser::Utils qw( split_shell );
+use Test::More;
+
+my @schedule = (
+ { name => 'Bare words',
+ in => 'bare words are here',
+ out => [ 'bare', 'words', 'are', 'here' ],
+ },
+ { name => 'Single quotes',
+ in => "'bare' 'words' 'are' 'here'",
+ out => [ 'bare', 'words', 'are', 'here' ],
+ },
+ { name => 'Double quotes',
+ in => '"bare" "words" "are" "here"',
+ out => [ 'bare', 'words', 'are', 'here' ],
+ },
+ { name => 'Escapes',
+ in => '\ "ba\"re" \'wo\\\'rds\' \\\\"are" "here"',
+ out => [ ' ', 'ba"re', "wo'rds", '\\are', 'here' ],
+ },
+ { name => 'Flag',
+ in => '-e "system(shift)"',
+ out => [ '-e', 'system(shift)' ],
+ },
+ { name => 'Nada',
+ in => undef,
+ out => [],
+ },
+ { name => 'Nada II',
+ in => '',
+ out => [],
+ },
+ { name => 'Zero',
+ in => 0,
+ out => ['0'],
+ },
+ { name => 'Empty',
+ in => '""',
+ out => [''],
+ },
+ { name => 'Empty II',
+ in => "''",
+ out => [''],
+ },
+);
+
+plan tests => 1 * @schedule;
+
+for my $test (@schedule) {
+ my $name = $test->{name};
+ my @got = split_shell( $test->{in} );
+ unless ( is_deeply \@got, $test->{out}, "$name: parse OK" ) {
+ use Data::Dumper;
+ diag( Dumper( { want => $test->{out}, got => \@got } ) );
+ }
+}

0 comments on commit 76b0815

Please sign in to comment.
Something went wrong with that request. Please try again.