#!./perl
-# $RCSfile: multiline.t,v $$Revision: 4.1 $$Date: 92/08/07 18:27:20 $
+print "1..6\n";
+my $test = 0;
+
+sub failed {
+ my ($got, $expected, $name) = @_;
+
+ 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);
+}
-print "1..5\n";
+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,'>Comp.try') || (die "Can't open temp file.");
+open(TRY,'>',$filename) || (die "Can't open $filename: $!");
$x = 'now is the time
for all good men
'for all good men' . "\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');
-if ($count == 7) {print "ok 3\n";} else {print "not ok 3\n";}
+is($count, 7, ' line count');
+is($., 7, ' $.' );
-$_ = ($^O eq 'MSWin32') ? `type Comp.try`
- : ($^O eq 'MacOS') ? `catenate Comp.try`
- : `cat Comp.try`;
+$out = (($^O eq 'MSWin32') || $^O eq 'NetWare') ? `type $filename`
+ : ($^O eq 'VMS') ? `type $filename.;0` # otherwise .LIS is assumed
+ : `cat $filename`;
-if (/.*\n.*\n.*\n$/) {print "ok 4\n";} else {print "not ok 4\n";}
+like($out, qr/.*\n.*\n.*\n$/);
-close(try) || (die "Can't close temp file.");
-unlink 'Comp.try' || `/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);