2 # Copyright (C) 2009, Parrot Foundation.
7 t/pmc/context.t - test Context PMC
11 % prove t/pmc/context.t
15 Tests the Context PMC.
17 TODO: Implement real tests when Context PMC will be migrated to use ATTRibutes.
24 .include 'test_more.pir'
30 $P0 = get_hll_global ['Foo'], 'load'
33 $P0.'test_inspect'() # 16 tests
35 test_backtrace() # 3 tests
41 ok(1, 'Instantiated .Context')
44 # Put test_inspect into Namespace, as method, with outer, etc.
51 .sub 'test_inspect' :method :outer('load')
52 .include 'test_more.pir'
62 ok($I0, "Got Context")
64 # Check current_sub first. Other tests relying on it
65 $P0 = ctx['current_sub']
66 is($P0, 'test_inspect', 'Got Context.current_sub')
68 $P0 = ctx['caller_ctx']
69 $I0 = isa $P0, 'Context'
70 ok($I0, 'Got Context.caller_ctx')
71 $P0 = $P0['current_sub']
72 is($P0, 'main', '... from proper Sub')
74 $P0 = ctx['outer_ctx']
75 $I0 = isa $P0, 'Context'
76 ok($I0, 'Got Context.outer_ctx')
77 $P0 = $P0['current_sub']
78 is($P0, 'load', '... from proper Sub')
81 $I0 = isa $P0, 'LexPad'
82 ok($I0, 'Got Context.lex_pad')
85 ok($I0, '... with proper content')
87 $P0 = ctx['current_cont']
88 $I0 = isa $P0, 'Continuation'
89 ok($I0, 'Got Context.current_cont')
91 $P0 = ctx['current_object']
93 ok($I0, 'Got Context.current_object')
95 $P0 = ctx['current_namespace']
96 ok($P0, 'Got Context.current_namespace')
97 $P1 = $P0['test_inspect']
98 is($P1, 'test_inspect', '... with proper content')
102 $P0 = ctx['handlers']
106 # Now we should have one more handler
107 $P0 = ctx['handlers']
110 is($I0, $I1, 'Got Context.handlers')
112 # Check absurd fields
114 $P0 = ctx['world_domination']
118 ok($I0, "No world domination in this Context")
120 # Current HLL shouldn't be zero
121 $P0 = ctx['current_HLL']
123 ok($I0, 'Got Context.current_HLL')
125 $P0 = ctx['current_hll']
126 ok($P0, 'FOO', 'Got Context.current_hll')
135 .sub 'test_backtrace'
139 ok($I0, "Got Context.backtrace()")
141 # We should have more than 3 elements
144 ok($I1, "... got enough elements")
146 # First one should be "test_bt2"
149 is($P2, 'test_bt2', "... with correct first element")
160 $P2 = $P1.'backtrace'()
168 # vim: expandtab shiftwidth=4 ft=pir: