Add TODO tests for the (sometimes) crashing threads/op deletion/reset
[p5sagit/p5-mst-13.2.git] / t / op / reset.t
CommitLineData
2f3c5f77 1#!./perl -w
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8use strict;
9
10# Currently only testing the reset of patterns.
a1f22e0c 11plan tests => 24;
2f3c5f77 12
13package aiieee;
14
15sub zlopp {
16 (shift =~ ?zlopp?) ? 1 : 0;
17}
18
19sub reset_zlopp {
20 reset;
21}
22
23package CLINK;
24
25sub ZZIP {
26 shift =~ ?ZZIP? ? 1 : 0;
27}
28
29sub reset_ZZIP {
30 reset;
31}
32
33package main;
34
35is(aiieee::zlopp(""), 0, "mismatch doesn't match");
36is(aiieee::zlopp("zlopp"), 1, "match matches first time");
37is(aiieee::zlopp(""), 0, "mismatch doesn't match");
38is(aiieee::zlopp("zlopp"), 0, "match doesn't match second time");
39aiieee::reset_zlopp();
40is(aiieee::zlopp("zlopp"), 1, "match matches after reset");
41is(aiieee::zlopp(""), 0, "mismatch doesn't match");
42
43aiieee::reset_zlopp();
44
45is(aiieee::zlopp(""), 0, "mismatch doesn't match");
46is(aiieee::zlopp("zlopp"), 1, "match matches first time");
47is(CLINK::ZZIP(""), 0, "mismatch doesn't match");
48is(CLINK::ZZIP("ZZIP"), 1, "match matches first time");
49is(CLINK::ZZIP(""), 0, "mismatch doesn't match");
50is(CLINK::ZZIP("ZZIP"), 0, "match doesn't match second time");
51is(aiieee::zlopp(""), 0, "mismatch doesn't match");
52is(aiieee::zlopp("zlopp"), 0, "match doesn't match second time");
53
54aiieee::reset_zlopp();
55is(aiieee::zlopp("zlopp"), 1, "match matches after reset");
56is(aiieee::zlopp(""), 0, "mismatch doesn't match");
57
58is(CLINK::ZZIP(""), 0, "mismatch doesn't match");
59is(CLINK::ZZIP("ZZIP"), 0, "match doesn't match third time");
60
61CLINK::reset_ZZIP();
62is(CLINK::ZZIP("ZZIP"), 1, "match matches after reset");
63is(CLINK::ZZIP(""), 0, "mismatch doesn't match");
a1f22e0c 64
65
66undef $/;
67my $prog = <DATA>;
68
69SKIP:
70{
71 eval {require threads; 1} or
72 skip "No threads", 4;
73 local $::TODO
74 = "Currently performs a read from free()d memory, and may crash";
75 foreach my $eight ('/', '?') {
76 foreach my $nine ('/', '?') {
77 my $copy = $prog;
78 $copy =~ s/8/$eight/gm;
79 $copy =~ s/9/$nine/gm;
80 fresh_perl_is($copy, "pass", "",
81 "first pattern $eight$eight, second $nine$nine");
82 }
83 }
84}
85
86__DATA__
87#!perl
88use warnings;
89use strict;
90
91# Note that there are no digits in this program, other than the placeholders
92sub a {
938one8;
94}
95sub b {
969two9;
97}
98
99use threads;
100use threads::shared;
101
102sub wipe {
103 eval 'no warnings; sub b {}';
104}
105
106sub lock_then_wipe {
107 my $l_r = shift;
108 lock $$l_r;
109 cond_wait($$l_r) until $$l_r eq "B";
110 wipe;
111 $$l_r = "C";
112 cond_signal $$l_r;
113}
114
115my $lock : shared = "A";
116my $r = \$lock;
117
118my $t;
119{
120 lock $$r;
121 $t = threads->new(\&lock_then_wipe, $r);
122 wipe;
123 $lock = "B";
124 cond_signal $lock;
125}
126
127{
128 lock $lock;
129 cond_wait($lock) until $lock eq "C";
130 reset;
131}
132
133$t->join;
134print "pass\n";