my $bas_tests = 20;
# number of tests in section 3
-my $hmb_tests = 36;
+my $hmb_tests = 39;
printf "1..%d\n", $bas_tests + $num_tests + $hmb_tests;
# must fail since we have a trailing ; in the eval'ed string (WL)
my @v = ('k');
eval "format OUT14 = \n@\n\@v";
- print $@ ? "ok 14\n" : "not ok 14\n";
+ print +($@ && $@ =~ /Format not terminated/)
+ ? "ok 14\n" : "not ok 14 $@\n";
}
.
open(OUT18, '>Op_write.tmp') || die "Can't create Op_write.tmp";
eval { write(OUT18); };
- print $@ ? "ok 18\n" : "not ok 18\n";
+ print +($@ && $@ =~ /Repeated format line will never terminate/)
+ ? "ok 18\n" : "not ok 18: $@\n";
close OUT18 or die "Could not close: $!";
}
: $writeres eq $expected;
print $ok
- ? "ok $nt\n"
+ ? "ok $nt - $writefmt\n"
: "not ok $nt\n# f=[$writefmt] exp=[$expected] got=[$writeres]\n";
}
}
use strict; # Amazed that this hackery can be made strict ...
+# DAPM. Exercise a couple of error codepaths
+
+{
+ local $~ = '';
+ eval { write };
+ print "not " unless $@ and $@ =~ /Not a format reference/;
+ print "ok $test - Not a format reference\n";
+ $test++;
+
+ $~ = "NOSUCHFORMAT";
+ eval { write };
+ print "not " unless $@ and $@ =~ /Undefined format/;
+ print "ok $test - Undefined format\n";
+ $test++;
+}
+
# Just a complete test for format, including top-, left- and bottom marging
# and format detection through glob entries
$test++;
}
select $oldfh;
+close STDOUT_DUP;
$^ = "STDOUT_TOP";
$= = 7; # Page length
my $bm = 2; # Bottom marging (empty lines between last text and footer)
my $lm = 4; # Left margin (indent in spaces)
-select ((select (STDOUT), $| = 1)[0]);
-if ($lm > 0 and !open STDOUT, "|-") { # Left margin (in this test ALWAYS set)
- select ((select (STDOUT), $| = 1)[0]);
+# -----------------------------------------------------------------------
+#
+# execute the rest of the script in a child process. The parent reads the
+# output from the child and compares it with <DATA>.
+
+my @data = <DATA>;
+
+select ((select (STDOUT), $| = 1)[0]); # flush STDOUT
+
+my $opened = open FROM_CHILD, "-|";
+unless (defined $opened) {
+ print "not ok $test - open gave $!\n"; exit 0;
+}
+
+if ($opened) {
+ # in parent here
+
+ print "ok $test - open\n"; $test++;
my $s = " " x $lm;
- while (<STDIN>) {
+ while (<FROM_CHILD>) {
+ unless (@data) {
+ print "not ok $test - too much output\n";
+ exit;
+ }
s/^/$s/;
- print + ($_ eq <DATA> ? "" : "not "), "ok ", $test++, "\n";
+ my $exp = shift @data;
+ print + ($_ eq $exp ? "" : "not "), "ok ", $test++, " \n";
+ if ($_ ne $exp) {
+ s/\n/\\n/g for $_, $exp;
+ print "#expected: $exp\n#got: $_\n";
}
- close STDIN;
- print + (<DATA>?"not ":""), "ok ", $test++, "\n";
- close STDOUT;
- exit;
}
+ close FROM_CHILD;
+ print + (@data?"not ":""), "ok ", $test++, " - too little output\n";
+ exit;
+}
+
+# in child here
+
+ select ((select (STDOUT), $| = 1)[0]);
$tm = "\n" x $tm;
$= -= $bm + 1; # count one for the trailing "----"
my $lastmin = 0;