os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/init.test
First public contribution.
1 # Functionality covered: this file contains a collection of tests for the
2 # auto loading and namespaces.
4 # Sourcing this file into Tcl runs the tests and generates output for
5 # errors. No output means no errors were found.
7 # Copyright (c) 1997 Sun Microsystems, Inc.
8 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 # See the file "license.terms" for information on usage and redistribution
11 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13 # RCS: @(#) $Id: init.test,v 1.9.2.2 2004/10/26 20:14:36 dgp Exp $
15 if {[lsearch [namespace children] ::tcltest] == -1} {
16 package require tcltest
17 namespace import -force ::tcltest::*
20 # Clear out any namespaces called test_ns_*
21 catch {eval namespace delete [namespace children :: test_ns_*]}
23 # Six cases - white box testing
25 test init-1.1 {auto_qualify - absolute cmd - namespace} {
26 auto_qualify ::foo::bar ::blue
29 test init-1.2 {auto_qualify - absolute cmd - global} {
30 auto_qualify ::global ::sub
33 test init-1.3 {auto_qualify - no colons cmd - global} {
34 auto_qualify nocolons ::
37 test init-1.4 {auto_qualify - no colons cmd - namespace} {
38 auto_qualify nocolons ::sub
39 } {::sub::nocolons nocolons}
41 test init-1.5 {auto_qualify - colons in cmd - global} {
42 auto_qualify foo::bar ::
45 test init-1.6 {auto_qualify - colons in cmd - namespace} {
46 auto_qualify foo::bar ::sub
47 } {::sub::foo::bar ::foo::bar}
49 # Some additional tests
51 test init-1.7 {auto_qualify - multiples colons 1} {
52 auto_qualify :::foo::::bar ::blue
55 test init-1.8 {auto_qualify - multiple colons 2} {
56 auto_qualify :::foo ::bar
60 # we use a sub interp and auto_reset and double the tests because there is 2
61 # places where auto_loading occur (before loading the indexes files and after)
63 set testInterp [interp create]
64 interp eval $testInterp [list set argv $argv]
65 interp eval $testInterp [list package require tcltest]
66 interp eval $testInterp [list namespace import -force ::tcltest::*]
68 interp eval $testInterp {
71 catch {rename parray {}}
73 test init-2.0 {load parray - stage 1} {
74 set ret [catch {parray} error]
75 rename parray {} ; # remove it, for the next test - that should not fail.
77 } {1 {wrong # args: should be "parray a ?pattern?"}}
80 test init-2.1 {load parray - stage 2} {
81 set ret [catch {parray} error]
83 } {1 {wrong # args: should be "parray a ?pattern?"}}
87 catch {rename ::safe::setLogCmd {}}
88 #unset auto_index(::safe::setLogCmd)
91 test init-2.2 {load ::safe::setLogCmd - stage 1} {
93 rename ::safe::setLogCmd {} ; # should not fail
96 test init-2.3 {load ::safe::setLogCmd - stage 2} {
98 rename ::safe::setLogCmd {} ; # should not fail
102 catch {rename ::safe::setLogCmd {}}
104 test init-2.4 {load safe:::setLogCmd - stage 1} {
105 safe:::setLogCmd ; # intentionally 3 :
106 rename ::safe::setLogCmd {} ; # should not fail
109 test init-2.5 {load safe:::setLogCmd - stage 2} {
110 safe:::setLogCmd ; # intentionally 3 :
111 rename ::safe::setLogCmd {} ; # should not fail
115 catch {rename ::safe::setLogCmd {}}
117 test init-2.6 {load setLogCmd from safe:: - stage 1} {
118 namespace eval safe setLogCmd
119 rename ::safe::setLogCmd {} ; # should not fail
122 test init-2.7 {oad setLogCmd from safe:: - stage 2} {
123 namespace eval safe setLogCmd
124 rename ::safe::setLogCmd {} ; # should not fail
129 test init-2.8 {load tcl::HistAdd} -setup {
131 catch {rename ::tcl::HistAdd {}}
134 list [catch {tcl:::HistAdd} error] $error
136 rename ::tcl::HistAdd {} ;
137 } -result {1 {wrong # args: should be "tcl:::HistAdd command ?exec?"}}
140 test init-3.0 {random stuff in the auto_index, should still work} {
141 set auto_index(foo:::bar::blah) {
142 namespace eval foo {namespace eval bar {proc blah {} {return 1}}}
147 # Tests that compare the error stack trace generated when autoloading
148 # with that generated when no autoloading is necessary. Ideally they
149 # should be the same.
152 foreach arg [subst -nocommands -novariables {
157 {argument which is all on one line but which is of such great length that the Tcl C library will truncate it when appending it onto the global error stack}
158 {argument which spans multiple lines
159 and is long enough to be truncated and
160 " <- includes a false lead in the prune point search
161 and must be longer still to force truncation}
162 {contrived example: rare circumstance
163 where the point at which to prune the
164 error stack cannot be uniquely determined.
167 {contrived example: rare circumstance
168 where the point at which to prune the
169 error stack cannot be uniquely determined.
172 {argument that contains non-ASCII character, \u20ac, and which is of such great length that it will be longer than 150 bytes so it will be truncated by the Tcl C library}
175 test init-4.$count.0 {::errorInfo produced by [unknown]} {
177 catch {parray a b $arg}
178 set first $::errorInfo
179 catch {parray a b $arg}
180 set second $::errorInfo
181 string equal $first $second
184 test init-4.$count.1 {::errorInfo produced by [unknown]} {
186 namespace eval junk [list array set $arg [list 1 2 3 4]]
187 trace variable ::junk::$arg r \
188 "[list error [subst {Variable \"$arg\" is write-only}]] ;# "
189 catch {parray ::junk::$arg}
190 set first $::errorInfo
191 catch {parray ::junk::$arg}
192 set second $::errorInfo
193 string equal $first $second
200 } ;# End of [interp eval $testInterp]
203 interp delete $testInterp
204 ::tcltest::cleanupTests