diff options
author | Michael G. Schwern <schwern@pobox.com> | 2001-09-21 13:59:03 -0400 |
---|---|---|
committer | Abhijit Menon-Sen <ams@wiw.org> | 2001-09-22 03:37:07 +0000 |
commit | 5d96a5e070ce49e6f3f6ee787d81f3b944ebff4f (patch) | |
tree | 6b8adf33b91a7d75a20376d80efa2b9d3340a76b /t/op/do.t | |
parent | 67ac489efef76ba94d2f040ea58ff87e017e54a4 (diff) | |
download | perl-5d96a5e070ce49e6f3f6ee787d81f3b944ebff4f.tar.gz |
[REPATCH] Re: [PATCH t/op/do.t] new regression tests for bug ID
20010920.007
Message-Id: <20010921175903.V5494@blackrider>
p4raw-id: //depot/perl@12122
Diffstat (limited to 't/op/do.t')
-rwxr-xr-x | t/op/do.t | 67 |
1 files changed, 44 insertions, 23 deletions
@@ -4,68 +4,89 @@ sub foo1 { - print $_[0]; + ok($_[0]); 'value'; } sub foo2 { shift; - print $_[0]; + ok($_[0]); $x = 'value'; $x; } +my $test = 1; +sub ok { + my($ok, $name) = @_; + + # You have to do it this way or VMS will get confused. + printf "%s %d%s\n", $ok ? "ok" : "not ok", + $test, + defined $name ? " - $name" : ''; + + printf "# Failed test at line %d\n", (caller)[2] unless $ok; + + $test++; + return $ok; +} + print "1..20\n"; -$_[0] = "not ok 1\n"; -$result = do foo1("ok 1\n"); -print "#2\t:$result: eq :value:\n"; -if ($result eq 'value') { print "ok 2\n"; } else { print "not ok 2\n"; } -if ($_[0] eq "not ok 1\n") { print "ok 3\n"; } else { print "not ok 3\n"; } +# Test do &sub and proper @_ handling. +$_[0] = 0; +$result = do foo1(1); -$_[0] = "not ok 4\n"; -$result = do foo2("not ok 4\n","ok 4\n","not ok 4\n"); -print "#5\t:$result: eq :value:\n"; -if ($result eq 'value') { print "ok 5\n"; } else { print "not ok 5\n"; } -if ($_[0] eq "not ok 4\n") { print "ok 6\n"; } else { print "not ok 6\n"; } +ok( $result eq 'value', ":$result: eq :value:" ); +ok( $_[0] == 0 ); -$result = do{print "ok 7\n"; 'value';}; -print "#8\t:$result: eq :value:\n"; -if ($result eq 'value') { print "ok 8\n"; } else { print "not ok 8\n"; } +$_[0] = 0; +$result = do foo2(0,1,0); +ok( $result eq 'value', ":$result: eq :value:" ); +ok( $_[0] == 0 ); + +$result = do{ ok 1; 'value';}; +ok( $result eq 'value', ":$result: eq :value:" ); sub blather { - print @_; + ok 1 foreach @_; } -do blather("ok 9\n","ok 10\n"); -@x = ("ok 11\n", "ok 12\n"); -@y = ("ok 14\n", "ok 15\n"); -do blather(@x,"ok 13\n",@y); +do blather("ayep","sho nuff"); +@x = ("jeepers", "okydoke"); +@y = ("uhhuh", "yeppers"); +do blather(@x,"noofie",@y); unshift @INC, '.'; if (open(DO, ">$$.16")) { - print DO "print qq{ok 16\n} if defined wantarray && not wantarray\n"; + print DO "ok(1, 'do in scalar context') if defined wantarray && not wantarray\n"; close DO; } my $a = do "$$.16"; if (open(DO, ">$$.17")) { - print DO "print qq{ok 17\n} if defined wantarray && wantarray\n"; + print DO "ok(1, 'do in list context') if defined wantarray && wantarray\n"; close DO; } my @a = do "$$.17"; if (open(DO, ">$$.18")) { - print DO "print qq{ok 18\n} if not defined wantarray\n"; + print DO "ok(1, 'do in void context') if not defined wantarray\n"; close DO; } do "$$.18"; +# bug ID 20010920.007 +eval qq{ do qq(a file that does not exist); }; +ok( !$@ ); + +eval qq{ do uc qq(a file that does not exist); }; +ok( !$@ ); + eval qq{ do qq(a file that does not exist); }; print "not " if $@; print "ok 19\n"; |