diff options
author | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-09-24 19:18:17 +0000 |
---|---|---|
committer | Nick Ing-Simmons <nik@tiuk.ti.com> | 2001-09-24 19:18:17 +0000 |
commit | 3ed9e235452ac04f38d3ebeb9fd58a5c777b9fff (patch) | |
tree | f4faddf9b2a5da1268700d69792c566eac55dbbd /t/op | |
parent | 5b82561c4274a5e1e753d0dede9084de567ff09f (diff) | |
parent | 7fcd0fc5f1b89986c4e176868a5363c5feb2d66d (diff) | |
download | perl-3ed9e235452ac04f38d3ebeb9fd58a5c777b9fff.tar.gz |
Integrate mainline
p4raw-id: //depot/perlio@12186
Diffstat (limited to 't/op')
-rw-r--r-- | t/op/inccode.t | 47 | ||||
-rwxr-xr-x | t/op/magic.t | 2 | ||||
-rwxr-xr-x | t/op/pack.t | 13 | ||||
-rwxr-xr-x | t/op/study.t | 124 |
4 files changed, 105 insertions, 81 deletions
diff --git a/t/op/inccode.t b/t/op/inccode.t index 95ee7c0094..71beb3e9e9 100644 --- a/t/op/inccode.t +++ b/t/op/inccode.t @@ -8,7 +8,7 @@ BEGIN { } use File::Spec; -use Test::More tests => 30; +use Test::More tests => 39; my @tempfiles = (); @@ -25,12 +25,6 @@ sub get_temp_fh { END { 1 while unlink @tempfiles } -sub get_addr { - my $str = shift; - $str =~ /(0x[0-9a-f]+)/i; - return $1; -} - sub fooinc { my ($self, $filename) = @_; if (substr($filename,0,3) eq 'Foo') { @@ -47,18 +41,18 @@ ok( !eval { require Bar; 1 }, 'Trying non-magic package' ); ok( eval { require Foo; 1 }, 'require() magic via code ref' ); ok( exists $INC{'Foo.pm'}, ' %INC sees it' ); -is( get_addr($INC{'Foo.pm'}), get_addr(\&fooinc), - ' key is correct in %INC' ); +is( ref $INC{'Foo.pm'}, 'CODE', ' key is a coderef in %INC' ); +is( $INC{'Foo.pm'}, \&fooinc, ' key is correct in %INC' ); ok( eval "use Foo1; 1;", 'use()' ); ok( exists $INC{'Foo1.pm'}, ' %INC sees it' ); -is( get_addr($INC{'Foo1.pm'}), get_addr(\&fooinc), - ' key is correct in %INC' ); +is( ref $INC{'Foo1.pm'}, 'CODE', ' key is a coderef in %INC' ); +is( $INC{'Foo1.pm'}, \&fooinc, ' key is correct in %INC' ); ok( eval { do 'Foo2.pl'; 1 }, 'do()' ); ok( exists $INC{'Foo2.pl'}, ' %INC sees it' ); -is( get_addr($INC{'Foo2.pl'}), get_addr(\&fooinc), - ' key is correct in %INC' ); +is( ref $INC{'Foo2.pl'}, 'CODE', ' key is a coderef in %INC' ); +is( $INC{'Foo2.pl'}, \&fooinc, ' key is correct in %INC' ); pop @INC; @@ -81,18 +75,18 @@ ok( !eval { require Foo3; 1; }, 'Original magic INC purged' ); ok( eval { require Bar; 1 }, 'require() magic via array ref' ); ok( exists $INC{'Bar.pm'}, ' %INC sees it' ); -is( get_addr($INC{'Bar.pm'}), get_addr($arrayref), - ' key is correct in %INC' ); +is( ref $INC{'Bar.pm'}, 'ARRAY', ' key is an arrayref in %INC' ); +is( $INC{'Bar.pm'}, $arrayref, ' key is correct in %INC' ); ok( eval "use Bar1; 1;", 'use()' ); ok( exists $INC{'Bar1.pm'}, ' %INC sees it' ); -is( get_addr($INC{'Bar1.pm'}), get_addr($arrayref), - ' key is correct in %INC' ); +is( ref $INC{'Bar1.pm'}, 'ARRAY', ' key is an arrayref in %INC' ); +is( $INC{'Bar1.pm'}, $arrayref, ' key is correct in %INC' ); ok( eval { do 'Bar2.pl'; 1 }, 'do()' ); ok( exists $INC{'Bar2.pl'}, ' %INC sees it' ); -is( get_addr($INC{'Bar2.pl'}), get_addr($arrayref), - ' key is correct in %INC' ); +is( ref $INC{'Bar2.pl'}, 'ARRAY', ' key is an arrayref in %INC' ); +is( $INC{'Bar2.pl'}, $arrayref, ' key is correct in %INC' ); pop @INC; @@ -111,8 +105,9 @@ push @INC, $href; ok( eval { require Quux; 1 }, 'require() magic via hash object' ); ok( exists $INC{'Quux.pm'}, ' %INC sees it' ); -is( get_addr($INC{'Quux.pm'}), get_addr($href), - ' key is correct in %INC' ); +is( ref $INC{'Quux.pm'}, 'FooLoader', + ' key is an object in %INC' ); +is( $INC{'Quux.pm'}, $href, ' key is correct in %INC' ); pop @INC; @@ -121,8 +116,9 @@ push @INC, $aref; ok( eval { require Quux1; 1 }, 'require() magic via array object' ); ok( exists $INC{'Quux1.pm'}, ' %INC sees it' ); -is( get_addr($INC{'Quux1.pm'}), get_addr($aref), - ' key is correct in %INC' ); +is( ref $INC{'Quux1.pm'}, 'FooLoader', + ' key is an object in %INC' ); +is( $INC{'Quux1.pm'}, $aref, ' key is correct in %INC' ); pop @INC; @@ -131,7 +127,8 @@ push @INC, $sref; ok( eval { require Quux2; 1 }, 'require() magic via scalar object' ); ok( exists $INC{'Quux2.pm'}, ' %INC sees it' ); -is( get_addr($INC{'Quux2.pm'}), get_addr($sref), - ' key is correct in %INC' ); +is( ref $INC{'Quux2.pm'}, 'FooLoader', + ' key is an object in %INC' ); +is( $INC{'Quux2.pm'}, $sref, ' key is correct in %INC' ); pop @INC; diff --git a/t/op/magic.t b/t/op/magic.t index d5931f3cd9..ae1b1d9b8a 100755 --- a/t/op/magic.t +++ b/t/op/magic.t @@ -83,8 +83,8 @@ else { } END + $test += 2; } -$test += 2; # can we slice ENV? @val1 = @ENV{keys(%ENV)}; diff --git a/t/op/pack.t b/t/op/pack.t index 02b3806c6d..fcc2abab03 100755 --- a/t/op/pack.t +++ b/t/op/pack.t @@ -1,6 +1,6 @@ -#!./perl -Tw +#!./perl -w -print "1..610\n"; +print "1..611\n"; BEGIN { chdir 't' if -d 't'; @@ -646,3 +646,12 @@ foreach ( or printf "# scalar unpack ('$template', \"%s\") gave %s expected %s\n", encode ($in), encode_list ($got), encode_list ($out[0]); } + +{ + # 611 + my $t = 'Z*Z*'; + my ($u, $v) = qw(foo xyzzy); + my $p = pack($t, $u, $v); + my @u = unpack($t, $p); + ok(@u == 2 && $u[0] eq $u && $u[1] eq $v); +} diff --git a/t/op/study.t b/t/op/study.t index 0c111ea9cc..3ca95355b0 100755 --- a/t/op/study.t +++ b/t/op/study.t @@ -5,99 +5,117 @@ BEGIN { @INC = '../lib'; } +$Ok_Level = 0; +my $test = 1; +sub ok ($;$) { + my($ok, $name) = @_; + + local $_; + + # You have to do it this way or VMS will get confused. + printf "%s $test%s\n", $ok ? 'ok' : 'not ok', + $name ? " - $name" : ''; + + printf "# Failed test at line %d\n", (caller($Ok_Level))[2] unless $ok; + + $test++; + return $ok; +} + +sub nok ($;$) { + my($nok, $name) = @_; + local $Ok_Level = 1; + ok( !$nok, $name ); +} + +use Config; +my $have_alarm = $Config{d_alarm}; +sub alarm_ok (&) { + my $test = shift; + + local $SIG{ALRM} = sub { die "timeout\n" }; + + my $match; + eval { + alarm(2) if $have_alarm; + $match = $test->(); + alarm(0) if $have_alarm; + }; + + local $Ok_Level = 1; + ok( !$match && !$@, 'testing studys that used to hang' ); +} + + print "1..26\n"; $x = "abc\ndef\n"; study($x); -if ($x =~ /^abc/) {print "ok 1\n";} else {print "not ok 1\n";} -if ($x !~ /^def/) {print "ok 2\n";} else {print "not ok 2\n";} +ok($x =~ /^abc/); +ok($x !~ /^def/); $* = 1; -if ($x =~ /^def/) {print "ok 3\n";} else {print "not ok 3\n";} +ok($x =~ /^def/); $* = 0; $_ = '123'; study; -if (/^([0-9][0-9]*)/) {print "ok 4\n";} else {print "not ok 4\n";} +ok(/^([0-9][0-9]*)/); -if ($x =~ /^xxx/) {print "not ok 5\n";} else {print "ok 5\n";} -if ($x !~ /^abc/) {print "not ok 6\n";} else {print "ok 6\n";} +nok($x =~ /^xxx/); +nok($x !~ /^abc/); -if ($x =~ /def/) {print "ok 7\n";} else {print "not ok 7\n";} -if ($x !~ /def/) {print "not ok 8\n";} else {print "ok 8\n";} +ok($x =~ /def/); +nok($x !~ /def/); study($x); -if ($x !~ /.def/) {print "ok 9\n";} else {print "not ok 9\n";} -if ($x =~ /.def/) {print "not ok 10\n";} else {print "ok 10\n";} +ok($x !~ /.def/); +nok($x =~ /.def/); -if ($x =~ /\ndef/) {print "ok 11\n";} else {print "not ok 11\n";} -if ($x !~ /\ndef/) {print "not ok 12\n";} else {print "ok 12\n";} +ok($x =~ /\ndef/); +nok($x !~ /\ndef/); $_ = 'aaabbbccc'; study; -if (/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc') { - print "ok 13\n"; -} else { - print "not ok 13\n"; -} -if (/(a+b+c+)/ && $1 eq 'aaabbbccc') { - print "ok 14\n"; -} else { - print "not ok 14\n"; -} +ok(/(a*b*)(c*)/ && $1 eq 'aaabbb' && $2 eq 'ccc'); +ok(/(a+b+c+)/ && $1 eq 'aaabbbccc'); -if (/a+b?c+/) {print "not ok 15\n";} else {print "ok 15\n";} +nok(/a+b?c+/); $_ = 'aaabccc'; study; -if (/a+b?c+/) {print "ok 16\n";} else {print "not ok 16\n";} -if (/a*b+c*/) {print "ok 17\n";} else {print "not ok 17\n";} +ok(/a+b?c+/); +ok(/a*b+c*/); $_ = 'aaaccc'; study; -if (/a*b?c*/) {print "ok 18\n";} else {print "not ok 18\n";} -if (/a*b+c*/) {print "not ok 19\n";} else {print "ok 19\n";} +ok(/a*b?c*/); +nok(/a*b+c*/); $_ = 'abcdef'; study; -if (/bcd|xyz/) {print "ok 20\n";} else {print "not ok 20\n";} -if (/xyz|bcd/) {print "ok 21\n";} else {print "not ok 21\n";} +ok(/bcd|xyz/); +ok(/xyz|bcd/); -if (m|bc/*d|) {print "ok 22\n";} else {print "not ok 22\n";} +ok(m|bc/*d|); -if (/^$_$/) {print "ok 23\n";} else {print "not ok 23\n";} +ok(/^$_$/); -$* = 1; # test 3 only tested the optimized version--this one is for real -if ("ab\ncd\n" =~ /^cd/) {print "ok 24\n";} else {print "not ok 24\n";} +$* = 1; # test 3 only tested the optimized version--this one is for real +ok("ab\ncd\n" =~ /^cd/); if ($^O eq 'os390') { # Even with the alarm() OS/390 can't manage these tests # (Perl just goes into a busy loop, luckily an interruptable one) - for (25..26) { print "not ok $_ # compiler bug?\n" } + for (25..26) { print "not ok $_ # TODO compiler bug?\n" } + $test += 2; } else { # [ID 20010618.006] tests 25..26 may loop - use Config; - my $have_alarm = $Config{d_alarm}; - local $SIG{ALRM} = sub { die "timeout\n" }; $_ = 'FGF'; study; - my $ok = $have_alarm - ? eval { alarm(2); my $match = /G.F$/; alarm(0); !$match } - : eval { !/G.F$/ }; - if ($ok && !$@) { - print "ok 25\n"; - } else { - print "not ok 25\t# " . $@ || "should not match\n"; - } - $ok = $have_alarm - ? eval { alarm(2); my $match = /[F]F$/; alarm(0); !$match } - : eval { !/[F]F$/ }; - if ($ok && !$@) { - print "ok 26\n"; - } else { - print "not ok 26\t# " . $@ || "should not match\n"; - } + alarm_ok { /G.F$/ }; + alarm_ok { /[F]F$/ }; } |