Upgrade to Test::Harness 2.24.
Jarkko Hietaniemi [Fri, 31 May 2002 01:54:38 +0000 (01:54 +0000)]
p4raw-id: //depot/perl@16914

lib/Test/Harness.pm
lib/Test/Harness/Changes
lib/Test/Harness/Straps.pm
lib/Test/Harness/t/callback.t
lib/Test/Harness/t/strap-analyze.t
lib/Test/Harness/t/test-harness.t
t/lib/sample-tests/die
t/lib/sample-tests/skip_nomsg [new file with mode: 0644]
t/lib/sample-tests/skipall [new file with mode: 0644]
t/lib/sample-tests/skipall_nomsg [new file with mode: 0644]

index be04797..4714f77 100644 (file)
@@ -1,5 +1,5 @@
 # -*- Mode: cperl; cperl-indent-level: 4 -*-
-# $Id: Harness.pm,v 1.31 2002/05/18 20:19:06 schwern Exp $
+# $Id: Harness.pm,v 1.33 2002/05/29 23:02:48 schwern Exp $
 
 package Test::Harness;
 
@@ -22,7 +22,7 @@ use vars qw($VERSION $Verbose $Switches $Have_Devel_Corestack $Curtest
 
 $Have_Devel_Corestack = 0;
 
-$VERSION = '2.23';
+$VERSION = '2.24';
 
 $ENV{HARNESS_ACTIVE} = 1;
 
@@ -159,13 +159,6 @@ emitted if the test script is skipped completely:
 
   1..0 # Skipped: no leverage found
 
-If you don't have any comment on skipping, just print C<1..0> with 
-nothing after it. Test::Harness will say something like this:
-
-op/64bitint..............skipped
-       skipped: no reason given
-       
-
 =item B<Todo tests>
 
 If the standard output line contains the substring C< # TODO> after
@@ -462,7 +455,8 @@ sub _run_all_tests {
         $tot{files}++;
 
         $Strap->{_seen_header} = 0;
-        my %results = $Strap->analyze_file($tfile);
+        my %results = $Strap->analyze_file($tfile) or
+          do { warn "$Strap->{error}\n";  next };
 
         # state of the current test.
         my @failed = grep { !$results{details}[$_-1]{ok} }
@@ -502,11 +496,11 @@ sub _run_all_tests {
                 print "$test{ml}ok\n        ".join(', ', @msg)."\n";
             } elsif ($test{max}) {
                 print "$test{ml}ok\n";
-            } elsif (defined $test{skip_all}) {
+            } elsif (length $test{skip_all}) {
                 print "skipped\n        all skipped: $test{skip_all}\n";
                 $tot{skipped}++;
             } else {
-                print "\n        skipped test on this platform\n";
+                print "skipped\n        all skipped: no reason given\n";
                 $tot{skipped}++;
             }
             $tot{good}++;
index 1a24f94..03eaab3 100644 (file)
@@ -1,5 +1,11 @@
 Revision history for Perl extension Test::Harness
 
+2.24  Wed May 29 19:02:18 EDT 2002
+    * Nikola Knezevic found a bug when tests are completely skipped
+      but no reason is given it was considered a failure.
+    * Made Test::Harness::Straps->analyze_file & Test::Harness a bit
+      more graceful when the test doesn't exist.
+
 2.23  Wed May 22 12:59:47 EDT 2002
     - reason for all skip wasn't being displayed.  Broken in 2.20.
     - Changed the wait status tests to conform with POSIX standards.
index aff5735..d19239f 100644 (file)
@@ -1,12 +1,12 @@
 # -*- Mode: cperl; cperl-indent-level: 4 -*-
-# $Id: Straps.pm,v 1.6 2002/05/17 23:04:11 schwern Exp $
+# $Id: Straps.pm,v 1.8 2002/05/29 23:02:48 schwern Exp $
 
 package Test::Harness::Straps;
 
 use strict;
 use vars qw($VERSION);
 use Config;
-$VERSION = '0.11';
+$VERSION = '0.12';
 
 use Test::Harness::Assert;
 use Test::Harness::Iterator;
@@ -150,7 +150,7 @@ sub _analyze_iterator {
 
     $totals{skip_all} = $self->{skip_all} if defined $self->{skip_all};
 
-    my $passed = $totals{skip_all} || 
+    my $passed = !$totals{max} ||
                   ($totals{max} && $totals{seen} &&
                    $totals{max} == $totals{seen} && 
                    $totals{max} == $totals{ok});
@@ -257,6 +257,16 @@ results.  It will also use that name for the total report.
 sub analyze_file {
     my($self, $file) = @_;
 
+    unless( -e $file ) {
+        $self->{error} = "$file does not exist";
+        return;
+    }
+
+    unless( -r $file ) {
+        $self->{error} = "$file is not readable";
+        return;
+    }
+
     local $ENV{PERL5LIB} = $self->_INC2PERL5LIB;
 
     # Is this necessary anymore?
@@ -315,8 +325,11 @@ sub _switches {
     my $s = '';
     $s .= " $ENV{'HARNESS_PERL_SWITCHES'}"
       if exists $ENV{'HARNESS_PERL_SWITCHES'};
-    $s .= qq[ "-$1" ] if $first =~ /^#!.*\bperl.*\s-\w*([Tt]+)/;
-    $s .= join " ", map {qq["-I$_"]} $self->_filtered_INC;
+
+    # When taint mode is on, PERL5LIB is ignored.  So we need to put
+    # all that on the command line as -Is.
+    $s .= join " ", qq[ "-$1"], map {qq["-I$_"]} $self->_filtered_INC
+      if $first =~ /^#!.*\bperl.*\s-\w*([Tt]+)/;
 
     close(TEST) or print "can't close $file. $!\n";
 
@@ -443,7 +456,8 @@ sub _is_header {
     if( my($max, $extra) = $line =~ /^1\.\.(\d+)(.*)/ ) {
         $self->{max}  = $max;
         assert( $self->{max} >= 0,  'Max # of tests looks right' );
-       if( defined $extra ) {
+
+        if( defined $extra ) {
             my($todo, $skip, $reason) = $extra =~ /$Extra_Header_Re/xo;
 
             $self->{todo} = { map { $_ => 1 } split /\s+/, $todo } if $todo;
index 65de524..0537f91 100644 (file)
@@ -10,11 +10,7 @@ BEGIN {
     }
 }
 
-use File::Spec::Functions;
-
-my $SAMPLE_TESTS = $ENV{PERL_CORE}
-    ? catdir(curdir(), 'lib', 'sample-tests')
-    : catdir(curdir(), 't', 'sample-tests');
+my $SAMPLE_TESTS = $ENV{PERL_CORE} ? 'lib/sample-tests' : 't/sample-tests';
 
 use Test::More;
 
@@ -32,8 +28,9 @@ use Test::More;
             simple      => [qw( header test test test test test )],
             simple_fail => [qw( header test test test test test )],
             'skip'      => [qw( header test test test test test )],
-            skip_all    => [qw( header )],
-            skip_no_msg => [qw( header test )],
+            skipall     => [qw( header )],
+            skipall_nomsg => [qw( header )],
+            skip_nomsg  => [qw( header test )],
             taint       => [qw( header test )],
             'todo'      => [qw( header test test test test test )],
             todo_inline => [qw( header test test test )],
@@ -53,7 +50,7 @@ $strap->{callback} = sub {
                             
 while( my($test, $expect) = each %samples ) {
     local @out = ();
-    $strap->analyze_file(catfile($SAMPLE_TESTS, $test));
+    $strap->analyze_file("$SAMPLE_TESTS/$test");
 
     is_deeply(\@out, $expect,   "$test callback");
 }
index 60ecb0d..7ebbf35 100644 (file)
@@ -10,19 +10,11 @@ BEGIN {
     }
 }
 
-use File::Spec::Functions;
-
-my $SAMPLE_TESTS = $ENV{PERL_CORE}
-    ? catdir(curdir(), 'lib', 'sample-tests')
-    : catdir(curdir(), 't', 'sample-tests');
+my $SAMPLE_TESTS = $ENV{PERL_CORE} ? 'lib/sample-tests' : 't/sample-tests';
 
 use strict;
 use Test::More;
 
-if ($^O eq 'MacOS') {
-    plan skip_all => "Exit status broken on Mac OS";
-}
-
 my $IsVMS = $^O eq 'VMS';
 
 # VMS uses native, not POSIX, exit codes.
@@ -239,7 +231,28 @@ my %samples = (
                                        ]
                        },
 
-   skip_all           => {
+   'skip_nomsg'     => {
+                        passing     => 1,
+
+                        'exit'      => 0,
+                        'wait'      => 0,
+
+                        max         => 1,
+                        seen        => 1,
+
+                        'ok'          => 1,
+                        'todo'        => 0,
+                        'skip'        => 1,
+                        bonus       => 0,
+
+                        details     => [ { 'ok'   => 1, actual_ok => 1,
+                                           type   => 'skip',
+                                           reason => '',
+                                         },
+                                       ]
+                       },
+
+   skipall           => {
                           passing   => 1,
 
                           'exit'    => 0,
@@ -257,6 +270,23 @@ my %samples = (
                           details   => [],
                          },
 
+   skipall_nomsg    => {
+                          passing   => 1,
+
+                          'exit'    => 0,
+                          'wait'    => 0,
+
+                          max       => 0,
+                          seen      => 0,
+
+                          'ok'      => 0,
+                          'todo'    => 0,
+                          'skip'    => 0,
+                          bonus     => 0,
+
+                          details   => [],
+                         },
+
    'todo'             => {
                         passing     => 1,
 
@@ -406,7 +436,7 @@ my %samples = (
                        },
 );
 
-plan tests => (keys(%samples) * 3) + 1;
+plan tests => (keys(%samples) * 3) + 3;
 
 use_ok('Test::Harness::Straps');
 
@@ -425,7 +455,7 @@ while( my($test, $expect) = each %samples ) {
     }
 
     my $strap = Test::Harness::Straps->new;
-    my %results = $strap->analyze_file(catfile($SAMPLE_TESTS, $test));
+    my %results = $strap->analyze_file("$SAMPLE_TESTS/$test");
 
     is_deeply($results{details}, $expect->{details}, "$test details" );
 
@@ -439,3 +469,8 @@ while( my($test, $expect) = each %samples ) {
 
     is_deeply(\%results, $expect, "  the rest $test" );
 }
+
+
+my $strap = Test::Harness::Straps->new;
+ok( !$strap->analyze_file('I_dont_exist') );
+is( $strap->{error}, "I_dont_exist does not exist" );
index d061059..c428e85 100644 (file)
@@ -10,11 +10,7 @@ BEGIN {
     }
 }
 
-use File::Spec::Functions;
-
-my $SAMPLE_TESTS = $ENV{PERL_CORE}
-    ? catdir(curdir(), 'lib', 'sample-tests')
-    : catdir(curdir(), 't', 'sample-tests');
+my $SAMPLE_TESTS = $ENV{PERL_CORE} ? "lib/sample-tests" : "t/sample-tests";
 
 use strict;
 
@@ -40,10 +36,9 @@ package main;
 use Test::More;
 
 my $IsVMS = $^O eq 'VMS';
-my $IsMacOS = $^O eq 'MacOS';
 
 # VMS uses native, not POSIX, exit codes.
-my $die_estat = $IsVMS ? 44 : $IsMacOS ? 0 : 1;
+my $die_estat = $IsVMS ? 44 : 1;
 
 my %samples = (
             simple            => {
@@ -162,6 +157,22 @@ my %samples = (
                                   failed => { },
                                   all_ok => 1,
                                  },
+            'skip_nomsg'      => {
+                                  total => {
+                                            bonus      => 0,
+                                            max        => 1,
+                                            'ok'       => 1,
+                                            files      => 1,
+                                            bad        => 0,
+                                            good       => 1,
+                                            tests      => 1,
+                                            sub_skipped=> 1,
+                                            'todo'     => 0,
+                                            skipped    => 0,
+                                           },
+                                  failed => { },
+                                  all_ok => 1,
+                                 },
             bailout           => 0,
             combined          => {
                                   total => {
@@ -233,7 +244,23 @@ my %samples = (
                                             },
                                   all_ok => 0,
                                  },
-            skip_all          => {
+            skipall          => {
+                                  total => {
+                                            bonus      => 0,
+                                            max        => 0,
+                                            'ok'       => 0,
+                                            files      => 1,
+                                            bad        => 0,
+                                            good       => 1,
+                                            tests      => 1,
+                                            sub_skipped=> 0,
+                                            'todo'     => 0,
+                                            skipped    => 1,
+                                           },
+                                  failed => { },
+                                  all_ok => 1,
+                                 },
+            skipall_nomsg   => {
                                   total => {
                                             bonus      => 0,
                                             max        => 0,
@@ -399,7 +426,7 @@ while (my($test, $expect) = each %samples) {
         select NULL;    # _run_all_tests() isn't as quiet as it should be.
         local $SIG{__WARN__} = sub { $warning .= join '', @_; };
         ($totals, $failed) = 
-          Test::Harness::_run_all_tests(catfile($SAMPLE_TESTS, $test));
+          Test::Harness::_run_all_tests("$SAMPLE_TESTS/$test");
     };
     select STDOUT;
 
@@ -417,7 +444,7 @@ while (my($test, $expect) = each %samples) {
         is_deeply( {map { $_=>$totals->{$_} } keys %{$expect->{total}}},
                    $expect->{total},
                                                   "$test - totals" );
-        is_deeply( {map { $_=>$failed->{catfile($SAMPLE_TESTS, $test)}{$_} }
+        is_deeply( {map { $_=>$failed->{"$SAMPLE_TESTS/$test"}{$_} }
                     keys %{$expect->{failed}}},
                    $expect->{failed},
                                                   "$test - failed" );
index ffd8e88..4c85340 100644 (file)
@@ -1,3 +1,2 @@
-use lib 'lib';
 use if ($^O eq 'VMS'), vmsish => 'hushed';
 exit 1;  # exit because die() can be noisy
diff --git a/t/lib/sample-tests/skip_nomsg b/t/lib/sample-tests/skip_nomsg
new file mode 100644 (file)
index 0000000..51d1ed6
--- /dev/null
@@ -0,0 +1,4 @@
+print <<DUMMY;
+1..1
+ok 1 # Skip
+DUMMY
diff --git a/t/lib/sample-tests/skipall b/t/lib/sample-tests/skipall
new file mode 100644 (file)
index 0000000..8c46796
--- /dev/null
@@ -0,0 +1,3 @@
+print <<DUMMY_TEST;
+1..0 # skip: rope
+DUMMY_TEST
diff --git a/t/lib/sample-tests/skipall_nomsg b/t/lib/sample-tests/skipall_nomsg
new file mode 100644 (file)
index 0000000..9b0dc11
--- /dev/null
@@ -0,0 +1,2 @@
+print "1..0\n";
+exit 0;