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. |
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 => 9; |
10 | | use Parrot::Config; |
11 | | |
12 | 5 | =head1 NAME |
13 | 6 | |
14 | 7 | t/dynpmc/foo.t - Test for a very simple dynamic PMC |
… |
… |
|
23 | 16 | |
24 | 17 | =cut |
25 | 18 | |
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" |
27 | 23 | |
28 | 24 | .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 |
29 | 40 | loadlib $P1, "foo_group" |
30 | 41 | $P1 = new "Foo" |
31 | 42 | |
32 | 43 | $I1 = $P1 |
33 | | print $I1 |
34 | | print "\n" |
| 44 | is($I1, 42, 'get integer') |
35 | 45 | .end |
36 | | CODE |
37 | | 42 |
38 | | OUTPUT |
39 | 46 | |
40 | | pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with relative pathname, no ext" ); |
41 | | .sub main :main |
| 47 | .sub test_loadlib_relative_pathname_no_ext |
42 | 48 | ## load a relative pathname without the extension. loadlib will convert the |
43 | 49 | ## '/' characters to '\\' on windows. |
44 | 50 | $S0 = "runtime/parrot/dynext/foo_group" |
… |
… |
|
47 | 53 | ## ensure that we can still make Foo instances. |
48 | 54 | $P1 = new "Foo" |
49 | 55 | $I1 = $P1 |
50 | | print $I1 |
51 | | print "\n" |
| 56 | is($I1, 42, 'test loadlib with relative pathname, no ext') |
52 | 57 | .end |
53 | | CODE |
54 | | 42 |
55 | | OUTPUT |
56 | 58 | |
57 | | pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with absolute pathname, no ext" ); |
58 | | .sub main :main |
| 59 | .sub test_loadlib_absolute_pathname_no_ext |
59 | 60 | ## get cwd in $S0. |
60 | 61 | .include "iglobals.pasm" |
61 | 62 | $P11 = getinterp |
… |
… |
|
71 | 72 | ## ensure that we can still make Foo instances. |
72 | 73 | $P1 = new "Foo" |
73 | 74 | $I1 = $P1 |
74 | | print $I1 |
75 | | print "\n" |
| 75 | is($I1, 42, 'loadlib with absolute pathname, no ext') |
76 | 76 | .end |
77 | | CODE |
78 | | 42 |
79 | | OUTPUT |
80 | 77 | |
81 | | pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with relative pathname & ext" ); |
82 | | .sub main :main |
| 78 | .sub test_loadlib_relative_pathname_and_ext |
83 | 79 | ## get load_ext in $S0. |
84 | 80 | .include "iglobals.pasm" |
85 | 81 | $P11 = getinterp |
… |
… |
|
93 | 89 | ## ensure that we can still make Foo instances. |
94 | 90 | $P1 = new "Foo" |
95 | 91 | $I1 = $P1 |
96 | | print $I1 |
97 | | print "\n" |
| 92 | is($I1, 42, 'loadlib with relative pathname & ext') |
98 | 93 | .end |
99 | | CODE |
100 | | 42 |
101 | | OUTPUT |
102 | 94 | |
103 | | pir_output_is( << 'CODE', << 'OUTPUT', "loadlib with absolute pathname & ext" ); |
104 | | .sub main :main |
| 95 | .sub test_loadlib_absolute_pathname_and_ext |
105 | 96 | ## get cwd in $S0, load_ext in $S1. |
106 | 97 | .include "iglobals.pasm" |
107 | 98 | $P11 = getinterp |
… |
… |
|
119 | 110 | ## ensure that we can still make Foo instances. |
120 | 111 | $P1 = new "Foo" |
121 | 112 | $I1 = $P1 |
122 | | print $I1 |
123 | | print "\n" |
| 113 | is($I1, 42, 'loadlib with absolute pathname & ext') |
124 | 114 | .end |
125 | | CODE |
126 | | 42 |
127 | | OUTPUT |
128 | | |
129 | | SKIP: { |
130 | | skip( "No BigInt Lib configured", 1 ) if !$PConfig{gmp}; |
131 | 115 | |
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 |
134 | 119 | .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 | |
135 | 125 | $P0 = loadlib "foo_group" |
136 | | print "ok\n" |
| 126 | ok(1, 'inherited add - loadlib') |
137 | 127 | l = new "Foo" |
138 | 128 | l = 42 |
139 | 129 | r = new 'BigInt' |
140 | 130 | r = 0x7ffffff |
141 | 131 | d = new 'Undef' |
142 | 132 | add d, l, r |
143 | | print d |
144 | | print "\n" |
| 133 | is(d, 134217769, 'inherited add') |
145 | 134 | $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' ) |
148 | 139 | .end |
149 | | CODE |
150 | | ok |
151 | | 134217769 |
152 | | BigInt |
153 | | OUTPUT |
154 | | |
155 | | } |
156 | 140 | |
157 | | pir_output_is( <<'CODE', <<'OUTPUT', "Foo subclass isa Integer" ); |
158 | | .sub main :main |
| 141 | .sub test_foo_subclass_isa_integer |
159 | 142 | .local pmc F, f, d, r |
160 | 143 | loadlib F, "foo_group" |
161 | 144 | f = new "Foo" |
… |
… |
|
164 | 147 | r = new 'Integer' |
165 | 148 | r = 2 |
166 | 149 | d = f - r |
167 | | print d |
168 | | print "\n" |
| 150 | is(d, 144, 'Foo subclass isa Integer') |
169 | 151 | .end |
170 | | CODE |
171 | | 144 |
172 | | OUTPUT |
173 | 152 | |
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 |
180 | 154 | new $P1, "Foo" # load by name |
181 | 155 | $I1 = $P1 |
182 | | print $I1 |
183 | | print "\n" |
| 156 | is($I1, 42, '.HLL 1') |
184 | 157 | .end |
185 | | CODE |
186 | | 42 |
187 | | OUTPUT |
188 | 158 | |
189 | | pir_output_is( << 'CODE', << 'OUTPUT', ".HLL 2" ); |
190 | | .HLL "Fool" |
191 | | .loadlib "foo_group" |
192 | | .sub main :main |
| 159 | .sub test_hll_2 |
193 | 160 | new $P1, 'Foo' # load by index |
194 | 161 | $I1 = $P1 |
195 | | print $I1 |
196 | | print "\n" |
| 162 | is($I1, 42, '.HLL 2') |
197 | 163 | .end |
198 | | CODE |
199 | | 42 |
200 | | OUTPUT |
201 | | |
202 | 164 | # Local Variables: |
203 | 165 | # mode: cperl |
204 | 166 | # cperl-indent-level: 4 |
205 | 167 | # fill-column: 100 |
206 | 168 | # End: |
207 | | # vim: expandtab shiftwidth=4: |
| 169 | # vim: expandtab shiftwidth=4 filetype=pir: |