2 # Copyright (C) 2006-2007, The Perl Foundation.
7 use lib qw( . lib ../lib ../../lib );
9 use Parrot::Test tests => 17;
13 t/pmc/ro.t -- tests read-only value support
21 Tests automatically generated read-only PMC support.
25 my $library = <<'CODE';
31 setprop arg, '_ro', one
39 setprop arg, '_ro', zero
43 pir_error_output_unlike( $library . <<'CODE', <<'OUTPUT', "Integer set read-only is not writable" );
58 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Integer set read-only can be read" );
98 pir_error_output_unlike( <<"CODE", <<'OUTPUT', "PerlInteger" );
103 foo = new 'PerlInteger'
114 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Integer stays Integer" );
130 pir_error_output_unlike( $library . <<'CODE', <<'OUTPUT', "Integer add" );
145 pir_error_output_unlike( $library . <<'CODE', <<'OUTPUT', "Complex i_add" );
162 # The ROTest dynpmc has opposite of normal logic for set/get integer
163 # and 'reader' and 'writer' NCI methods.
164 # The values are [should work with read-only, is todo test].
167 # these first two tests would test overriding of the default
168 # read-onlyness notion of vtable methods
169 q{value = 42} => [ 1, 0 ],
170 q{$I0 = value} => [ 0, 0 ],
172 # these make sure NCI methods check does-write flags
173 # 'writer' is marked as writing; 'reader' is not.
174 q{$I0 = value.'reader'()} => [ 1, 0 ],
175 q{$I0 = value.'writer'(42)} => [ 0, 0 ],
177 for my $test ( keys %tests ) {
178 my $code = $library . <<"CODE";
185 print "reached end\\n"
189 my ( $readonly, $todo ) = @{ $tests{$test} };
191 # first make sure it works without the make_readonly
192 pir_output_is( $code, "reached end\n", "ROTest (dry run) ($test)" );
194 $code =~ s/#READONLYTEST/make_readonly(value)/;
196 pir_output_is( $code, "reached end\n", "ROTest (read-only/okay) ($test)" );
199 pir_error_output_isnt( $code, "reached end\n", "ROTest (read-only/fail) ($test)" );
205 pir_error_output_unlike(
206 $library . <<'CODE', <<'OUTPUT', "ResizablePMCArray (non-recursive part)" );
212 foo = new 'ResizablePMCArray'
213 three = new 'Integer'
231 pir_error_output_unlike( $library . <<'CODE', <<'OUTPUT', "Objects" );
239 fooclass = newclass 'Foo'
240 addattribute fooclass, 'bar'
242 setattribute foo, 'bar', $P0
245 setattribute foo, 'bar', $P0
252 # RT#46821: should this work?
255 pir_output_unlike( $library . <<'CODE', <<'OUTPUT', "ResizablePMCArray -- Recursive" );
261 foo = new 'ResizablePMCArray'
262 three = new 'Integer'
268 print "before make_readonly\n"
272 # three = 4 # should fail -- is that what we want
286 # cperl-indent-level: 4
289 # vim: expandtab shiftwidth=4: