Debian Codegraph @

tests/eval.test

raw
1 # Commands covered: eval
2 #
3 # This file contains a collection of tests for one or more of the Tcl built-in
4 # commands. Sourcing this file into Tcl runs the tests and generates output
5 # 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 of
12 # this file, and for a DISCLAIMER OF ALL WARRANTIES.
13
14 if {"::tcltest" ni [namespace children]} {
15 package require tcltest 2.5
16 namespace import -force ::tcltest::*
17 }
18
19 test eval-1.1 {single argument} {
20 eval {format 22}
21 } 22
22 test eval-1.2 {multiple arguments} {
23 set a {$b}
24 set b xyzzy
25 eval format $a
26 } xyzzy
27 test eval-1.3 {single argument} {
28 eval concat a b c d e f g
29 } {a b c d e f g}
30
31 test eval-2.1 {error: not enough arguments} {catch eval} 1
32 test eval-2.2 {error: not enough arguments} {
33 catch eval msg
34 set msg
35 } {wrong # args: should be "eval arg ?arg ...?"}
36 test eval-2.3 {error in eval'ed command} {
37 catch {eval {error "test error"}}
38 } 1
39 test eval-2.4 {error in eval'ed command} {
40 catch {eval {error "test error"}} msg
41 set msg
42 } {test error}
43 test eval-2.5 {error in eval'ed command: setting errorInfo} {
44 catch {eval {
45 set a 1
46 error "test error"
47 }} msg
48 set ::errorInfo
49 } "test error
50 while executing
51 \"error \"test error\"\"
52 (\"eval\" body line 3)
53 invoked from within
54 \"eval {
55 set a 1
56 error \"test error\"
57 }\""
58
59 test eval-3.1 {eval and pure lists} {
60 eval [list list 1 2 3 4 5]
61 } {1 2 3 4 5}
62 test eval-3.2 {concatenating eval and pure lists} {
63 eval [list list 1] [list 2 3 4 5]
64 } {1 2 3 4 5}
65 test eval-3.3 {eval and canonical lists} {
66 set cmd [list list 1 2 3 4 5]
67 # Force existence of utf-8 rep
68 set dummy($cmd) $cmd
69 unset dummy
70 eval $cmd
71 } {1 2 3 4 5}
72 test eval-3.4 {concatenating eval and canonical lists} {
73 set cmd [list list 1]
74 set cmd2 [list 2 3 4 5]
75 # Force existence of utf-8 rep
76 set dummy($cmd) $cmd
77 set dummy($cmd2) $cmd2
78 unset dummy
79 eval $cmd $cmd2
80 } {1 2 3 4 5}
81
82 # cleanup
83 ::tcltest::cleanupTests
84 return
85
86 # Local Variables:
87 # mode: tcl
88 # fill-column: 78
89 # End: