tagged release 0.7.1
[parrot.git] / languages / tcl / t / cmd_global.t
blob16e9e92a39efca7e6594cdd94c6fdea4a77eb0db
1 #!perl
3 # Copyright (C) 2004-2006, The Perl Foundation.
4 # $Id$
6 # the following lines re-execute this as a tcl script
7 # the \ at the end of these lines makes them a comment in tcl \
8 use lib qw(languages/tcl/lib tcl/lib lib ../lib ../../lib); # \
9 use Tcl::Test; #\
10 __DATA__
12 source lib/test_more.tcl
13 plan 7
15 eval_is {
16   catch {unset q}
17   proc a {} {
18     global q
19     return ok
20  }
21  a
22 } ok {missing unreferenced global}
24 eval_is {
25   catch {unset q}
26   proc a {} {
27     global q
28     puts $q
29  }
30  a
31 } {can't read "q": no such variable} {missing global}
33 eval_is {
34   catch {unset q}
35   proc a {} {
36     global q
37     return $q
38  }
39  set q 2
40  a
41 } 2 {one global}
43 eval_is {
44   catch {unset q r s}
45   proc a {} {
46     global q r s
47     return "$q $r $s"
48  }
49  set q 1
50  set r 2
51  set s 3
52  a
53 } {1 2 3} {few globals}
55 eval_is {
56   catch {unset a}
57   proc j {} {
58     global a
59     set a 1
60   }
61   j
62   set a
63 } 1 {vivify global}
65 eval_is {
66  set a 4
67  proc inca2 {} {
68   global a
69   set a [expr $a + 2]
70  }
71  set b $a
72  inca2
73  list $b $a
74 } {4 6} {changing value}
76 eval_is {
77   catch {unset a}
78   proc j {} {
79     global a
80   }
81   j
82   set a
83 } {can't read "a": no such variable} {nonvivifying global}