require './test.pl';
}
+use strict; # Amazed that this hackery can be made strict ...
+
# read in a file
sub cat {
my $file = shift;
my $bas_tests = 20;
# number of tests in section 3
-my $bug_tests = 4;
+my $bug_tests = 4 + 3 * 3 * 5 * 2 * 3 + 2 + 1 + 1;
# number of tests in section 4
my $hmb_tests = 35;
## Section 1
############
+use vars qw($fox $multiline $foo $good);
+
format OUT =
the quick brown @<<
$fox
write(OUT);
close OUT or die "Could not close: $!";
-$right =
+my $right =
"the quick brown fox
jumped
forescore
# formline tests
-$mustbe = <<EOT;
+$right = <<EOT;
@ a
@> ab
@>> abc
@>>>>>>>>>> abc
EOT
-$was1 = $was2 = '';
+my $was1 = my $was2 = '';
+use vars '$format2';
for (0..10) {
# lexical picture
$^A = '';
formline $format2, 'abc';
$was2 .= "$format2 $^A\n";
}
-is $was1, $mustbe;
-is $was2, $mustbe;
+is $was1, $right;
+is $was2, $right;
$^A = '';
open(OUT10, '>Op_write.tmp') || die "Can't create Op_write.tmp";
+use vars '$test1';
$test1 = 12.95;
write(OUT10);
close OUT10 or die "Could not close: $!";
## Easiest to add new tests just here
#####################################
-use strict; # Amazed that this hackery can be made strict ...
-
# DAPM. Exercise a couple of error codepaths
{
like $@, qr/Undefined format/, 'no such format';
}
+{
+ package Count;
+
+ sub TIESCALAR {
+ my $class = shift;
+ bless [shift, 0, 0], $class;
+ }
+
+ sub FETCH {
+ my $self = shift;
+ ++$self->[1];
+ $self->[0];
+ }
+
+ sub STORE {
+ my $self = shift;
+ ++$self->[2];
+ $self->[0] = shift;
+ }
+}
+
+{
+ my ($pound_utf8, $pm_utf8) = map { my $a = "$_\x{100}"; chop $a; $a}
+ my ($pound, $pm) = ("\xA3", "\xB1");
+
+ foreach my $first ('N', $pound, $pound_utf8) {
+ foreach my $base ('N', $pm, $pm_utf8) {
+ foreach my $second ($base, "$base\n", "$base\nMoo!", "$base\nMoo!\n",
+ "$base\nMoo!\n",) {
+ foreach (['^*', qr/(.+)/], ['@*', qr/(.*?)$/s]) {
+ my ($format, $re) = @$_;
+ foreach my $class ('', 'Count') {
+ my $name = "$first, $second $format $class";
+ $name =~ s/\n/\\n/g;
+
+ $first =~ /(.+)/ or die $first;
+ my $expect = "1${1}2";
+ $second =~ $re or die $second;
+ $expect .= " 3${1}4";
+
+ if ($class) {
+ my $copy1 = $first;
+ my $copy2;
+ tie $copy2, $class, $second;
+ is swrite("1^*2 3${format}4", $copy1, $copy2), $expect, $name;
+ my $obj = tied $copy2;
+ is $obj->[1], 1, 'value read exactly once';
+ } else {
+ my ($copy1, $copy2) = ($first, $second);
+ is swrite("1^*2 3${format}4", $copy1, $copy2), $expect, $name;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+{
+ # This will fail an assertion in 5.10.0 built with -DDEBUGGING (because
+ # pp_formline attempts to set SvCUR() on an SVt_RV). I suspect that it will
+ # be doing something similarly out of bounds on everything from 5.000
+ my $ref = [];
+ is swrite('>^*<', $ref), ">$ref<";
+ is swrite('>@*<', $ref), ">$ref<";
+}
format EMPTY =
.
select $oldfh;
close STDOUT_DUP;
+*CmT = *{$::{Comment}}{FORMAT};
+ok defined *{$::{CmT}}{FORMAT}, "glob assign";
+
+fresh_perl_like(<<'EOP', qr/^Format STDOUT redefined at/, {stderr => 1}, '#64562 - Segmentation fault with redefined formats and warnings');
+#!./perl
+
+use strict;
+use warnings; # crashes!
+
+format =
+.
+
+write;
+
+format =
+.
+
+write;
+EOP
+
#############################
## Section 4
## Add new tests *above* here
# Just a complete test for format, including top-, left- and bottom marging
# and format detection through glob entries
-if ($^O eq 'VMS' || $^O eq 'MSWin32' || $^O eq 'dos' || $^O eq 'MacOS' ||
+if ($^O eq 'VMS' || $^O eq 'MSWin32' || $^O eq 'dos' ||
($^O eq 'os2' and not eval '$OS2::can_fork')) {
$test = curr_test();
SKIP: {