Ticket #658: ro.t.patch
| File ro.t.patch, 5.8 KB (added by bobw, 4 years ago) |
|---|
-
ro.t
1 #! p erl2 # Copyright (C) 2006-200 7, ParrotFoundation.1 #! parrot 2 # Copyright (C) 2006-2009, The Perl Foundation. 3 3 # $Id$ 4 4 5 use strict;6 use warnings;7 use lib qw( . lib ../lib ../../lib );8 use Test::More;9 use Parrot::Test tests => 8;10 11 5 =head1 NAME 12 6 13 7 t/pmc/ro.t -- tests read-only value support … … 22 16 23 17 =cut 24 18 25 my $library = <<'CODE'; 19 .HLL "perl6" 20 21 .namespace [] 22 26 23 .include "except_types.pasm" 27 24 .sub make_readonly 28 25 .param pmc arg … … 39 36 zero = 0 40 37 setprop arg, '_ro', zero 41 38 .end 42 CODE43 39 44 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Integer set read-only is not writable" );45 40 .sub main :main 41 .include 'include/test_more.pir' 42 43 plan(12) 44 45 integer_set_read_only_is_not_writable() # 1 test 46 integer_set_read_only_can_be_read() # 6 tests 47 integer_stays_integer() # 1 test 48 integer_add() # 1 test 49 complex_i_add() # 1 test 50 resizablepmcarray_non_recursive_part() # 1 test 51 objects() # 1 test 52 # resizablepmcarray_recursive() # 53 .end 54 55 .sub integer_set_read_only_is_not_writable 46 56 .local pmc foo, eh 47 57 48 58 foo = new ['Integer'] … … 56 66 push_eh eh 57 67 foo = 43 58 68 pop_eh 59 print "no exception caught"69 ok( 0, "integer_set_read_only_is_not_writable" ) 60 70 end 61 71 62 72 eh_label: 73 .local string message 63 74 .get_results($P0) 64 say "RO exception caught"65 end75 message = $P0['message'] 76 is( message, "set_integer_native() in read-only instance of 'Integer'", "integer_set_read_only_is_not_writable" ) 66 77 .end 67 CODE68 RO exception caught69 OUTPUT70 78 71 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Integer set read-only can be read" ); 72 .sub main :main 79 .sub integer_set_read_only_can_be_read 73 80 .local pmc foo 74 81 .local pmc tmp 75 82 … … 77 84 foo = 42 78 85 79 86 make_readonly(foo) 80 print foo 81 print "\n" 87 is(foo, 42, 'foo initialised to 42 is readable after make_readonly') 82 88 $I0 = foo 89 is($I0, 42, 'foo copied to int correctly') 83 90 $S0 = foo 84 print $I0 85 print "\n" 86 print $S0 87 print "\n" 91 is($S0, 42, 'foo copied to string correctly') 88 92 89 93 tmp = new ['Integer'] 90 94 add tmp, foo, foo 91 print tmp 92 print "\n" 95 is(tmp, 84, 'foo can be added to foo correctly and stored elsewhere') 93 96 94 97 $P0 = foo 95 98 add foo, foo, foo 96 print foo 97 print "\n" 99 is(foo, 84, 'foo can be added to foo correctly and stored to foo') 98 100 99 print $P0 100 print "\n" 101 is($P0, 42, 'copied foo retains its value') 101 102 .end 102 CODE103 42104 42105 42106 84107 84108 42109 OUTPUT110 103 111 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Integer stays Integer" ); 112 .sub main :main 104 .sub integer_stays_integer 113 105 .local pmc foo 114 106 115 107 foo = new ['Integer'] … … 117 109 118 110 make_readonly(foo) 119 111 typeof $S0, foo 120 say $S0112 is($S0, 'Integer', 'integer_stays_integer') 121 113 .end 122 CODE123 Integer124 OUTPUT125 114 126 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Integer add" ); 127 .sub main :main 115 .sub integer_add 128 116 .local pmc foo, eh 129 117 130 118 foo = new ['Integer'] … … 139 127 foo += 16 140 128 pop_eh 141 129 142 say "no exception caught" 143 end 130 ok(0, 'integer_add') 144 131 145 132 eh_label: 133 .local string message 146 134 .get_results($P0) 147 say "RO exception caught"148 end135 message = $P0['message'] 136 is( message, "i_add_int() in read-only instance of 'Integer'", 'integer_add' ) 149 137 .end 150 CODE151 RO exception caught152 OUTPUT153 138 154 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Complex i_add" ); 155 .sub main :main 139 .sub complex_i_add 156 140 .local pmc foo, eh 157 141 158 142 foo = new ['Complex'] … … 167 151 push_eh eh 168 152 add foo, 4 169 153 pop_eh 170 say "no exception caught" 171 end 154 ok( 0, 'complex_i_add') 172 155 173 156 eh_label: 157 .local string message 174 158 .get_results($P0) 175 say "RO exception caught" 176 end 159 message = $P0['message'] 160 is( message, "i_add_int() in read-only instance of 'Complex'", 'complex_i_add' ) 161 177 162 .end 178 CODE179 RO exception caught180 OUTPUT181 163 182 pir_output_is( $library . <<'CODE', <<'OUTPUT', "ResizablePMCArray (non-recursive part)" ); 183 .sub main :main 164 .sub resizablepmcarray_non_recursive_part 184 165 .local pmc foo, three, four, eh 185 166 186 167 foo = new ['ResizablePMCArray'] … … 202 183 push_eh eh 203 184 foo[0] = four 204 185 pop_eh 205 say "no exception caught"206 end207 186 187 ok(0, 'resizablepmcarray_non_recursive_part') 188 208 189 eh_label: 190 .local string message 209 191 .get_results($P0) 210 say "RO exception caught"211 end192 message = $P0['message'] 193 is( message, "set_pmc_keyed_int() in read-only instance of 'ResizablePMCArray'", 'resizablepmcarray_non_recursive_part' ) 212 194 .end 213 CODE214 RO exception caught215 OUTPUT216 195 217 pir_output_is( $library . <<'CODE', <<'OUTPUT', "Objects" ); 218 .sub main :main 196 .sub objects 219 197 .local pmc fooclass, foo, eh, i 220 198 221 199 i = new ['Integer'] … … 237 215 setattribute foo, 'bar', i 238 216 pop_eh 239 217 240 say "no exception caught" 241 end 218 ok( 0, 'objects') 242 219 243 220 eh_label: 221 .local string message 244 222 .get_results($P0) 245 say "RO exception caught"246 end223 message = $P0['message'] 224 is( message, "set_attr_str() in read-only instance of 'Foo'", 'objects' ) 247 225 .end 248 CODE249 RO exception caught250 OUTPUT251 226 252 # RT #46821: should this work? 253 { 254 local $TODO = 1; 255 pir_output_unlike( $library . <<'CODE', <<'OUTPUT', "ResizablePMCArray -- Recursive" ); 256 .sub main :main 227 =pod 228 229 .sub resizablepmcarray_recursive 257 230 .local pmc foo 258 231 .local pmc three 259 232 .local pmc tmp … … 276 249 tmp = foo[0] 277 250 print tmp 278 251 .end 279 CODE280 /NOT OKAY/281 OUTPUT282 }283 252 284 # Local Variables: 285 # mode: cperl 286 # cperl-indent-level: 4 287 # fill-column: 100 288 # End: 289 # vim: expandtab shiftwidth=4: 253 =cut
