1#!./perl 2 3print "1..6\n"; 4my $test = 0; 5 6sub failed { 7 my ($got, $expected, $name) = @_; 8 9 print "not ok $test - $name\n"; 10 my @caller = caller(1); 11 print "# Failed test at $caller[1] line $caller[2]\n"; 12 if (defined $got) { 13 print "# Got '$got'\n"; 14 } else { 15 print "# Got undef\n"; 16 } 17 print "# Expected $expected\n"; 18 return; 19} 20 21sub like { 22 my ($got, $pattern, $name) = @_; 23 $test = $test + 1; 24 if (defined $got && $got =~ $pattern) { 25 print "ok $test - $name\n"; 26 # Principle of least surprise - maintain the expected interface, even 27 # though we aren't using it here (yet). 28 return 1; 29 } 30 failed($got, $pattern, $name); 31} 32 33sub is { 34 my ($got, $expect, $name) = @_; 35 $test = $test + 1; 36 if (defined $got && $got eq $expect) { 37 print "ok $test - $name\n"; 38 return 1; 39 } 40 failed($got, "'$expect'", $name); 41} 42 43my $filename = "multiline$$"; 44 45END { 46 1 while unlink $filename; 47} 48 49open(TRY,'>',$filename) || (die "Can't open $filename: $!"); 50 51$x = 'now is the time 52for all good men 53to come to. 54 55 56! 57 58'; 59 60$y = 'now is the time' . "\n" . 61'for all good men' . "\n" . 62'to come to.' . "\n\n\n!\n\n"; 63 64is($x, $y, 'test data is sane'); 65 66print TRY $x; 67close TRY or die "Could not close: $!"; 68 69open(TRY,$filename) || (die "Can't reopen $filename: $!"); 70$count = 0; 71$z = ''; 72while (<TRY>) { 73 $z .= $_; 74 $count = $count + 1; 75} 76 77is($z, $y, 'basic multiline reading'); 78 79is($count, 7, ' line count'); 80is($., 7, ' $.' ); 81 82$out = (($^O eq 'MSWin32') || $^O eq 'NetWare') ? `type $filename` 83 : ($^O eq 'VMS') ? `type $filename.;0` # otherwise .LIS is assumed 84 : `cat $filename`; 85 86like($out, qr/.*\n.*\n.*\n$/); 87 88close(TRY) || (die "Can't close $filename: $!"); 89 90is($out, $y); 91