Ticket #1217: dynpmc_foo.patch

File dynpmc_foo.patch, 5.4 KB (added by bubaflub, 12 years ago)

(v2) forgot to indent a label

  • t/dynpmc/foo.t

    diff --git t/dynpmc/foo.t t/dynpmc/foo.t
    index 693e6c9..0c6c893 100644
     
    1 #! perl 
    2 # Copyright (C) 2005, Parrot Foundation. 
     1#! parrot 
     2# Copyright (C) 2001-2009, 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 => 9; 
    10 use Parrot::Config; 
    11  
    125=head1 NAME 
    136 
    147t/dynpmc/foo.t - Test for a very simple dynamic PMC 
     
    2316 
    2417=cut 
    2518 
    26 pir_output_is( << 'CODE', << 'OUTPUT', "get_integer" ); 
     19# load our Foo test (pseudo) language 
     20# it defines one PMC type "Foo" 
     21.HLL "Fool" 
     22.loadlib "foo_group" 
    2723 
    2824.sub main :main 
     25    .include 'test_more.pir' 
     26    plan(11) 
     27 
     28    test_get_integer() 
     29    test_loadlib_relative_pathname_no_ext() 
     30    test_loadlib_absolute_pathname_no_ext() 
     31    test_loadlib_relative_pathname_and_ext() 
     32    test_loadlib_absolute_pathname_and_ext() 
     33    test_inherited_add() 
     34    test_foo_subclass_isa_integer() 
     35    test_hll_1() 
     36    test_hll_2() 
     37.end 
     38 
     39.sub test_get_integer 
    2940    loadlib $P1, "foo_group" 
    3041    $P1 = new "Foo" 
    3142 
    3243    $I1 = $P1 
    33     print $I1 
    34     print "\n" 
     44    is($I1, 42, 'get integer') 
    3545.end 
    36 CODE 
    37 42 
    38 OUTPUT 
    3946 
    40 pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with relative pathname, no ext" ); 
    41 .sub main :main 
     47.sub test_loadlib_relative_pathname_no_ext  
    4248    ## load a relative pathname without the extension.  loadlib will convert the 
    4349    ## '/' characters to '\\' on windows. 
    4450    $S0 = "runtime/parrot/dynext/foo_group" 
     
    4753    ## ensure that we can still make Foo instances. 
    4854    $P1 = new "Foo" 
    4955    $I1 = $P1 
    50     print $I1 
    51     print "\n" 
     56    is($I1, 42, 'test loadlib with relative pathname, no ext') 
    5257.end 
    53 CODE 
    54 42 
    55 OUTPUT 
    5658 
    57 pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with absolute pathname, no ext" ); 
    58 .sub main :main 
     59.sub test_loadlib_absolute_pathname_no_ext  
    5960    ## get cwd in $S0. 
    6061    .include "iglobals.pasm" 
    6162    $P11 = getinterp 
     
    7172    ## ensure that we can still make Foo instances. 
    7273    $P1 = new "Foo" 
    7374    $I1 = $P1 
    74     print $I1 
    75     print "\n" 
     75    is($I1, 42, 'loadlib with absolute pathname, no ext') 
    7676.end 
    77 CODE 
    78 42 
    79 OUTPUT 
    8077 
    81 pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with relative pathname & ext" ); 
    82 .sub main :main 
     78.sub test_loadlib_relative_pathname_and_ext 
    8379    ## get load_ext in $S0. 
    8480    .include "iglobals.pasm" 
    8581    $P11 = getinterp 
     
    9389    ## ensure that we can still make Foo instances. 
    9490    $P1 = new "Foo" 
    9591    $I1 = $P1 
    96     print $I1 
    97     print "\n" 
     92    is($I1, 42, 'loadlib with relative pathname & ext') 
    9893.end 
    99 CODE 
    100 42 
    101 OUTPUT 
    10294 
    103 pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with absolute pathname & ext" ); 
    104 .sub main :main 
     95.sub test_loadlib_absolute_pathname_and_ext 
    10596    ## get cwd in $S0, load_ext in $S1. 
    10697    .include "iglobals.pasm" 
    10798    $P11 = getinterp 
     
    119110    ## ensure that we can still make Foo instances. 
    120111    $P1 = new "Foo" 
    121112    $I1 = $P1 
    122     print $I1 
    123     print "\n" 
     113    is($I1, 42, 'loadlib with absolute pathname & ext') 
    124114.end 
    125 CODE 
    126 42 
    127 OUTPUT 
    128  
    129 SKIP: { 
    130     skip( "No BigInt Lib configured", 1 ) if !$PConfig{gmp}; 
    131115 
    132     pir_output_is( << 'CODE', << 'OUTPUT', "inherited add" ); 
    133 .sub _main :main 
     116.sub test_inherited_add 
     117    .include "iglobals.pasm"  
     118    .local pmc config_hash, interp  
    134119    .local pmc d, l, r 
     120    interp = getinterp  
     121    config_hash = interp[.IGLOBALS_CONFIG_HASH]  
     122    $S0 = config_hash['gmp']  
     123    unless $S0 goto no_bigint 
     124 
    135125    $P0 = loadlib "foo_group" 
    136     print "ok\n" 
     126    ok(1, 'inherited add - loadlib') 
    137127    l = new "Foo" 
    138128    l = 42 
    139129    r = new 'BigInt' 
    140130    r = 0x7ffffff 
    141131    d = new 'Undef' 
    142132    add d, l, r 
    143     print d 
    144     print "\n" 
     133    is(d, 134217769, 'inherited add') 
    145134    $S0 = typeof d 
    146     print $S0 
    147     print "\n" 
     135    is($S0, 'BigInt', 'inherited add - typeof') 
     136    .return() 
     137  no_bigint: 
     138    skip( 3, 'No BigInt Lib configured' ) 
    148139.end 
    149 CODE 
    150 ok 
    151 134217769 
    152 BigInt 
    153 OUTPUT 
    154  
    155 } 
    156140 
    157 pir_output_is( <<'CODE', <<'OUTPUT', "Foo subclass isa Integer" ); 
    158 .sub main :main 
     141.sub test_foo_subclass_isa_integer  
    159142    .local pmc F, f, d, r 
    160143    loadlib F, "foo_group" 
    161144    f = new "Foo" 
     
    164147    r = new 'Integer' 
    165148    r = 2 
    166149    d = f - r 
    167     print d 
    168     print "\n" 
     150    is(d, 144, 'Foo subclass isa Integer') 
    169151.end 
    170 CODE 
    171 144 
    172 OUTPUT 
    173152 
    174 pir_output_is( << 'CODE', << 'OUTPUT', ".HLL 1" ); 
    175 # load our Foo test (pseudo) language 
    176 # it defines one PMC type "Foo" 
    177 .HLL "Fool" 
    178 .loadlib "foo_group" 
    179 .sub main :main 
     153.sub test_hll_1 
    180154    new $P1, "Foo"      # load by name 
    181155    $I1 = $P1 
    182     print $I1 
    183     print "\n" 
     156    is($I1, 42, '.HLL 1') 
    184157.end 
    185 CODE 
    186 42 
    187 OUTPUT 
    188158 
    189 pir_output_is( << 'CODE', << 'OUTPUT', ".HLL 2" ); 
    190 .HLL "Fool" 
    191 .loadlib "foo_group" 
    192 .sub main :main 
     159.sub test_hll_2 
    193160    new $P1, 'Foo'       # load by index 
    194161    $I1 = $P1 
    195     print $I1 
    196     print "\n" 
     162    is($I1, 42, '.HLL 2') 
    197163.end 
    198 CODE 
    199 42 
    200 OUTPUT 
    201  
    202164# Local Variables: 
    203165#   mode: cperl 
    204166#   cperl-indent-level: 4 
    205167#   fill-column: 100 
    206168# End: 
    207 # vim: expandtab shiftwidth=4: 
     169# vim: expandtab shiftwidth=4 filetype=pir: