This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
in Carp, avoid vivifying utf8 stash on Perl 5.6
[perl5.git] / t / comp / multiline.t
index 5565081..f1e098e 100644 (file)
@@ -1,40 +1,90 @@
 #!./perl
 
-# $Header: multiline.t,v 4.0 91/03/20 01:50:15 lwall Locked $
+print "1..6\n";
+my $test = 0;
 
-print "1..5\n";
+sub failed {
+    my ($got, $expected, $name) = @_;
 
-open(try,'>Comp.try') || (die "Can't open temp file.");
+    print "not ok $test - $name\n";
+    my @caller = caller(1);
+    print "# Failed test at $caller[1] line $caller[2]\n";
+    if (defined $got) {
+       print "# Got '$got'\n";
+    } else {
+       print "# Got undef\n";
+    }
+    print "# Expected $expected\n";
+    return;
+}
+
+sub like {
+    my ($got, $pattern, $name) = @_;
+    $test = $test + 1;
+    if (defined $got && $got =~ $pattern) {
+       print "ok $test - $name\n";
+       # Principle of least surprise - maintain the expected interface, even
+       # though we aren't using it here (yet).
+       return 1;
+    }
+    failed($got, $pattern, $name);
+}
+
+sub is {
+    my ($got, $expect, $name) = @_;
+    $test = $test + 1;
+    if (defined $got && $got eq $expect) {
+       print "ok $test - $name\n";
+       return 1;
+    }
+    failed($got, "'$expect'", $name);
+}
+
+my $filename = "multiline$$";
+
+END {
+    1 while unlink $filename;
+}
+
+open(TRY,'>',$filename) || (die "Can't open $filename: $!");
 
 $x = 'now is the time
 for all good men
 to come to.
+
+
+!
+
 ';
 
 $y = 'now is the time' . "\n" .
 'for all good men' . "\n" .
-'to come to.' . "\n";
+'to come to.' . "\n\n\n!\n\n";
 
-if ($x eq $y) {print "ok 1\n";} else {print "not ok 1\n";}
+is($x, $y,  'test data is sane');
 
-print try $x;
-close try;
+print TRY $x;
+close TRY or die "Could not close: $!";
 
-open(try,'Comp.try') || (die "Can't reopen temp file.");
+open(TRY,$filename) || (die "Can't reopen $filename: $!");
 $count = 0;
 $z = '';
-while (<try>) {
+while (<TRY>) {
     $z .= $_;
     $count = $count + 1;
 }
 
-if ($z eq $y) {print "ok 2\n";} else {print "not ok 2\n";}
+is($z, $y,  'basic multiline reading');
+
+is($count, 7,   '    line count');
+is($., 7,       '    $.' );
 
-if ($count == 3) {print "ok 3\n";} else {print "not ok 3\n";}
+$out = (($^O eq 'MSWin32') || $^O eq 'NetWare') ? `type $filename`
+    : ($^O eq 'VMS') ? `type $filename.;0`   # otherwise .LIS is assumed
+    : `cat $filename`;
 
-$_ = `cat Comp.try`;
+like($out, qr/.*\n.*\n.*\n$/);
 
-if (/.*\n.*\n.*\n$/) {print "ok 4\n";} else {print "not ok 4\n";}
-`/bin/rm -f Comp.try`;
+close(TRY) || (die "Can't close $filename: $!");
 
-if ($_ eq $y) {print "ok 5\n";} else {print "not ok 5\n";}
+is($out, $y);