tagged release 0.7.1
[parrot.git] / languages / tcl / t / cmd_uplevel.t
blob765348034d186c3c9286f717470cf76015691383
1 #! perl
3 # Copyright (C) 2006-2007, The Perl Foundation.
4 # $Id$
6 use strict;
7 use warnings;
8 use lib qw(tcl/lib ./lib ../lib ../../lib ../../../lib);
10 use Parrot::Test tests => 10;
11 use Test::More;
13 language_output_is( "tcl", <<'TCL', <<'OUT', 'upvar $command' );
14   proc test {} {uplevel {set a 42}}
15   test
16   puts $a
17 TCL
19 OUT
21 language_output_is( "tcl", <<'TCL', <<'OUT', "uplevel - bad args" );
22   uplevel
23 TCL
24 wrong # args: should be "uplevel ?level? command ?arg ...?"
25 OUT
27 language_output_is( 'tcl', <<'TCL', <<'OUT', 'uplevel - bad args' );
28   uplevel 0
29 TCL
30 wrong # args: should be "uplevel ?level? command ?arg ...?"
31 OUT
33 language_output_is( "tcl", <<'TCL', <<'OUT', "uplevel - bad level" );
34   uplevel a b
35 TCL
36 bad level "a"
37 OUT
39 language_output_is( "tcl", <<'TCL', <<'OUT', "uplevel 0" );
40   proc test {} {uplevel 0 {set a 42}; puts $a}
41   test
42 TCL
44 OUT
46 language_output_is( "tcl", <<'TCL', <<'OUT', "uplevel #0" );
47   proc a {} {uplevel #0 {set a 42}}
48   proc b {} {a}
49   a
50   puts $a
51 TCL
53 OUT
55 language_output_is( "tcl", <<'TCL', <<'OUT', "uplevel - from one lexical to another" );
56   proc add2to_a {} {uplevel {set a [expr {$a+2}]}}
57   proc test {} { set a 1; add2to_a; puts $a }
58   test
59 TCL
61 OUT
63 language_output_is( 'tcl',
64     <<'TCL', <<'OUT', 'uplevel - from one lexical in an uplevel to another' );
65 proc test {} {
66     set ok 0
67     level1
68     puts $ok
70 proc level1 {} {
71     uplevel #0 deep1
73 proc deep1 {} {
74     set ok 0
75     deep2
76     puts $ok
78 proc deep2 {} {
79     uplevel 1 {set ok 1}
81 test
82 TCL
85 OUT
87 language_output_is( 'tcl', <<'TCL', <<'OUT', 'uplevel - reset environent on execption' );
88   proc test {} {catch {uplevel #0 {error "foo"}}}
89   set a 4
90   test
91   puts $a
92 TCL
94 OUT
96 language_output_is( 'tcl', <<'TCL', <<'OUT', 'uplevel - info level interaction' );
97   proc test {} {uplevel {info level}}
98   puts [test]
99 TCL
103 # Local Variables:
104 #   mode: cperl
105 #   cperl-indent-level: 4
106 #   fill-column: 100
107 # End:
108 # vim: expandtab shiftwidth=4: