Ticket #1090: exporter.t.patch
File exporter.t.patch, 10.9 KB (added by kurahaupo, 12 years ago) |
---|
-
t/pmc/exporter.t
1 #!p erl1 #!parrot 2 2 # Copyright (C) 2007, Parrot 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 => 12;10 11 5 =head1 NAME 12 6 13 7 t/pmc/exporter.t - test the Exporter PMC … … 23 17 =cut 24 18 25 19 # L<PDD17/Exporter PMC> 26 pir_output_is( <<'CODE', <<'OUT', 'new' ); 27 .sub 'test' :main 20 21 .sub 'main' :main 22 .include 'test_more.pir' 23 plan(26) 24 25 test_1() # 3 tests 26 test_2() # 4 tests 27 test_3() # 5 tests 28 test_4() # 6 tests 29 test_5() # 1 tests 30 test_6() # 1 tests 31 test_7() # 1 tests 32 test_8() # 1 tests 33 test_9() # 1 tests 34 test_10() # 1 tests 35 test_11() # 1 tests 36 test_12() # 1 tests 37 38 .end 39 40 .sub 'test_1' 28 41 $P0 = new ['Exporter'] 29 say "ok 1 - $P0 = new ['Exporter']" 42 $I0 = isnull $P0 43 is( $I0, 0, 'Constructed "Exporter" object' ) 30 44 31 45 $I0 = isa $P0, 'Exporter' 32 if $I0 goto ok_233 print 'not ' 34 ok_2:35 say "ok 2 - isa $P0, 'Exporter'"46 ok( $I0, '... isa "Exporter"' ) 47 48 $I0 = can $P0, 'destination' 49 ok( $I0, '... can "destination"' ) 36 50 .end 37 CODE38 ok 1 - $P0 = new ['Exporter']39 ok 2 - isa $P0, 'Exporter'40 OUT41 51 42 pir_output_is( <<'CODE', <<'OUT', 'source' ); 43 .sub 'test' :main 52 .sub 'test_2' 44 53 $P0 = new ['Exporter'] 45 54 $P1 = $P0.'source'() 46 if null $P1 goto ok_1 47 print 'not ' 48 ok_1: 49 say 'ok 1 - source() returns PMCNULL upon Exporter init' 55 $I0 = isnull $P1 56 ok( $I0, 'source() returns PMCNULL upon Exporter init' ) 50 57 51 58 # get a NameSpace PMC for testing 52 59 # RT #46859 replace with make_namespace, when implemented … … 55 62 56 63 $P0.'source'(ns) 57 64 $P1 = $P0.'source'() 58 if $P1 == 'Eponymous' goto ok_2 59 print 'not ' 60 ok_2: 61 say 'ok 2 - source() with args sets source namespace' 65 is( $P1, 'Eponymous', 'source() with args sets source namespace' ) 62 66 63 67 $P1 = clone ns 64 68 $I0 = 1 65 69 push_eh ok_3 66 70 $P0.'source'(ns, $P1) 71 $I0 = 0 72 ok_3: 67 73 pop_eh 74 ok( $I0, 'source() with too many args fails' ) 68 75 69 print 'not '70 ok_3:71 say 'ok 3 - source() with too many args fails'72 73 76 push_eh ok_4 77 $I0 = 1 74 78 $P0.'source'('foo') 75 pop_eh 76 print 'not ' 79 $I0 = 0 77 80 78 81 ok_4: 79 say 'ok 4 - source() with non-namespace arg throws exception' 82 pop_eh 83 ok( $I0, 'source() with non-namespace arg throws exception' ) 80 84 .end 81 85 82 83 # RT #46859 replace with make_namespace, when implemented 84 .namespace ['Eponymous'] 85 .sub 'Eponymous' :anon 86 .end 87 CODE 88 ok 1 - source() returns PMCNULL upon Exporter init 89 ok 2 - source() with args sets source namespace 90 ok 3 - source() with too many args fails 91 ok 4 - source() with non-namespace arg throws exception 92 OUT 93 94 pir_output_is( <<'CODE', <<'OUT', 'destination' ); 95 .sub 'test' :main 86 .sub 'test_3' 96 87 $P0 = new ['Exporter'] 97 88 $P1 = $P0.'destination'() 98 unless null $P1 goto ok_1 99 print 'not ' 100 ok_1: 101 say 'ok 1 - destination() with no args returns destination namespace' 89 $I0 = isnull $P1 90 is( $I0, 0, 'destination() with no args returns destination namespace' ) 102 91 103 92 $P99 = get_namespace 104 if $P1 == $P99 goto ok_2 105 print 'not ' 106 ok_2: 107 say 'ok 2 - ...which is current namespace at first' 93 is( $P1, $P99, 'ok 2 - ...which is current namespace at first' ) 108 94 109 95 # get a NameSpace PMC for testing 110 96 # RT #46859 replace with make_namespace, when implemented 111 97 .local pmc ns 112 98 ns = get_namespace ['Eponymous'] 113 114 99 $P0.'destination'(ns) 115 100 $P1 = $P0.'destination'() 116 if $P1 == 'Eponymous' goto ok_3 117 print 'not ' 118 ok_3: 119 say 'ok 3 - destination() with args sets destination namespace' 101 is( $P1, 'Eponymous', 'destination() with args sets destination namespace' ) 120 102 121 103 $P1 = clone ns 122 123 104 push_eh ok_4 105 $I0 = 1 124 106 $P0.'destination'(ns, $P1) 107 $I0 = 0 108 ok_4: 125 109 pop_eh 110 ok( $I0, 'destination() with too many args fails' ) 126 111 127 print 'not '128 ok_4:129 say 'ok 4 - destination() with too many args fails'130 131 112 push_eh ok_5 113 $I0 = 1 132 114 $P0.'destination'('foo') 115 $I0 = 0 116 ok_5: 133 117 pop_eh 134 print 'not '118 ok( $I0, 'destination() with non-namespace arg throws exception' ) 135 119 136 ok_5:137 say 'ok 5 - destination() with non-namespace arg throws exception'138 120 .end 139 121 140 122 141 # RT #46859 replace with make_namespace, when implemented 142 .namespace ['Eponymous'] 143 .sub 'Eponymous' :anon 144 .end 145 CODE 146 ok 1 - destination() with no args returns destination namespace 147 ok 2 - ...which is current namespace at first 148 ok 3 - destination() with args sets destination namespace 149 ok 4 - destination() with too many args fails 150 ok 5 - destination() with non-namespace arg throws exception 151 OUT 152 153 pir_output_is( <<'CODE', <<'OUT', 'globals' ); 154 .sub 'test' :main 123 .sub 'test_4' 155 124 $P0 = new ['Exporter'] 156 125 157 126 $P1 = $P0.'globals'() 158 127 $I0 = isnull $P1 159 if $I0 goto ok_1 160 print 'not ' 161 ok_1: 162 say 'ok 1 - globals() returns PMCNULL upon Exporter init' 128 ok( $I0, 'globals() returns PMCNULL upon Exporter init' ) 163 129 164 130 # create an array to store globals in 165 131 $P99 = new ['ResizableStringArray'] … … 167 133 $P0.'globals'($P99) 168 134 $P1 = $P0.'globals'() 169 135 $I0 = isnull $P1 170 if $I0 goto ok_2 171 print 'not ' 172 ok_2: 173 say 'ok 2 - globals() with empty array arg sets PMCNULL' 136 ok( $I0, 'globals() with empty array arg sets PMCNULL' ) 174 137 175 138 $P99 = push 'Alex' 176 139 $P99 = push 'Prince' 177 140 141 $I9 = 1 178 142 $P0.'globals'($P99) 179 143 $P1 = $P0.'globals'() 180 144 $I0 = does $P1, 'hash' 145 eq $I0, 0, nok_3 181 146 $I99 = $P99 182 147 $I1 = $P1 183 unless $I0 == 1 goto nok_3 184 unless $I1 == $I99 goto nok_3 185 unless $I1 == 2 goto ok_3 148 ne $I1, $I99, nok_3 149 ne $I1, 2, ok_3 # <<< should this be nok_3 instead?!? 186 150 $I0 = exists $P1['Prince'] 187 unless $I0 gotonok_3151 eq $I0, 0, nok_3 188 152 $I0 = exists $P1['Alex'] 153 eq $I0, 0, nok_3 189 154 goto ok_3 190 155 nok_3: 191 print 'not '156 $I9 = 0 192 157 ok_3: 193 say 'ok 3 - globals() with array arg sets globals hash (hash with two keys)'158 ok( $I9, 'globals() with array arg sets globals hash (hash with two keys)' ) 194 159 195 160 # create a hash to store globals in 196 161 $P99 = new ['Hash'] … … 198 163 $P0.'globals'($P99) 199 164 $P1 = $P0.'globals'() 200 165 $I0 = isnull $P1 201 if $I0 goto ok_4 202 print 'not ' 203 ok_4: 204 say 'ok 4 - globals() with empty hash arg sets PMCNULL' 166 ok( $I0, 'globals() with empty hash arg sets PMCNULL' ) 205 167 206 168 $P99['Prince'] = '' 207 169 $P99['Alex'] = '' 208 170 171 $I9 = 1 209 172 $P0.'globals'($P99) 210 173 $P1 = $P0.'globals'() 211 174 $I99 = $P99 … … 218 181 unless $I0 goto nok_5 219 182 goto ok_5 220 183 nok_5: 221 print 'not '184 $I9 = 0 222 185 ok_5: 223 say 'ok 5 - globals() with hash arg sets globals hash (hash with two keys)'186 ok( $I9, 'globals() with hash arg sets globals hash (hash with two keys)' ) 224 187 225 226 188 $P98 = clone $P99 227 189 228 190 push_eh ok_6 191 $I1 = 1 229 192 $P0.'globals'($P99, $P98) 193 $I1 = 0 194 ok_6: 230 195 pop_eh 196 ok( $I1, 'globals() with too many args fails' ) 231 197 232 print 'not '233 ok_6:234 say 'ok 6 - globals() with too many args fails'235 236 198 .end 237 CODE238 ok 1 - globals() returns PMCNULL upon Exporter init239 ok 2 - globals() with empty array arg sets PMCNULL240 ok 3 - globals() with array arg sets globals hash (hash with two keys)241 ok 4 - globals() with empty hash arg sets PMCNULL242 ok 5 - globals() with hash arg sets globals hash (hash with two keys)243 ok 6 - globals() with too many args fails244 OUT245 199 246 pir_error_output_like( <<'CODE', <<'OUT', 'import - no args' ); 247 .sub 'test' :main 200 .sub 'test_5' 248 201 $P0 = new ['Exporter'] 249 202 203 push_eh e1 204 $I0 = 1 250 205 $P0.'import'() 251 say 'ok 1 - import() with no args throws an exception' 252 206 $I0 = 0 207 e1: 208 pop_eh 209 # /^source namespace not set\n/ 210 ok( $I0, 'import() with no args throws an exception' ) 253 211 .end 254 CODE255 /^source namespace not set\n/256 OUT257 212 258 pir_output_is( <<'CODE', <<'OUT', 'import - same source and destination namespaces' ); 259 .sub 'test' :main 213 .sub 'test_6' 260 214 .local pmc exporter, src 261 215 262 216 src = get_namespace 263 217 264 218 exporter = new ['Exporter'] 265 219 exporter.'import'( src :named('source'), src :named('destination'), 'plan ok' :named('globals') ) 266 plan(1)267 220 ok(1) 268 221 .end 269 222 270 .sub 'plan' 271 .param int one 272 say '1..1' 273 .end 274 275 .sub 'ok' 276 .param int one 277 say 'ok 1' 278 .end 279 CODE 280 1..1 281 ok 1 282 OUT 283 284 pir_output_is( <<'CODE', <<'OUT', 'import - globals as string' ); 285 .sub 'test' :main 223 .sub 'test_7' 286 224 load_bytecode 'Test/More.pbc' 287 225 .local pmc exporter, src 288 226 … … 290 228 291 229 exporter = new ['Exporter'] 292 230 exporter.'import'( src :named('source'), 'plan ok' :named('globals') ) 293 plan(1)294 231 ok(1) 295 232 .end 296 CODE297 1..1298 ok 1299 OUT300 233 301 pir_output_is( <<'CODE', <<'OUT', 'import - globals with source passed separately' ); 302 .sub 'test' :main 234 .sub 'test_8' 303 235 load_bytecode 'Test/More.pbc' 304 236 .local pmc exporter, src 305 237 … … 308 240 exporter = new ['Exporter'] 309 241 exporter.'source'( src ) 310 242 exporter.'import'( 'plan ok' :named('globals') ) 311 plan(1)312 243 ok(1) 313 244 .end 314 CODE315 1..1316 ok 1317 OUT318 245 319 pir_output_is( <<'CODE', <<'OUT', 'import - globals as array' ); 320 .sub 'test' :main 246 .sub 'test_9' 321 247 load_bytecode 'Test/More.pbc' 322 248 .local pmc exporter, src, globals 323 249 … … 328 254 329 255 exporter = new ['Exporter'] 330 256 exporter.'import'( src :named('source'), globals :named('globals') ) 331 plan(1)332 257 ok(1) 333 258 .end 334 CODE335 1..1336 ok 1337 OUT338 259 339 pir_output_is( <<'CODE', <<'OUT', 'import - globals as hash - null + empty string' ); 340 .sub 'test' :main 260 .sub 'test_10' 341 261 load_bytecode 'Test/More.pbc' 342 262 .local pmc exporter, src, globals, nul 343 263 … … 349 269 350 270 exporter = new ['Exporter'] 351 271 exporter.'import'( src :named('source'), globals :named('globals') ) 352 plan(1)353 272 ok(1) 354 273 .end 355 CODE356 1..1357 ok 1358 OUT359 274 360 pir_output_is( <<'CODE', <<'OUT', 'import - globals as hash - with dest names (latin)' ); 361 .sub 'test' :main 275 .sub 'test_11' 362 276 load_bytecode 'Test/More.pbc' 363 277 .local pmc exporter, src, globals 364 278 … … 369 283 370 284 exporter = new ['Exporter'] 371 285 exporter.'import'( src :named('source'), globals :named('globals') ) 372 consilium(1)286 #consilium(1) 373 287 rectus(1) 374 288 .end 375 CODE376 1..1377 ok 1378 OUT379 289 380 pir_output_is( <<'CODE', <<'OUT', 'import - globals with destination' ); 381 .sub 'test' :main 290 .sub 'test_12' 382 291 load_bytecode 'Test/More.pbc' 383 292 .local pmc exporter, src, dest, globals 384 293 … … 397 306 398 307 .namespace ['foo'] 399 308 .sub 'bar' 400 plan(1)401 309 ok(1) 402 310 .end 403 CODE404 1..1405 ok 1406 OUT407 311 312 # RT #46859 replace with make_namespace, when implemented 313 .namespace ['Eponymous'] 314 .sub 'Eponymous' :anon 315 .end 316 408 317 # RT #46861 test exporting mmd subs 409 318 410 319 # Local Variables: … … 412 321 # cperl-indent-level: 4 413 322 # fill-column: 100 414 323 # End: 415 # vim: expandtab shiftwidth=4 :324 # vim: expandtab shiftwidth=4 ft=pir: