2 # Copyright (C) 2009, Parrot Foundation.
7 t/pmc/context.t - test CallContext PMC
11 % prove t/pmc/context.t
15 Tests the CallContext PMC.
17 TODO: Implement real tests when CallContext 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
39 $P0 = new ['CallContext']
41 ok(1, 'Instantiated .CallContext')
44 # Put test_inspect into Namespace, as method, with outer, etc.
51 .sub 'test_inspect' :method :nsentry('test_inspect') :outer('load')
52 .include 'test_more.pir'
62 ok($I0, "Got CallContext")
64 # Check current_sub first. Other tests relying on it
65 $P0 = getattribute ctx, 'current_sub'
66 is($P0, 'test_inspect', 'Got CallContext.current_sub')
68 $P0 = getattribute ctx, 'caller_ctx'
69 $I0 = isa $P0, 'CallContext'
70 ok($I0, 'Got CallContext.caller_ctx')
71 $P0 = getattribute $P0, 'current_sub'
72 is($P0, 'main', '... from proper Sub')
74 $P0 = getattribute ctx, 'outer_ctx'
75 $I0 = isa $P0, 'CallContext'
76 ok($I0, 'Got CallContext.outer_ctx')
77 $P0 = getattribute $P0, 'current_sub'
78 is($P0, 'load', '... from proper Sub')
80 $P0 = getattribute ctx, 'lex_pad'
81 $I0 = isa $P0, 'LexPad'
82 ok($I0, 'Got CallContext.lex_pad')
85 ok($I0, '... with proper content')
87 $P0 = getattribute ctx, 'current_cont'
88 $I0 = isa $P0, 'Continuation'
89 ok($I0, 'Got CallContext.current_cont')
91 $P0 = getattribute ctx, 'current_object'
93 ok($I0, 'Got CallContext.current_object')
95 $P0 = getattribute ctx, 'current_namespace'
96 ok($P0, 'Got CallContext.current_namespace')
97 $P1 = $P0['test_inspect']
98 is($P1, 'test_inspect', '... with proper content')
102 $P0 = getattribute ctx, 'handlers'
106 # Now we should have one more handler
107 $P0 = getattribute ctx, 'handlers'
110 is($I0, $I1, 'Got CallContext.handlers')
112 # Check absurd fields
114 $P0 = getattribute ctx, 'world_domination'
118 ok($I0, "No world domination in this CallContext")
120 # Current HLL shouldn't be zero
121 $P0 = getattribute ctx, 'current_HLL'
123 ok($I0, 'Got CallContext.current_HLL')
125 $P0 = getattribute ctx, 'current_hll'
126 ok($P0, 'FOO', 'Got CallContext.current_hll')
135 .sub 'test_backtrace'
139 ok($I0, "Got CallContext.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: