Ticket #1090: exporter.t.patch

File exporter.t.patch, 10.9 KB (added by kurahaupo, 12 years ago)

Patch

  • t/pmc/exporter.t

     
    1 #!perl 
     1#!parrot 
    22# Copyright (C) 2007, Parrot Foundation. 
    33# $Id$ 
    44 
    5 use strict; 
    6 use warnings; 
    7 use lib qw( . lib ../lib ../../lib ); 
    8 use Test::More; 
    9 use Parrot::Test tests => 12; 
    10  
    115=head1 NAME 
    126 
    137t/pmc/exporter.t - test the Exporter PMC 
     
    2317=cut 
    2418 
    2519# 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' 
    2841    $P0 = new ['Exporter'] 
    29     say "ok 1 - $P0 = new ['Exporter']" 
     42    $I0 = isnull $P0 
     43    is( $I0, 0, 'Constructed "Exporter" object' ) 
    3044 
    3145    $I0 = isa $P0, 'Exporter' 
    32     if $I0 goto ok_2 
    33     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"' ) 
    3650.end 
    37 CODE 
    38 ok 1 - $P0 = new ['Exporter'] 
    39 ok 2 - isa $P0, 'Exporter' 
    40 OUT 
    4151 
    42 pir_output_is( <<'CODE', <<'OUT', 'source' ); 
    43 .sub 'test' :main 
     52.sub 'test_2' 
    4453    $P0 = new ['Exporter'] 
    4554    $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' ) 
    5057 
    5158    # get a NameSpace PMC for testing 
    5259    # RT #46859 replace with make_namespace, when implemented 
     
    5562 
    5663    $P0.'source'(ns) 
    5764    $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' ) 
    6266 
    6367    $P1 = clone ns 
    64  
     68    $I0 = 1 
    6569    push_eh ok_3 
    6670    $P0.'source'(ns, $P1) 
     71    $I0 = 0 
     72  ok_3: 
    6773    pop_eh 
     74    ok( $I0, 'source() with too many args fails' ) 
    6875 
    69     print 'not ' 
    70   ok_3: 
    71     say 'ok 3 - source() with too many args fails' 
    72  
    7376    push_eh ok_4 
     77    $I0 = 1 
    7478    $P0.'source'('foo') 
    75     pop_eh 
    76     print 'not ' 
     79    $I0 = 0 
    7780 
    7881  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' ) 
    8084.end 
    8185 
    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' 
    9687    $P0 = new ['Exporter'] 
    9788    $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' ) 
    10291 
    10392    $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' ) 
    10894 
    10995    # get a NameSpace PMC for testing 
    11096    # RT #46859 replace with make_namespace, when implemented 
    11197    .local pmc ns 
    11298    ns = get_namespace ['Eponymous'] 
    113  
    11499    $P0.'destination'(ns) 
    115100    $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' ) 
    120102 
    121103    $P1 = clone ns 
    122  
    123104    push_eh ok_4 
     105    $I0 = 1 
    124106    $P0.'destination'(ns, $P1) 
     107    $I0 = 0 
     108  ok_4: 
    125109    pop_eh 
     110    ok( $I0, 'destination() with too many args fails' ) 
    126111 
    127     print 'not ' 
    128   ok_4: 
    129     say 'ok 4 - destination() with too many args fails' 
    130  
    131112    push_eh ok_5 
     113    $I0 = 1 
    132114    $P0.'destination'('foo') 
     115    $I0 = 0 
     116  ok_5: 
    133117    pop_eh 
    134     print 'not ' 
     118    ok( $I0, 'destination() with non-namespace arg throws exception' ) 
    135119 
    136   ok_5: 
    137     say 'ok 5 - destination() with non-namespace arg throws exception' 
    138120.end 
    139121 
    140122 
    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' 
    155124    $P0 = new ['Exporter'] 
    156125 
    157126    $P1 = $P0.'globals'() 
    158127    $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' ) 
    163129 
    164130    # create an array to store globals in 
    165131    $P99 = new ['ResizableStringArray'] 
     
    167133    $P0.'globals'($P99) 
    168134    $P1 = $P0.'globals'() 
    169135    $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' ) 
    174137 
    175138    $P99 = push 'Alex' 
    176139    $P99 = push 'Prince' 
    177140 
     141    $I9 = 1 
    178142    $P0.'globals'($P99) 
    179143    $P1 = $P0.'globals'() 
    180144    $I0 = does $P1, 'hash' 
     145    eq $I0, 0, nok_3 
    181146    $I99 = $P99 
    182147    $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?!? 
    186150    $I0 = exists $P1['Prince'] 
    187     unless $I0 goto nok_3 
     151    eq $I0, 0, nok_3 
    188152    $I0 = exists $P1['Alex'] 
     153    eq $I0, 0, nok_3 
    189154    goto ok_3 
    190155  nok_3: 
    191     print 'not ' 
     156    $I9 = 0 
    192157  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)' ) 
    194159 
    195160    # create a hash to store globals in 
    196161    $P99 = new ['Hash'] 
     
    198163    $P0.'globals'($P99) 
    199164    $P1 = $P0.'globals'() 
    200165    $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' ) 
    205167 
    206168    $P99['Prince'] = '' 
    207169    $P99['Alex'] = '' 
    208170 
     171    $I9 = 1 
    209172    $P0.'globals'($P99) 
    210173    $P1 = $P0.'globals'() 
    211174    $I99 = $P99 
     
    218181    unless $I0 goto nok_5 
    219182    goto ok_5 
    220183  nok_5: 
    221     print 'not ' 
     184    $I9 = 0 
    222185  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)' ) 
    224187 
    225  
    226188    $P98 = clone $P99 
    227189 
    228190    push_eh ok_6 
     191    $I1 = 1 
    229192    $P0.'globals'($P99, $P98) 
     193    $I1 = 0 
     194  ok_6: 
    230195    pop_eh 
     196    ok( $I1, 'globals() with too many args fails' ) 
    231197 
    232     print 'not ' 
    233   ok_6: 
    234     say 'ok 6 - globals() with too many args fails' 
    235  
    236198.end 
    237 CODE 
    238 ok 1 - globals() returns PMCNULL upon Exporter init 
    239 ok 2 - globals() with empty array arg sets PMCNULL 
    240 ok 3 - globals() with array arg sets globals hash (hash with two keys) 
    241 ok 4 - globals() with empty hash arg sets PMCNULL 
    242 ok 5 - globals() with hash arg sets globals hash (hash with two keys) 
    243 ok 6 - globals() with too many args fails 
    244 OUT 
    245199 
    246 pir_error_output_like( <<'CODE', <<'OUT', 'import - no args' ); 
    247 .sub 'test' :main 
     200.sub 'test_5' 
    248201    $P0 = new ['Exporter'] 
    249202 
     203    push_eh e1 
     204    $I0 = 1 
    250205    $P0.'import'() 
    251     say 'ok 1 - import() with no args throws an exception' 
    252  
     206    $I0 = 0 
     207e1: 
     208    pop_eh 
     209# /^source namespace not set\n/ 
     210    ok( $I0, 'import() with no args throws an exception' ) 
    253211.end 
    254 CODE 
    255 /^source namespace not set\n/ 
    256 OUT 
    257212 
    258 pir_output_is( <<'CODE', <<'OUT', 'import - same source and destination namespaces' ); 
    259 .sub 'test' :main 
     213.sub 'test_6' 
    260214    .local pmc exporter, src 
    261215 
    262216    src      = get_namespace 
    263217 
    264218    exporter = new ['Exporter'] 
    265219    exporter.'import'( src :named('source'), src :named('destination'), 'plan ok' :named('globals') ) 
    266     plan(1) 
    267220    ok(1) 
    268221.end 
    269222 
    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' 
    286224    load_bytecode 'Test/More.pbc' 
    287225    .local pmc exporter, src 
    288226 
     
    290228 
    291229    exporter = new ['Exporter'] 
    292230    exporter.'import'( src :named('source'), 'plan ok' :named('globals') ) 
    293     plan(1) 
    294231    ok(1) 
    295232.end 
    296 CODE 
    297 1..1 
    298 ok 1 
    299 OUT 
    300233 
    301 pir_output_is( <<'CODE', <<'OUT', 'import - globals with source passed separately' ); 
    302 .sub 'test' :main 
     234.sub 'test_8' 
    303235    load_bytecode 'Test/More.pbc' 
    304236    .local pmc exporter, src 
    305237 
     
    308240    exporter = new ['Exporter'] 
    309241    exporter.'source'( src ) 
    310242    exporter.'import'( 'plan ok' :named('globals') ) 
    311     plan(1) 
    312243    ok(1) 
    313244.end 
    314 CODE 
    315 1..1 
    316 ok 1 
    317 OUT 
    318245 
    319 pir_output_is( <<'CODE', <<'OUT', 'import - globals as array' ); 
    320 .sub 'test' :main 
     246.sub 'test_9' 
    321247    load_bytecode 'Test/More.pbc' 
    322248    .local pmc exporter, src, globals 
    323249 
     
    328254 
    329255    exporter = new ['Exporter'] 
    330256    exporter.'import'( src :named('source'), globals :named('globals') ) 
    331     plan(1) 
    332257    ok(1) 
    333258.end 
    334 CODE 
    335 1..1 
    336 ok 1 
    337 OUT 
    338259 
    339 pir_output_is( <<'CODE', <<'OUT', 'import - globals as hash - null + empty string' ); 
    340 .sub 'test' :main 
     260.sub 'test_10' 
    341261    load_bytecode 'Test/More.pbc' 
    342262    .local pmc exporter, src, globals, nul 
    343263 
     
    349269 
    350270    exporter = new ['Exporter'] 
    351271    exporter.'import'( src :named('source'), globals :named('globals') ) 
    352     plan(1) 
    353272    ok(1) 
    354273.end 
    355 CODE 
    356 1..1 
    357 ok 1 
    358 OUT 
    359274 
    360 pir_output_is( <<'CODE', <<'OUT', 'import - globals as hash - with dest names (latin)' ); 
    361 .sub 'test' :main 
     275.sub 'test_11' 
    362276    load_bytecode 'Test/More.pbc' 
    363277    .local pmc exporter, src, globals 
    364278 
     
    369283 
    370284    exporter = new ['Exporter'] 
    371285    exporter.'import'( src :named('source'), globals :named('globals') ) 
    372     consilium(1) 
     286    #consilium(1) 
    373287    rectus(1) 
    374288.end 
    375 CODE 
    376 1..1 
    377 ok 1 
    378 OUT 
    379289 
    380 pir_output_is( <<'CODE', <<'OUT', 'import - globals with destination' ); 
    381 .sub 'test' :main 
     290.sub 'test_12' 
    382291    load_bytecode 'Test/More.pbc' 
    383292    .local pmc exporter, src, dest, globals 
    384293 
     
    397306 
    398307.namespace ['foo'] 
    399308.sub 'bar' 
    400     plan(1) 
    401309    ok(1) 
    402310.end 
    403 CODE 
    404 1..1 
    405 ok 1 
    406 OUT 
    407311 
     312# RT #46859 replace with make_namespace, when implemented 
     313.namespace ['Eponymous'] 
     314.sub 'Eponymous' :anon 
     315.end 
     316 
    408317# RT #46861 test exporting mmd subs 
    409318 
    410319# Local Variables: 
     
    412321#   cperl-indent-level: 4 
    413322#   fill-column: 100 
    414323# End: 
    415 # vim: expandtab shiftwidth=4: 
     324# vim: expandtab shiftwidth=4 ft=pir: