In perl.git, the branch blead has been updated <http://perl5.git.perl.org/perl.git/commitdiff/bcf53fae4530fa696a6f26dd100207c224a13e89?hp=caedc70ba6260eef7c753adf315b14a90252192d>
- Log ----------------------------------------------------------------- commit bcf53fae4530fa696a6f26dd100207c224a13e89 Author: Nicholas Clark <[email protected]> Date: Sun Mar 6 22:42:22 2011 +0000 Ensure that t/io/{print,read,say}.t load Errno at BEGIN time. If Errno is loaded after the compiler has parsed the C<exists &Errno::EBADF> later in the script, then the intent of that test is subverted - &Errno::EBADF does not exist, at least as far as the typeglob bound to that op is concerned, and the test for $! is skipped. I suspect that these have been skipping since the implementation of Errno was changed in 42607a60df6df19b in May 2010 to reduce its memory footprint by 55%. M t/io/print.t M t/io/read.t M t/io/say.t commit bad1036f7c06bd513a9312c5265dcaa0e82dd8b3 Author: Nicholas Clark <[email protected]> Date: Sun Mar 6 22:14:23 2011 +0000 Tidy perlio_open.t, by using test.pl skip_all* functions where appropriate. This reduces the startup boilerplate code by more than half. M t/io/perlio_open.t commit 7465bc322e5c5dcbd256bb5fbdd3135163fb3dc1 Author: Nicholas Clark <[email protected]> Date: Sun Mar 6 21:58:19 2011 +0000 Add skip_all_without_extension() to test.pl, for the common skip idiom. Use it in t/io/layers.t to skip if Encode is not built. M t/io/layers.t M t/test.pl commit 21da8bce185d89ceb57f48bde4bcb5679ce4d106 Author: Nicholas Clark <[email protected]> Date: Sun Mar 6 21:41:01 2011 +0000 Tidy t/io/layers.t Skip under minitest using skip_all_if_miniperl(). skip_all() once rather than skipping every test if Encode is not built, or PerlIO is not available. M t/io/layers.t commit bd1869dca4d5c5a05da6fe5ec612a3f53b18c6ea Author: Nicholas Clark <[email protected]> Date: Sun Mar 6 21:25:47 2011 +0000 Tidy t/io/crlf.t Skip a test under minitest using skip_if_miniperl(). Use eq(), like() and unlike() where appropriate, instead of ok(). M t/io/crlf.t commit 3d27376121e12fdf0629aa994dc7d07910a5606d Author: Nicholas Clark <[email protected]> Date: Sun Mar 6 21:21:10 2011 +0000 Tidy t/io/binmode.t Remove redundant C<use Config;> If C<find PerlIO::Layer 'perlio'> fails, use skip() rather than ok() to skip. Make the indenting on 2 inconsistent lines consistent with the rest of the file. Die if Errno can't be loaded, unless it's miniperl. M t/io/binmode.t ----------------------------------------------------------------------- Summary of changes: t/io/binmode.t | 28 +++++++++++++--------------- t/io/crlf.t | 9 ++++----- t/io/layers.t | 21 ++++++--------------- t/io/perlio_open.t | 16 +++------------- t/io/print.t | 5 +++-- t/io/read.t | 4 ++-- t/io/say.t | 6 +++--- t/test.pl | 10 ++++++++++ 8 files changed, 44 insertions(+), 55 deletions(-) diff --git a/t/io/binmode.t b/t/io/binmode.t index 41eff4a..473261e 100644 --- a/t/io/binmode.t +++ b/t/io/binmode.t @@ -4,39 +4,37 @@ BEGIN { chdir 't' if -d 't'; @INC = qw(. ../lib); require './test.pl'; + eval 'use Errno'; + die $@ if $@ and !is_miniperl(); } -use Config; -BEGIN { - eval {require Errno; Errno->import;}; -} + plan(tests => 9); ok( binmode(STDERR), 'STDERR made binary' ); -if (find PerlIO::Layer 'perlio') { - ok( binmode(STDERR, ":unix"), ' with unix discipline' ); -} else { - ok(1, ' skip unix discipline without PerlIO layers' ); +SKIP: { + skip('skip unix discipline without PerlIO layers', 1) + unless find PerlIO::Layer 'perlio'; + ok( binmode(STDERR, ":unix"), ' with unix discipline' ); } ok( binmode(STDERR, ":raw"), ' raw' ); ok( binmode(STDERR, ":crlf"), ' and crlf' ); # If this one fails, we're in trouble. So we just bail out. ok( binmode(STDOUT), 'STDOUT made binary' ) || exit(1); -if (find PerlIO::Layer 'perlio') { - ok( binmode(STDOUT, ":unix"), ' with unix discipline' ); -} else { - ok(1, ' skip unix discipline without PerlIO layers' ); +SKIP: { + skip('skip unix discipline without PerlIO layers', 1) + unless find PerlIO::Layer 'perlio'; + ok( binmode(STDOUT, ":unix"), ' with unix discipline' ); } ok( binmode(STDOUT, ":raw"), ' raw' ); ok( binmode(STDOUT, ":crlf"), ' and crlf' ); SKIP: { - skip "minitest", 1 if $ENV{PERL_CORE_MINITEST}; - skip "no EBADF", 1 if (!exists &Errno::EBADF); + skip "no EBADF", 1 unless exists &Errno::EBADF; no warnings 'io', 'once'; $! = 0; binmode(B); - ok($! == &Errno::EBADF); + cmp_ok($!, '==', Errno::EBADF()); } diff --git a/t/io/crlf.t b/t/io/crlf.t index 4c97a91..7eb9a78 100644 --- a/t/io/crlf.t +++ b/t/io/crlf.t @@ -29,8 +29,7 @@ if (find PerlIO::Layer 'perlio') { SKIP: { - skip("miniperl can't rely on loading PerlIO::scalar") - if $ENV{PERL_CORE_MINITEST}; + skip_if_miniperl("miniperl can't rely on loading PerlIO::scalar"); skip("no PerlIO::scalar") unless $Config{extensions} =~ m!\bPerlIO/scalar\b!; require PerlIO::scalar; my $fcontents = join "", map {"$_\015\012"} "a".."zzz"; @@ -41,7 +40,7 @@ if (find PerlIO::Layer 'perlio') { seek $fh, $pos, 0; $/ = "\n"; $s = <$fh>.<$fh>; - ok($s eq "\nxxy\n"); + is($s, "\nxxy\n"); } ok(close(FOO)); @@ -66,8 +65,8 @@ if (find PerlIO::Layer 'perlio') { close FOO; print join(" ", "#", map { sprintf("%02x", $_) } unpack("C*", $foo)), "\n"; - ok($foo =~ /\x0d\x0a$/); - ok($foo !~ /\x0d\x0d/); + like($foo, qr/\x0d\x0a$/); + unlike($foo, qr/\x0d\x0d/); } } } diff --git a/t/io/layers.t b/t/io/layers.t index b0bcf1e..cb7cbef 100644 --- a/t/io/layers.t +++ b/t/io/layers.t @@ -6,15 +6,11 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; require './test.pl'; - unless (find PerlIO::Layer 'perlio') { - print "1..0 # Skip: not perlio\n"; - exit 0; - } - eval 'use Encode'; - if ($@ =~ /dynamic loading not available/) { - print "1..0 # miniperl cannot load Encode\n"; - exit 0; - } + skip_all('not perlio') unless (find PerlIO::Layer 'perlio'); + # FIXME - more of these could be tested without Encode or full perl + skip_all_if_miniperl("no dynamic loading on miniperl, no Encode"); + skip_all_without_extension('Encode'); + # Makes testing easier. $ENV{PERLIO} = 'stdio' if exists $ENV{PERLIO} && $ENV{PERLIO} eq ''; if (exists $ENV{PERLIO} && $ENV{PERLIO} !~ /^(stdio|perlio|mmap)$/) { @@ -60,12 +56,7 @@ print <<__EOH__; # UTF8_STDIN = $UTF8_STDIN __EOH__ -SKIP: { - # FIXME - more of these could be tested without Encode or full perl - skip("This perl does not have Encode", $NTEST) - unless " $Config{extensions} " =~ / Encode /; - skip("miniperl does not have Encode", $NTEST) if $ENV{PERL_CORE_MINITEST}; - +{ sub check { my ($result, $expected, $id) = @_; # An interesting dance follows where we try to make the following diff --git a/t/io/perlio_open.t b/t/io/perlio_open.t index 5f6a65c..7bd9a70 100644 --- a/t/io/perlio_open.t +++ b/t/io/perlio_open.t @@ -3,20 +3,10 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; - if ($ENV{PERL_CORE_MINITEST}) { - print "1..0 # Skip: no Fcntl under miniperl\n"; - exit 0; - } - unless (find PerlIO::Layer 'perlio') { - print "1..0 # Skip: not perlio\n"; - exit 0; - } - use Config; - unless (" $Config{extensions} " =~ / Fcntl /) { - print "1..0 # Skip: no Fcntl (how did you get this far?)\n"; - exit 0; - } require './test.pl'; + skip_all('not perlio') unless (find PerlIO::Layer 'perlio'); + skip_all_if_miniperl("no dynamic loading on miniperl, no Fcntl"); + skip_all_without_extension('Fcntl'); # how did you get this far? } use strict; diff --git a/t/io/print.t b/t/io/print.t index d29036b..321eb1e 100644 --- a/t/io/print.t +++ b/t/io/print.t @@ -3,11 +3,12 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; + require './test.pl'; + eval 'use Errno'; + die $@ if $@ and !is_miniperl(); } use strict 'vars'; -eval 'use Errno'; -die $@ if $@ and !$ENV{PERL_CORE_MINITEST}; print "1..21\n"; diff --git a/t/io/read.t b/t/io/read.t index 57e671d..8cc1640 100644 --- a/t/io/read.t +++ b/t/io/read.t @@ -4,11 +4,11 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; require './test.pl'; + eval 'use Errno'; + die $@ if $@ and !is_miniperl(); } use strict; -eval 'use Errno'; -die $@ if $@ and !$ENV{PERL_CORE_MINITEST}; plan tests => 2; diff --git a/t/io/say.t b/t/io/say.t index 1da7a18..ead4d0b 100644 --- a/t/io/say.t +++ b/t/io/say.t @@ -3,6 +3,9 @@ BEGIN { chdir 't' if -d 't'; @INC = '../lib'; + require './test.pl'; + eval 'use Errno'; + die $@ if $@ and !is_miniperl(); } # Just a few very basic tests cribbed from t/io/print.t, @@ -11,9 +14,6 @@ BEGIN { # the same way as print in any case. use strict 'vars'; -eval 'use Errno'; -die $@ if $@ and !$ENV{PERL_CORE_MINITEST}; - use feature "say"; say "1..12"; diff --git a/t/test.pl b/t/test.pl index 5eed21d..9958356 100644 --- a/t/test.pl +++ b/t/test.pl @@ -122,6 +122,16 @@ sub skip_all_if_miniperl { skip_all(@_) if is_miniperl(); } +sub skip_all_without_extension { + my $extension = shift; + unless (eval 'require Config; 1') { + warn "test.pl had problems loading Config: $@"; + return; + } + return if ($Config::Config{extensions} =~ /\b$extension\b/); + skip_all("$extension was not built"); +} + sub _ok { my ($pass, $where, $name, @mess) = @_; # Do not try to microoptimize by factoring out the "not ". -- Perl5 Master Repository
