1 | # Commands covered: eval |
---|
2 | # |
---|
3 | # This file contains a collection of tests for one or more of the Tcl |
---|
4 | # built-in commands. Sourcing this file into Tcl runs the tests and |
---|
5 | # generates output for errors. No output means no errors were found. |
---|
6 | # |
---|
7 | # Copyright (c) 1991-1993 The Regents of the University of California. |
---|
8 | # Copyright (c) 1994 Sun Microsystems, Inc. |
---|
9 | # Copyright (c) 1998-1999 by Scriptics Corporation. |
---|
10 | # |
---|
11 | # See the file "license.terms" for information on usage and redistribution |
---|
12 | # of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | # |
---|
14 | # RCS: @(#) $Id: eval.test,v 1.9 2006/10/09 19:15:44 msofer Exp $ |
---|
15 | |
---|
16 | if {[lsearch [namespace children] ::tcltest] == -1} { |
---|
17 | package require tcltest |
---|
18 | namespace import -force ::tcltest::* |
---|
19 | } |
---|
20 | |
---|
21 | test eval-1.1 {single argument} { |
---|
22 | eval {format 22} |
---|
23 | } 22 |
---|
24 | test eval-1.2 {multiple arguments} { |
---|
25 | set a {$b} |
---|
26 | set b xyzzy |
---|
27 | eval format $a |
---|
28 | } xyzzy |
---|
29 | test eval-1.3 {single argument} { |
---|
30 | eval concat a b c d e f g |
---|
31 | } {a b c d e f g} |
---|
32 | |
---|
33 | test eval-2.1 {error: not enough arguments} {catch eval} 1 |
---|
34 | test eval-2.2 {error: not enough arguments} { |
---|
35 | catch eval msg |
---|
36 | set msg |
---|
37 | } {wrong # args: should be "eval arg ?arg ...?"} |
---|
38 | test eval-2.3 {error in eval'ed command} { |
---|
39 | catch {eval {error "test error"}} |
---|
40 | } 1 |
---|
41 | test eval-2.4 {error in eval'ed command} { |
---|
42 | catch {eval {error "test error"}} msg |
---|
43 | set msg |
---|
44 | } {test error} |
---|
45 | test eval-2.5 {error in eval'ed command: setting errorInfo} { |
---|
46 | catch {eval { |
---|
47 | set a 1 |
---|
48 | error "test error" |
---|
49 | }} msg |
---|
50 | set ::errorInfo |
---|
51 | } "test error |
---|
52 | while executing |
---|
53 | \"error \"test error\"\" |
---|
54 | (\"eval\" body line 3) |
---|
55 | invoked from within |
---|
56 | \"eval { |
---|
57 | set a 1 |
---|
58 | error \"test error\" |
---|
59 | }\"" |
---|
60 | |
---|
61 | test eval-3.1 {eval and pure lists} { |
---|
62 | eval [list list 1 2 3 4 5] |
---|
63 | } {1 2 3 4 5} |
---|
64 | test eval-3.2 {concatenating eval and pure lists} { |
---|
65 | eval [list list 1] [list 2 3 4 5] |
---|
66 | } {1 2 3 4 5} |
---|
67 | test eval-3.3 {eval and canonical lists} { |
---|
68 | set cmd [list list 1 2 3 4 5] |
---|
69 | # Force existance of utf-8 rep |
---|
70 | set dummy($cmd) $cmd |
---|
71 | unset dummy |
---|
72 | eval $cmd |
---|
73 | } {1 2 3 4 5} |
---|
74 | test eval-3.4 {concatenating eval and canonical lists} { |
---|
75 | set cmd [list list 1] |
---|
76 | set cmd2 [list 2 3 4 5] |
---|
77 | # Force existance of utf-8 rep |
---|
78 | set dummy($cmd) $cmd |
---|
79 | set dummy($cmd2) $cmd2 |
---|
80 | unset dummy |
---|
81 | eval $cmd $cmd2 |
---|
82 | } {1 2 3 4 5} |
---|
83 | |
---|
84 | # cleanup |
---|
85 | ::tcltest::cleanupTests |
---|
86 | return |
---|