diff options
author | Nicholas Clark <nick@ccl4.org> | 2011-02-21 14:50:22 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2011-02-21 14:50:22 +0000 |
commit | e55b089a984517eb26e82f4ab40b82f3ef47b0eb (patch) | |
tree | 3711da4b12c4cb5576e03c6361856f4520c7156a /t | |
parent | f299c5a14ed4ed2fd75f01659ba6dcfa3ef38c9f (diff) | |
download | perl-e55b089a984517eb26e82f4ab40b82f3ef47b0eb.tar.gz |
Break out the test for #72922 into a new test file.
Skip the new t/re/qr-72922.t under minitest.
Diffstat (limited to 't')
-rw-r--r-- | t/re/qr-72922.t | 38 | ||||
-rw-r--r-- | t/re/qr.t | 63 |
2 files changed, 39 insertions, 62 deletions
diff --git a/t/re/qr-72922.t b/t/re/qr-72922.t new file mode 100644 index 0000000000..5daaff0942 --- /dev/null +++ b/t/re/qr-72922.t @@ -0,0 +1,38 @@ +#!perl -w +use strict; + +BEGIN { + require './test.pl'; + skip_all_if_miniperl("no dynamic loading on miniperl, no Scalar::Util"); + plan(tests => 14); +} + +# [perl 72922]: A 'copy' of a Regex object which has magic should not crash +# When a Regex object was copied and the copy weaken then the original regex object +# could no longer be 'copied' with qr// + +use Scalar::Util 'weaken'; +sub s1 { + my $re = qr/abcdef/; + my $re_copy1 = $re; + my $re_weak_copy = $re;; + weaken($re_weak_copy); + my $re_copy2 = qr/$re/; + + my $str_re = "$re"; + is("$$re_weak_copy", $str_re, "weak copy equals original"); + is("$re_copy1", $str_re, "copy1 equals original"); + is("$re_copy2", $str_re, "copy2 equals original"); + + my $refcnt_start = Internals::SvREFCNT($$re_weak_copy); + + undef $re; + is(Internals::SvREFCNT($$re_weak_copy), $refcnt_start - 1, "refcnt decreased"); + is("$re_weak_copy", $str_re, "weak copy still equals original"); + + undef $re_copy2; + is(Internals::SvREFCNT($$re_weak_copy), $refcnt_start - 1, "refcnt not decreased"); + is("$re_weak_copy", $str_re, "weak copy still equals original"); +} +s1(); +s1(); @@ -6,7 +6,7 @@ BEGIN { require './test.pl'; } -plan tests => 6; +plan tests => 5; my $rx = qr//; @@ -81,64 +81,3 @@ for($'){ $flile =~ qr/(?:)/; is $scratch, "[fetching]", '/$qr/ with magical LHS'; } - -{ - # [perl 72922]: A 'copy' of a Regex object which has magic should not crash - # When a Regex object was copied and the copy weaken then the original regex object - # could no longer be 'copied' with qr// - - my $prog = tempfile(); - open my $fh, ">", $prog or die "Can't write to tempfile"; - print $fh <<'EOTEST'; -require "./test.pl"; -$verbose = 1; -use Scalar::Util 'weaken'; -sub s1 { - my $re = qr/abcdef/; - my $re_copy1 = $re; - my $re_weak_copy = $re;; - weaken($re_weak_copy); - my $re_copy2 = qr/$re/; - - my $str_re = "$re"; - is("$$re_weak_copy", $str_re, "weak copy equals original"); - is("$re_copy1", $str_re, "copy1 equals original"); - is("$re_copy2", $str_re, "copy2 equals original"); - - my $refcnt_start = Internals::SvREFCNT($$re_weak_copy); - - undef $re; - is(Internals::SvREFCNT($$re_weak_copy), $refcnt_start - 1, "refcnt decreased"); - is("$re_weak_copy", $str_re, "weak copy still equals original"); - - undef $re_copy2; - is(Internals::SvREFCNT($$re_weak_copy), $refcnt_start - 1, "refcnt not decreased"); - is("$re_weak_copy", $str_re, "weak copy still equals original"); -} -s1(); -s1(); -EOTEST - close $fh; - - my $out = runperl(stderr => 1, progfile => $prog); - unlink_all $prog; - - my $expected = <<'EOOUT'; -ok 1 - weak copy equals original -ok 2 - copy1 equals original -ok 3 - copy2 equals original -ok 4 - refcnt decreased -ok 5 - weak copy still equals original -ok 6 - refcnt not decreased -ok 7 - weak copy still equals original -ok 8 - weak copy equals original -ok 9 - copy1 equals original -ok 10 - copy2 equals original -ok 11 - refcnt decreased -ok 12 - weak copy still equals original -ok 13 - refcnt not decreased -ok 14 - weak copy still equals original -EOOUT - - is ($out, $expected, '[perl #72922] copy of a regex of which a weak copy exist'); -} |