2 # Copyright (C) 2001-2009, Parrot Foundation.
7 t/op/globals.t - Global Variables
11 % prove t/op/globals.t
15 Tests the C<get_global> and C<set_global> operations.
24 .include 'test_more.pir'
31 get_set_global_with_key()
34 get_hll_global_not_found()
46 set_global "Integer", $P0
47 $P1 = get_global "Integer"
49 is($P1, 12, 'root_integer')
52 .sub 'get_null_global'
56 push_eh get_null_global_catch
59 goto get_null_global_end
61 get_null_global_catch:
65 ok($I0, 'get null global')
69 $P1 = get_global 'no_such_global'
70 ok(1, 'not_found_null get_global returns')
73 nok($I0, 'not_found_null get_global returns null')
76 .sub 'get_set_global_with_key'
77 $P0 = get_global ['Monkey'], 'do_explosion'
79 ok($I0, 'get_global of a sub with a key')
86 $P1 = get_hll_global [ "Monkey" ; "Toaster" ], "Explosion"
87 is($P1, "Ook...BANG!\n", 'get/set_global with key')
93 set_global [ "Toaster" ], "Explosion", $P0
96 #----------------------------------------------------------------
98 #----------------------------------------------------------------
102 .sub 'fetch_and_store'
109 set_global 'Integer', $P0
110 $P1 = get_hll_global 'Integer'
111 is($P1, 12, 'Fetch and store')
114 .sub 'find_null_global'
116 push_eh find_null_global_catch
117 $P1 = get_hll_global $S0
120 goto find_null_global_end
122 find_null_global_catch:
124 find_null_global_end:
125 ok($I0, 'Find null global')
128 .sub 'get_hll_global_not_found'
129 $P1 = get_hll_global 'no such global'
130 ok(1, 'get_hll_global returns if not found')
133 nok($I0, 'get_hll_global returns null if not found')
136 .sub 'find_store_with_key'
137 $P0 = get_global ['Monkey2'], 'do_explosion'
139 ok($I0, 'get_hll_global of a sub with a key')
143 .namespace ['Monkey2']
146 $P1 = get_hll_global [ "Monkey2" ; "Toaster" ], "Explosion"
147 is($P1, "Ook...BANG, again!\n", 'find/store global with key')
152 $P0 = "Ook...BANG, again!\n"
153 set_hll_global [ "Monkey2"; "Toaster" ], "Explosion", $P0
160 # vim: expandtab shiftwidth=4 ft=pir: