os/persistentdata/persistentstorage/sqlite3api/TEST/TCL/tcldistribution/tests/namespace.test
First public contribution.
1 # Functionality covered: this file contains a collection of tests for the
2 # procedures in tclNamesp.c that implement Tcl's basic support for
3 # namespaces. Other namespace-related tests appear in variable.test.
5 # Sourcing this file into Tcl runs the tests and generates output for
6 # errors. No output means no errors were found.
8 # Copyright (c) 1997 Sun Microsystems, Inc.
9 # Copyright (c) 1998-2000 by Scriptics Corporation.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 # RCS: @(#) $Id: namespace.test,v 1.21.2.10 2006/10/04 17:59:06 dgp Exp $
16 if {[lsearch [namespace children] ::tcltest] == -1} {
17 package require tcltest 2
18 namespace import -force ::tcltest::*
21 # Clear out any namespaces called test_ns_*
22 catch {eval namespace delete [namespace children :: test_ns_*]}
24 test namespace-1.1 {TclInitNamespaces, GetNamespaceFromObj, NamespaceChildrenCmd} {
25 namespace children :: test_ns_*
29 test namespace-2.1 {Tcl_GetCurrentNamespace} {
30 list [namespace current] [namespace eval {} {namespace current}] \
31 [namespace eval {} {namespace current}]
33 test namespace-2.2 {Tcl_GetCurrentNamespace} {
35 lappend l [namespace current]
36 namespace eval test_ns_1 {
37 lappend l [namespace current]
39 lappend l [namespace current]
42 lappend l [namespace current]
44 } {:: ::test_ns_1 ::test_ns_1::foo ::}
46 test namespace-3.1 {Tcl_GetGlobalNamespace} {
47 namespace eval test_ns_1 {namespace eval foo {namespace eval bar {} } }
48 # namespace children uses Tcl_GetGlobalNamespace
49 namespace eval test_ns_1 {namespace children foo b*}
50 } {::test_ns_1::foo::bar}
52 test namespace-4.1 {Tcl_PushCallFrame with isProcCallFrame=1} {
53 namespace eval test_ns_1 {
60 test_ns_1::p ;# does Tcl_PushCallFrame to push p's namespace
62 test namespace-4.2 {Tcl_PushCallFrame with isProcCallFrame=0} {
63 namespace eval test_ns_1::baz {} ;# does Tcl_PushCallFrame to create baz
64 proc test_ns_1::baz::p {} {
71 test namespace-5.1 {Tcl_PopCallFrame, no vars} {
72 namespace eval test_ns_1::blodge {} ;# pushes then pops frame
74 test namespace-5.2 {Tcl_PopCallFrame, local vars must be deleted} {
75 proc test_ns_1::r {} {
78 test_ns_1::r ;# pushes then pop's r's frame
81 test namespace-6.1 {Tcl_CreateNamespace} {
82 catch {eval namespace delete [namespace children :: test_ns_*]}
83 list [lsort [namespace children :: test_ns_*]] \
84 [namespace eval test_ns_1 {namespace current}] \
85 [namespace eval test_ns_2 {namespace current}] \
86 [namespace eval ::test_ns_3 {namespace current}] \
87 [namespace eval ::test_ns_4 \
88 {namespace eval foo {namespace current}}] \
89 [namespace eval ::test_ns_5 \
90 {namespace eval ::test_ns_6 {namespace current}}] \
91 [lsort [namespace children :: test_ns_*]]
92 } {{} ::test_ns_1 ::test_ns_2 ::test_ns_3 ::test_ns_4::foo ::test_ns_6 {::test_ns_1 ::test_ns_2 ::test_ns_3 ::test_ns_4 ::test_ns_5 ::test_ns_6}}
93 test namespace-6.2 {Tcl_CreateNamespace, odd number of :'s in name is okay} {
94 list [namespace eval :::test_ns_1::::foo {namespace current}] \
95 [namespace eval test_ns_2:::::foo {namespace current}]
96 } {::test_ns_1::foo ::test_ns_2::foo}
97 test namespace-6.3 {Tcl_CreateNamespace, trailing ::s in ns name are ignored} {
98 list [catch {namespace eval test_ns_7::: {namespace current}} msg] $msg
100 test namespace-6.4 {Tcl_CreateNamespace, trailing ::s in ns name are ignored} {
101 catch {eval namespace delete [namespace children :: test_ns_*]}
102 namespace eval test_ns_1:: {
103 namespace eval test_ns_2:: {}
104 namespace eval test_ns_3:: {}
106 lsort [namespace children ::test_ns_1]
107 } [lsort {::test_ns_1::test_ns_2 ::test_ns_1::test_ns_3}]
108 test namespace-6.5 {Tcl_CreateNamespace, relative ns names now only looked up in current ns} {
110 namespace eval test_ns_2 {namespace current}
113 lappend l [namespace eval test_ns_1 $trigger]
114 namespace eval test_ns_1::test_ns_2 {}
115 lappend l [namespace eval test_ns_1 $trigger]
116 } {::test_ns_1::test_ns_2 ::test_ns_1::test_ns_2}
118 test namespace-7.1 {Tcl_DeleteNamespace, active call frames in ns} {
119 catch {eval namespace delete [namespace children :: test_ns_*]}
120 namespace eval test_ns_1 {
122 namespace delete [namespace current]
123 return [namespace current]
126 list [test_ns_1::p] [catch {test_ns_1::p} msg] $msg
127 } {::test_ns_1 1 {invalid command name "test_ns_1::p"}}
128 test namespace-7.2 {Tcl_DeleteNamespace, no active call frames in ns} {
129 namespace eval test_ns_2 {
131 return [namespace current]
134 list [test_ns_2::p] [namespace delete test_ns_2]
136 test namespace-7.3 {recursive Tcl_DeleteNamespace, active call frames in ns} {
138 namespace eval test_ns_2 {
140 trace add variable x unset "namespace delete [namespace current];#"
141 namespace delete [namespace current]
144 test namespace-7.4 {recursive Tcl_DeleteNamespace, active call frames in ns} {
146 namespace eval test_ns_2 {
148 trace add command x delete "namespace delete [namespace current];#"
149 namespace delete [namespace current]
152 test namespace-7.5 {recursive Tcl_DeleteNamespace, no active call frames in ns} {
154 namespace eval test_ns_2 {
156 trace add variable x unset "namespace delete [namespace current];#"
158 namespace delete test_ns_2
160 test namespace-7.6 {recursive Tcl_DeleteNamespace, no active call frames in ns} {
162 namespace eval test_ns_2 {
164 trace add command x delete "namespace delete [namespace current];#"
166 namespace delete test_ns_2
169 test namespace-8.1 {TclTeardownNamespace, delete global namespace} {
170 catch {interp delete test_interp}
171 interp create test_interp
172 interp eval test_interp {
173 namespace eval test_ns_1 {
176 return [namespace current]
179 namespace eval test_ns_2 {
180 namespace import ::test_ns_1::p
190 list [interp eval test_interp {test_ns_2::q}] \
191 [interp eval test_interp {namespace delete ::}] \
192 [catch {interp eval test_interp {set a 123}} msg] $msg \
193 [interp delete test_interp]
194 } {{::test_ns_1 27} {} 1 {invalid command name "set"} {}}
195 test namespace-8.2 {TclTeardownNamespace, remove deleted ns from parent} {
196 catch {eval namespace delete [namespace children :: test_ns_*]}
197 namespace eval test_ns_1::test_ns_2::test_ns_3a {proc p {} {}}
198 namespace eval test_ns_1::test_ns_2::test_ns_3b {proc q {} {}}
199 list [namespace children test_ns_1] \
200 [namespace delete test_ns_1::test_ns_2] \
201 [namespace children test_ns_1]
202 } {::test_ns_1::test_ns_2 {} {}}
203 test namespace-8.3 {TclTeardownNamespace, delete child namespaces} {
204 catch {eval namespace delete [namespace children :: test_ns_*]}
205 namespace eval test_ns_1::test_ns_2::test_ns_3a {proc p {} {}}
206 namespace eval test_ns_1::test_ns_2::test_ns_3b {proc q {} {}}
207 list [namespace children test_ns_1] \
208 [namespace delete test_ns_1::test_ns_2] \
209 [namespace children test_ns_1] \
210 [catch {namespace children test_ns_1::test_ns_2} msg] $msg \
211 [info commands test_ns_1::test_ns_2::test_ns_3a::*]
212 } {::test_ns_1::test_ns_2 {} {} 1 {unknown namespace "test_ns_1::test_ns_2" in namespace children command} {}}
213 test namespace-8.4 {TclTeardownNamespace, cmds imported from deleted ns go away} {
214 catch {eval namespace delete [namespace children :: test_ns_*]}
215 namespace eval test_ns_export {
216 namespace export cmd1 cmd2
217 proc cmd1 {args} {return "cmd1: $args"}
218 proc cmd2 {args} {return "cmd2: $args"}
220 namespace eval test_ns_import {
221 namespace import ::test_ns_export::*
222 proc p {} {return foo}
224 list [lsort [info commands test_ns_import::*]] \
225 [namespace delete test_ns_export] \
226 [info commands test_ns_import::*]
227 } [list [lsort {::test_ns_import::p ::test_ns_import::cmd1 ::test_ns_import::cmd2}] {} ::test_ns_import::p]
228 test namespace-8.5 {TclTeardownNamespace: preserve errorInfo; errorCode values} {
230 slave eval {trace add execution error leave {namespace delete :: ;#}}
231 catch {slave eval error foo bar baz}
236 "slave eval error foo bar baz"}
237 test namespace-8.6 {TclTeardownNamespace: preserve errorInfo; errorCode values} {
239 slave eval {trace add variable errorCode write {namespace delete :: ;#}}
240 catch {slave eval error foo bar baz}
245 "slave eval error foo bar baz"}
246 test namespace-8.7 {TclTeardownNamespace: preserve errorInfo; errorCode values} {
248 slave eval {trace add execution error leave {namespace delete :: ;#}}
249 catch {slave eval error foo bar baz}
254 test namespace-9.1 {Tcl_Import, empty import pattern} {
255 catch {eval namespace delete [namespace children :: test_ns_*]}
256 list [catch {namespace eval test_ns_import {namespace import {}}} msg] $msg
257 } {1 {empty import pattern}}
258 test namespace-9.2 {Tcl_Import, unknown namespace in import pattern} {
259 list [catch {namespace eval test_ns_import {namespace import fred::x}} msg] $msg
260 } {1 {unknown namespace in import pattern "fred::x"}}
261 test namespace-9.3 {Tcl_Import, import ns == export ns} {
262 list [catch {namespace eval test_ns_import {namespace import ::test_ns_import::puts}} msg] $msg
263 } {1 {import pattern "::test_ns_import::puts" tries to import from namespace "test_ns_import" into itself}}
264 test namespace-9.4 {Tcl_Import, simple import} {
265 catch {eval namespace delete [namespace children :: test_ns_*]}
266 namespace eval test_ns_export {
267 namespace export cmd1
268 proc cmd1 {args} {return "cmd1: $args"}
269 proc cmd2 {args} {return "cmd2: $args"}
271 namespace eval test_ns_import {
272 namespace import ::test_ns_export::*
273 proc p {} {return [cmd1 123]}
277 test namespace-9.5 {Tcl_Import, can't redefine cmd unless allowOverwrite!=0} {
278 list [catch {namespace eval test_ns_import {namespace import ::test_ns_export::*}} msg] $msg
280 test namespace-9.6 {Tcl_Import, cmd redefinition ok if allowOverwrite!=0} {
281 namespace eval test_ns_import {
282 namespace import -force ::test_ns_export::*
286 test namespace-9.7 {Tcl_Import, links are preserved if cmd is redefined} {
287 catch {eval namespace delete [namespace children :: test_ns_*]}
288 namespace eval test_ns_export {
289 namespace export cmd1
290 proc cmd1 {args} {return "cmd1: $args"}
292 namespace eval test_ns_import {
293 namespace import -force ::test_ns_export::*
295 list [test_ns_import::cmd1 a b c] \
296 [test_ns_export::cmd1 d e f] \
297 [proc test_ns_export::cmd1 {args} {return "new1: $args"}] \
298 [namespace origin test_ns_import::cmd1] \
299 [namespace origin test_ns_export::cmd1] \
300 [test_ns_import::cmd1 g h i] \
301 [test_ns_export::cmd1 j k l]
302 } {{cmd1: a b c} {cmd1: d e f} {} ::test_ns_export::cmd1 ::test_ns_export::cmd1 {new1: g h i} {new1: j k l}}
304 test namespace-9.8 {Tcl_Import: Bug 1017299} -setup {
314 [list namespace import [namespace current]::one::cmd]
315 namespace eval three \
316 [list namespace import [namespace current]::two::cmd]
317 namespace eval three {
319 namespace export other
322 namespace eval two [list namespace import -force \
323 [namespace current]::three::other]
324 namespace origin two::other
326 namespace delete one two three
327 } -match glob -result *::one::cmd
329 test namespace-9.9 {Tcl_Import: Bug 1017299} -setup {
334 namespace eval two namespace export cmd
336 [list namespace import [namespace current]::one::cmd]
337 namespace eval three namespace export cmd
338 namespace eval three \
339 [list namespace import [namespace current]::two::cmd]
341 namespace eval two [list namespace import -force \
342 [namespace current]::three::cmd]
343 namespace origin two::cmd
345 namespace delete one two three
346 } -returnCodes error -match glob -result {import pattern * would create a loop*}
348 test namespace-10.1 {Tcl_ForgetImport, check for valid namespaces} {
349 catch {eval namespace delete [namespace children :: test_ns_*]}
350 list [catch {namespace forget xyzzy::*} msg] $msg
351 } {1 {unknown namespace in namespace forget pattern "xyzzy::*"}}
352 test namespace-10.2 {Tcl_ForgetImport, ignores patterns that don't match} {
353 namespace eval test_ns_export {
354 namespace export cmd1
355 proc cmd1 {args} {return "cmd1: $args"}
356 proc cmd2 {args} {return "cmd2: $args"}
358 namespace eval test_ns_import {
359 namespace forget ::test_ns_export::wombat
362 test namespace-10.3 {Tcl_ForgetImport, deletes matching imported cmds} {
363 namespace eval test_ns_import {
364 namespace import ::test_ns_export::*
365 proc p {} {return [cmd1 123]}
367 lappend l [lsort [info commands ::test_ns_import::*]]
368 namespace forget ::test_ns_export::cmd1
369 lappend l [info commands ::test_ns_import::*]
370 lappend l [catch {cmd1 777} msg] $msg
372 } [list [lsort {::test_ns_import::p ::test_ns_import::cmd1}] ::test_ns_import::p 1 {invalid command name "cmd1"}]
374 test namespace-10.4 {Tcl_ForgetImport: Bug 560297} -setup {
375 namespace eval origin {
379 namespace eval unrelated {
383 [list namespace import [namespace current]::origin::cmd]
386 [list namespace forget [namespace current]::unrelated::cmd]
389 namespace delete origin unrelated my
392 test namespace-10.5 {Tcl_ForgetImport: Bug 560297} -setup {
393 namespace eval origin {
398 [list namespace import [namespace current]::origin::cmd]
399 namespace eval my rename cmd newname
402 [list namespace forget [namespace current]::origin::cmd]
405 namespace delete origin my
406 } -returnCodes error -match glob -result *
408 test namespace-10.6 {Tcl_ForgetImport: Bug 560297} -setup {
409 namespace eval origin {
414 [list namespace import [namespace current]::origin::cmd]
415 namespace eval your {}
417 [list rename cmd [namespace current]::your::newname]
419 namespace eval your namespace forget newname
422 namespace delete origin my your
423 } -returnCodes error -match glob -result *
425 test namespace-10.7 {Tcl_ForgetImport: Bug 560297} -setup {
426 namespace eval origin {
430 namespace eval link namespace export cmd
431 namespace eval link \
432 [list namespace import [namespace current]::origin::cmd]
433 namespace eval link2 namespace export cmd
434 namespace eval link2 \
435 [list namespace import [namespace current]::link::cmd]
437 [list namespace import [namespace current]::link2::cmd]
440 [list namespace forget [namespace current]::origin::cmd]
443 namespace delete origin link link2 my
444 } -returnCodes error -match glob -result *
446 test namespace-10.8 {Tcl_ForgetImport: Bug 560297} -setup {
447 namespace eval origin {
451 namespace eval link namespace export cmd
452 namespace eval link \
453 [list namespace import [namespace current]::origin::cmd]
454 namespace eval link2 namespace export cmd
455 namespace eval link2 \
456 [list namespace import [namespace current]::link::cmd]
458 [list namespace import [namespace current]::link2::cmd]
461 [list namespace forget [namespace current]::link::cmd]
464 namespace delete origin link link2 my
467 test namespace-10.9 {Tcl_ForgetImport: Bug 560297} -setup {
468 namespace eval origin {
472 namespace eval link namespace export cmd
473 namespace eval link \
474 [list namespace import [namespace current]::origin::cmd]
475 namespace eval link2 namespace export cmd
476 namespace eval link2 \
477 [list namespace import [namespace current]::link::cmd]
479 [list namespace import [namespace current]::link2::cmd]
482 [list namespace forget [namespace current]::link2::cmd]
485 namespace delete origin link link2 my
486 } -returnCodes error -match glob -result *
488 test namespace-11.1 {TclGetOriginalCommand, check if not imported cmd} {
489 catch {eval namespace delete [namespace children :: test_ns_*]}
490 namespace eval test_ns_export {
491 namespace export cmd1
492 proc cmd1 {args} {return "cmd1: $args"}
494 list [namespace origin set] [namespace origin test_ns_export::cmd1]
495 } {::set ::test_ns_export::cmd1}
496 test namespace-11.2 {TclGetOriginalCommand, directly imported cmd} {
497 namespace eval test_ns_import1 {
498 namespace import ::test_ns_export::*
500 proc p {} {namespace origin cmd1}
502 list [test_ns_import1::p] [namespace origin test_ns_import1::cmd1]
503 } {::test_ns_export::cmd1 ::test_ns_export::cmd1}
504 test namespace-11.3 {TclGetOriginalCommand, indirectly imported cmd} {
505 namespace eval test_ns_import2 {
506 namespace import ::test_ns_import1::*
507 proc q {} {return [cmd1 123]}
509 list [test_ns_import2::q] [namespace origin test_ns_import2::cmd1]
510 } {{cmd1: 123} ::test_ns_export::cmd1}
512 test namespace-12.1 {InvokeImportedCmd} {
513 catch {eval namespace delete [namespace children :: test_ns_*]}
514 namespace eval test_ns_export {
515 namespace export cmd1
516 proc cmd1 {args} {namespace current}
518 namespace eval test_ns_import {
519 namespace import ::test_ns_export::*
521 list [test_ns_import::cmd1]
524 test namespace-13.1 {DeleteImportedCmd, deletes imported cmds} {
525 namespace eval test_ns_import {
527 lappend l [info commands ::test_ns_import::*]
528 namespace forget ::test_ns_export::cmd1
529 lappend l [info commands ::test_ns_import::*]
531 } {::test_ns_import::cmd1 {}}
533 test namespace-14.1 {TclGetNamespaceForQualName, absolute names} {
534 catch {eval namespace delete [namespace children :: test_ns_*]}
536 namespace eval test_ns_1::test_ns_2 {
539 namespace eval test_ns_2 {
542 namespace eval test_ns_1 {
543 list $::v $::test_ns_2::v $::test_ns_1::test_ns_2::v \
544 [lsort [namespace children :: test_ns_*]]
546 } [list 10 30 20 [lsort {::test_ns_1 ::test_ns_2}]]
547 test namespace-14.2 {TclGetNamespaceForQualName, invalid absolute names} {
548 namespace eval test_ns_1 {
549 list [catch {set ::test_ns_777::v} msg] $msg \
550 [catch {namespace children test_ns_777} msg] $msg
552 } {1 {can't read "::test_ns_777::v": no such variable} 1 {unknown namespace "test_ns_777" in namespace children command}}
553 test namespace-14.3 {TclGetNamespaceForQualName, relative names} {
554 namespace eval test_ns_1 {
555 list $v $test_ns_2::v
558 test namespace-14.4 {TclGetNamespaceForQualName, relative ns names looked up only in current ns} {
559 namespace eval test_ns_1::test_ns_2 {
560 namespace eval foo {}
562 namespace eval test_ns_1 {
563 list [namespace children test_ns_2] \
564 [catch {namespace children test_ns_1} msg] $msg
566 } {::test_ns_1::test_ns_2::foo 1 {unknown namespace "test_ns_1" in namespace children command}}
567 test namespace-14.5 {TclGetNamespaceForQualName, relative ns names looked up only in current ns} {
568 namespace eval ::test_ns_2 {
569 namespace eval bar {}
571 namespace eval test_ns_1 {
572 set l [list [catch {namespace delete test_ns_2::bar} msg] $msg]
575 } {1 {unknown namespace "test_ns_2::bar" in namespace delete command}}
576 test namespace-14.6 {TclGetNamespaceForQualName, relative ns names looked up only in current ns} {
577 namespace eval test_ns_1::test_ns_2 {
578 namespace eval foo {}
580 namespace eval test_ns_1 {
581 list [namespace children test_ns_2] \
582 [catch {namespace children test_ns_1} msg] $msg
584 } {::test_ns_1::test_ns_2::foo 1 {unknown namespace "test_ns_1" in namespace children command}}
585 test namespace-14.7 {TclGetNamespaceForQualName, ignore extra :s if ns} {
586 namespace children test_ns_1:::
587 } {::test_ns_1::test_ns_2}
588 test namespace-14.8 {TclGetNamespaceForQualName, ignore extra :s if ns} {
589 namespace children :::test_ns_1:::::test_ns_2:::
590 } {::test_ns_1::test_ns_2::foo}
591 test namespace-14.9 {TclGetNamespaceForQualName, extra ::s are significant for vars} {
593 lappend l [catch {set test_ns_1::test_ns_2::} msg] $msg
594 namespace eval test_ns_1::test_ns_2 {variable {} 2525}
595 lappend l [set test_ns_1::test_ns_2::]
596 } {1 {can't read "test_ns_1::test_ns_2::": no such variable} 2525}
597 test namespace-14.10 {TclGetNamespaceForQualName, extra ::s are significant for vars} {
598 catch {unset test_ns_1::test_ns_2::}
600 lappend l [catch {set test_ns_1::test_ns_2::} msg] $msg
601 set test_ns_1::test_ns_2:: 314159
602 lappend l [set test_ns_1::test_ns_2::]
603 } {1 {can't read "test_ns_1::test_ns_2::": no such variable} 314159}
604 test namespace-14.11 {TclGetNamespaceForQualName, extra ::s are significant for commands} {
605 catch {rename test_ns_1::test_ns_2:: {}}
607 lappend l [catch {test_ns_1::test_ns_2:: hello} msg] $msg
608 proc test_ns_1::test_ns_2:: {args} {return "\{\}: $args"}
609 lappend l [test_ns_1::test_ns_2:: hello]
610 } {1 {invalid command name "test_ns_1::test_ns_2::"} {{}: hello}}
611 test namespace-14.12 {TclGetNamespaceForQualName, extra ::s are significant for vars} {
612 catch {eval namespace delete [namespace children :: test_ns_*]}
613 namespace eval test_ns_1 {
619 test namespace-14.13 {TclGetNamespaceForQualName, namespace other than global ns can't have empty name} {
620 catch {eval namespace delete [namespace children :: test_ns_*]}
621 list [catch {namespace eval test_ns_1 {proc {} {} {}; namespace eval {} {}; {}}} msg] $msg
622 } {1 {can't create namespace "": only global namespace can have empty name}}
624 test namespace-15.1 {Tcl_FindNamespace, absolute name found} {
625 catch {eval namespace delete [namespace children :: test_ns_*]}
626 namespace eval test_ns_delete {
627 namespace eval test_ns_delete2 {}
628 proc cmd {args} {namespace current}
630 list [namespace delete ::test_ns_delete::test_ns_delete2] \
631 [namespace children ::test_ns_delete]
633 test namespace-15.2 {Tcl_FindNamespace, absolute name not found} {
634 list [catch {namespace delete ::test_ns_delete::test_ns_delete2} msg] $msg
635 } {1 {unknown namespace "::test_ns_delete::test_ns_delete2" in namespace delete command}}
636 test namespace-15.3 {Tcl_FindNamespace, relative name found} {
637 namespace eval test_ns_delete {
638 namespace eval test_ns_delete2 {}
639 namespace eval test_ns_delete3 {}
640 list [namespace delete test_ns_delete2] \
641 [namespace children [namespace current]]
643 } {{} ::test_ns_delete::test_ns_delete3}
644 test namespace-15.4 {Tcl_FindNamespace, relative name not found} {
645 namespace eval test_ns_delete2 {}
646 namespace eval test_ns_delete {
647 list [catch {namespace delete test_ns_delete2} msg] $msg
649 } {1 {unknown namespace "test_ns_delete2" in namespace delete command}}
651 test namespace-16.1 {Tcl_FindCommand, absolute name found} {
652 catch {eval namespace delete [namespace children :: test_ns_*]}
653 namespace eval test_ns_1 {
654 proc cmd {args} {return "[namespace current]::cmd: $args"}
655 variable v "::test_ns_1::cmd"
658 } {::test_ns_1::cmd: one}
659 test namespace-16.2 {Tcl_FindCommand, absolute name found} {
660 eval $test_ns_1::v two
661 } {::test_ns_1::cmd: two}
662 test namespace-16.3 {Tcl_FindCommand, absolute name not found} {
663 namespace eval test_ns_1 {
664 variable v2 "::test_ns_1::ladidah"
665 list [catch {eval $v2} msg] $msg
667 } {1 {invalid command name "::test_ns_1::ladidah"}}
669 # save the "unknown" proc, which is redefined by the following two tests
670 catch {rename unknown unknown.old}
671 proc unknown {args} {
672 return "unknown: $args"
674 test namespace-16.4 {Tcl_FindCommand, absolute name and TCL_GLOBAL_ONLY} {
675 ::test_ns_1::foobar x y z
676 } {unknown: ::test_ns_1::foobar x y z}
677 test namespace-16.5 {Tcl_FindCommand, absolute name and TCL_GLOBAL_ONLY} {
679 } {unknown: ::foobar 1 2 3 4 5}
680 test namespace-16.6 {Tcl_FindCommand, relative name and TCL_GLOBAL_ONLY} {
681 test_ns_1::foobar x y z
682 } {unknown: test_ns_1::foobar x y z}
683 test namespace-16.7 {Tcl_FindCommand, relative name and TCL_GLOBAL_ONLY} {
685 } {unknown: foobar 1 2 3 4 5}
686 # restore the "unknown" proc saved previously
687 catch {rename unknown {}}
688 catch {rename unknown.old unknown}
690 test namespace-16.8 {Tcl_FindCommand, relative name found} {
691 namespace eval test_ns_1 {
694 } {::test_ns_1::cmd: a b c}
695 test namespace-16.9 {Tcl_FindCommand, relative name found} {
696 catch {rename cmd2 {}}
697 proc cmd2 {args} {return "[namespace current]::cmd2: $args"}
698 namespace eval test_ns_1 {
702 test namespace-16.10 {Tcl_FindCommand, relative name found, only look in current then global ns} {
703 namespace eval test_ns_1 {
705 return "[namespace current]::cmd2 in test_ns_1: $args"
707 namespace eval test_ns_12 {
712 test namespace-16.11 {Tcl_FindCommand, relative name not found} {
713 namespace eval test_ns_1 {
714 list [catch {cmd3 a b c} msg] $msg
716 } {1 {invalid command name "cmd3"}}
719 test namespace-17.1 {Tcl_FindNamespaceVar, absolute name found} {
720 catch {eval namespace delete [namespace children :: test_ns_*]}
722 namespace eval test_ns_1 {
726 test namespace-17.2 {Tcl_FindNamespaceVar, absolute name found} {
727 namespace eval test_ns_1 {
732 test namespace-17.3 {Tcl_FindNamespaceVar, absolute name found} {
733 namespace eval test_ns_1 {
734 namespace eval test_ns_2 {
737 set ::test_ns_1::test_ns_2::x
740 test namespace-17.4 {Tcl_FindNamespaceVar, absolute name not found} {
741 namespace eval test_ns_1 {
742 namespace eval test_ns_2 {
745 list [catch {set ::test_ns_1::test_ns_2::y} msg] $msg
747 } {1 {can't read "::test_ns_1::test_ns_2::y": no such variable}}
748 test namespace-17.5 {Tcl_FindNamespaceVar, absolute name and TCL_GLOBAL_ONLY} {
749 namespace eval test_ns_1 {
750 namespace eval test_ns_3 {
751 variable ::test_ns_1::test_ns_2::x 2222
754 set ::test_ns_1::test_ns_2::x
756 test namespace-17.6 {Tcl_FindNamespaceVar, relative name found} {
757 namespace eval test_ns_1 {
761 test namespace-17.7 {Tcl_FindNamespaceVar, relative name found} {
762 namespace eval test_ns_1 {
764 set x ;# must be global x now
767 test namespace-17.8 {Tcl_FindNamespaceVar, relative name not found} {
768 namespace eval test_ns_1 {
769 list [catch {set wuzzat} msg] $msg
771 } {1 {can't read "wuzzat": no such variable}}
772 test namespace-17.9 {Tcl_FindNamespaceVar, relative name and TCL_GLOBAL_ONLY} {
773 namespace eval test_ns_1 {
781 catch {rename foo {}}
782 test namespace-18.1 {TclResetShadowedCmdRefs, one-level check for command shadowing} {
783 catch {eval namespace delete [namespace children :: test_ns_*]}
784 proc foo {} {return "global foo"}
785 namespace eval test_ns_1 {
791 lappend l [test_ns_1::trigger]
792 namespace eval test_ns_1 {
793 # force invalidation of cached ref to "foo" in proc trigger
794 proc foo {} {return "foo in test_ns_1"}
796 lappend l [test_ns_1::trigger]
798 } {{global foo} {foo in test_ns_1}}
799 test namespace-18.2 {TclResetShadowedCmdRefs, multilevel check for command shadowing} {
800 namespace eval test_ns_2 {
801 proc foo {} {return "foo in ::test_ns_2"}
803 namespace eval test_ns_1 {
804 namespace eval test_ns_2 {}
806 return [test_ns_2::foo]
810 lappend l [test_ns_1::trigger]
811 namespace eval test_ns_1 {
812 namespace eval test_ns_2 {
813 # force invalidation of cached ref to "foo" in proc trigger
814 proc foo {} {return "foo in ::test_ns_1::test_ns_2"}
817 lappend l [test_ns_1::trigger]
819 } {{foo in ::test_ns_2} {foo in ::test_ns_1::test_ns_2}}
821 catch {rename foo {}}
823 test namespace-19.1 {GetNamespaceFromObj, global name found} {
824 catch {eval namespace delete [namespace children :: test_ns_*]}
825 namespace eval test_ns_1::test_ns_2 {}
826 namespace children ::test_ns_1
827 } {::test_ns_1::test_ns_2}
828 test namespace-19.2 {GetNamespaceFromObj, relative name found} {
829 namespace eval test_ns_1 {
830 namespace children test_ns_2
833 test namespace-19.3 {GetNamespaceFromObj, name not found} {
834 namespace eval test_ns_1 {
835 list [catch {namespace children test_ns_99} msg] $msg
837 } {1 {unknown namespace "test_ns_99" in namespace children command}}
838 test namespace-19.4 {GetNamespaceFromObj, invalidation of cached ns refs} {
839 namespace eval test_ns_1 {
841 return [namespace children test_ns_2]
843 list [catch {namespace children test_ns_99} msg] $msg
846 lappend l [test_ns_1::foo]
847 namespace delete test_ns_1::test_ns_2
848 namespace eval test_ns_1::test_ns_2::test_ns_3 {}
849 lappend l [test_ns_1::foo]
851 } {{} ::test_ns_1::test_ns_2::test_ns_3}
853 test namespace-20.1 {Tcl_NamespaceObjCmd, bad subcommand} {
854 catch {eval namespace delete [namespace children :: test_ns_*]}
855 list [catch {namespace} msg] $msg
856 } {1 {wrong # args: should be "namespace subcommand ?arg ...?"}}
857 test namespace-20.2 {Tcl_NamespaceObjCmd, bad subcommand} {
858 list [catch {namespace wombat {}} msg] $msg
859 } {1 {bad option "wombat": must be children, code, current, delete, eval, exists, export, forget, import, inscope, origin, parent, qualifiers, tail, or which}}
860 test namespace-20.3 {Tcl_NamespaceObjCmd, abbreviations are okay} {
861 namespace ch :: test_ns_*
864 test namespace-21.1 {NamespaceChildrenCmd, no args} {
865 catch {eval namespace delete [namespace children :: test_ns_*]}
866 namespace eval test_ns_1::test_ns_2 {}
867 expr {[string first ::test_ns_1 [namespace children]] != -1}
869 test namespace-21.2 {NamespaceChildrenCmd, no args} {
870 namespace eval test_ns_1 {
873 } {::test_ns_1::test_ns_2}
874 test namespace-21.3 {NamespaceChildrenCmd, ns name given} {
875 namespace children ::test_ns_1
876 } {::test_ns_1::test_ns_2}
877 test namespace-21.4 {NamespaceChildrenCmd, ns name given} {
878 namespace eval test_ns_1 {
879 namespace children test_ns_2
882 test namespace-21.5 {NamespaceChildrenCmd, too many args} {
883 namespace eval test_ns_1 {
884 list [catch {namespace children test_ns_2 xxx yyy} msg] $msg
886 } {1 {wrong # args: should be "namespace children ?name? ?pattern?"}}
887 test namespace-21.6 {NamespaceChildrenCmd, glob-style pattern given} {
888 namespace eval test_ns_1::test_ns_foo {}
889 namespace children test_ns_1 *f*
890 } {::test_ns_1::test_ns_foo}
891 test namespace-21.7 {NamespaceChildrenCmd, glob-style pattern given} {
892 namespace eval test_ns_1::test_ns_foo {}
893 lsort [namespace children test_ns_1 test*]
894 } [lsort {::test_ns_1::test_ns_2 ::test_ns_1::test_ns_foo}]
896 test namespace-22.1 {NamespaceCodeCmd, bad args} {
897 catch {eval namespace delete [namespace children :: test_ns_*]}
898 list [catch {namespace code} msg] $msg \
899 [catch {namespace code xxx yyy} msg] $msg
900 } {1 {wrong # args: should be "namespace code arg"} 1 {wrong # args: should be "namespace code arg"}}
901 test namespace-22.2 {NamespaceCodeCmd, arg is already scoped value} {
902 namespace eval test_ns_1 {
903 proc cmd {} {return "test_ns_1::cmd"}
905 namespace code {namespace inscope ::test_ns_1 cmd}
906 } {namespace inscope ::test_ns_1 cmd}
907 test namespace-22.3 {NamespaceCodeCmd, arg is already scoped value} {
908 namespace code {namespace inscope ::test_ns_1 cmd}
909 } {namespace inscope ::test_ns_1 cmd}
910 test namespace-22.4 {NamespaceCodeCmd, in :: namespace} {
911 namespace code unknown
912 } {::namespace inscope :: unknown}
913 test namespace-22.5 {NamespaceCodeCmd, in other namespace} {
914 namespace eval test_ns_1 {
917 } {::namespace inscope ::test_ns_1 cmd}
918 test namespace-22.6 {NamespaceCodeCmd, in other namespace} {
919 namespace eval test_ns_1 {
922 namespace eval test_ns_2 {
923 proc namespace args {}
925 namespace eval test_ns_2 [namespace eval test_ns_1 {
926 namespace code {set v}
930 test namespace-23.1 {NamespaceCurrentCmd, bad args} {
931 catch {eval namespace delete [namespace children :: test_ns_*]}
932 list [catch {namespace current xxx} msg] $msg \
933 [catch {namespace current xxx yyy} msg] $msg
934 } {1 {wrong # args: should be "namespace current"} 1 {wrong # args: should be "namespace current"}}
935 test namespace-23.2 {NamespaceCurrentCmd, at global level} {
938 test namespace-23.3 {NamespaceCurrentCmd, in nested ns} {
939 namespace eval test_ns_1::test_ns_2 {
942 } {::test_ns_1::test_ns_2}
944 test namespace-24.1 {NamespaceDeleteCmd, no args} {
945 catch {eval namespace delete [namespace children :: test_ns_*]}
948 test namespace-24.2 {NamespaceDeleteCmd, one arg} {
949 namespace eval test_ns_1::test_ns_2 {}
950 namespace delete ::test_ns_1
952 test namespace-24.3 {NamespaceDeleteCmd, two args} {
953 namespace eval test_ns_1::test_ns_2 {}
954 list [namespace delete ::test_ns_1::test_ns_2] [namespace delete ::test_ns_1]
956 test namespace-24.4 {NamespaceDeleteCmd, unknown ns} {
957 list [catch {namespace delete ::test_ns_foo} msg] $msg
958 } {1 {unknown namespace "::test_ns_foo" in namespace delete command}}
960 test namespace-25.1 {NamespaceEvalCmd, bad args} {
961 catch {eval namespace delete [namespace children :: test_ns_*]}
962 list [catch {namespace eval} msg] $msg
963 } {1 {wrong # args: should be "namespace eval name arg ?arg...?"}}
964 test namespace-25.2 {NamespaceEvalCmd, bad args} {
965 list [catch {namespace test_ns_1} msg] $msg
966 } {1 {bad option "test_ns_1": must be children, code, current, delete, eval, exists, export, forget, import, inscope, origin, parent, qualifiers, tail, or which}}
968 test namespace-25.3 {NamespaceEvalCmd, new namespace} {
970 namespace eval test_ns_1 {
979 test namespace-25.4 {NamespaceEvalCmd, existing namespace} {
980 namespace eval test_ns_1 {
981 proc q {} {return [expr {[p]+1}]}
985 test namespace-25.5 {NamespaceEvalCmd, multiple args} {
986 namespace eval test_ns_1 "set" "v"
988 test namespace-25.6 {NamespaceEvalCmd, error in eval'd script} {
989 list [catch {namespace eval test_ns_1 {xxxx}} msg] $msg $errorInfo
990 } {1 {invalid command name "xxxx"} {invalid command name "xxxx"
993 (in namespace eval "::test_ns_1" script line 1)
995 "namespace eval test_ns_1 {xxxx}"}}
996 test namespace-25.7 {NamespaceEvalCmd, error in eval'd script} {
997 list [catch {namespace eval test_ns_1 {error foo bar baz}} msg] $msg $errorInfo
999 (in namespace eval "::test_ns_1" script line 1)
1001 "namespace eval test_ns_1 {error foo bar baz}"}}
1002 test namespace-25.8 {NamespaceEvalCmd, error in eval'd script} knownBug {
1003 list [catch {namespace eval test_ns_1 error foo bar baz} msg] $msg $errorInfo
1005 (in namespace eval "::test_ns_1" script line 1)
1007 "namespace eval test_ns_1 error foo bar baz"}}
1009 test namespace-25.9 {NamespaceEvalCmd, 545325} {
1010 namespace eval test_ns_1 info level 0
1011 } {namespace eval test_ns_1 info level 0}
1013 test namespace-26.1 {NamespaceExportCmd, no args and new ns} {
1014 catch {eval namespace delete [namespace children :: test_ns_*]}
1017 test namespace-26.2 {NamespaceExportCmd, just -clear arg} {
1018 namespace export -clear
1020 test namespace-26.3 {NamespaceExportCmd, pattern can't specify a namespace} {
1021 namespace eval test_ns_1 {
1022 list [catch {namespace export ::zzz} msg] $msg
1024 } {1 {invalid export pattern "::zzz": pattern can't specify a namespace}}
1025 test namespace-26.4 {NamespaceExportCmd, one pattern} {
1026 namespace eval test_ns_1 {
1027 namespace export cmd1
1028 proc cmd1 {args} {return "cmd1: $args"}
1029 proc cmd2 {args} {return "cmd2: $args"}
1030 proc cmd3 {args} {return "cmd3: $args"}
1031 proc cmd4 {args} {return "cmd4: $args"}
1033 namespace eval test_ns_2 {
1034 namespace import ::test_ns_1::*
1036 list [info commands test_ns_2::*] [test_ns_2::cmd1 hello]
1037 } {::test_ns_2::cmd1 {cmd1: hello}}
1038 test namespace-26.5 {NamespaceExportCmd, sequence of patterns, patterns accumulate} {
1039 namespace eval test_ns_1 {
1040 namespace export cmd1 cmd3
1042 namespace eval test_ns_2 {
1043 namespace import -force ::test_ns_1::*
1045 list [lsort [info commands test_ns_2::*]] [test_ns_2::cmd3 hello]
1046 } [list [lsort {::test_ns_2::cmd1 ::test_ns_2::cmd3}] {cmd3: hello}]
1047 test namespace-26.6 {NamespaceExportCmd, no patterns means return uniq'ed export list} {
1048 namespace eval test_ns_1 {
1052 test namespace-26.7 {NamespaceExportCmd, -clear resets export list} {
1053 namespace eval test_ns_1 {
1054 namespace export -clear cmd4
1056 namespace eval test_ns_2 {
1057 namespace import ::test_ns_1::*
1059 list [lsort [info commands test_ns_2::*]] [test_ns_2::cmd4 hello]
1060 } [list [lsort {::test_ns_2::cmd4 ::test_ns_2::cmd1 ::test_ns_2::cmd3}] {cmd4: hello}]
1062 test namespace-27.1 {NamespaceForgetCmd, no args} {
1063 catch {eval namespace delete [namespace children :: test_ns_*]}
1066 test namespace-27.2 {NamespaceForgetCmd, args must be valid namespaces} {
1067 list [catch {namespace forget ::test_ns_1::xxx} msg] $msg
1068 } {1 {unknown namespace in namespace forget pattern "::test_ns_1::xxx"}}
1069 test namespace-27.3 {NamespaceForgetCmd, arg is forgotten} {
1070 namespace eval test_ns_1 {
1071 namespace export cmd*
1072 proc cmd1 {args} {return "cmd1: $args"}
1073 proc cmd2 {args} {return "cmd2: $args"}
1075 namespace eval test_ns_2 {
1076 namespace import ::test_ns_1::*
1077 namespace forget ::test_ns_1::cmd1
1079 info commands ::test_ns_2::*
1080 } {::test_ns_2::cmd2}
1082 test namespace-28.1 {NamespaceImportCmd, no args} {
1083 catch {eval namespace delete [namespace children :: test_ns_*]}
1086 test namespace-28.2 {NamespaceImportCmd, no args and just "-force"} {
1087 namespace import -force
1089 test namespace-28.3 {NamespaceImportCmd, arg is imported} {
1090 namespace eval test_ns_1 {
1091 namespace export cmd2
1092 proc cmd1 {args} {return "cmd1: $args"}
1093 proc cmd2 {args} {return "cmd2: $args"}
1095 namespace eval test_ns_2 {
1096 namespace import ::test_ns_1::*
1097 namespace forget ::test_ns_1::cmd1
1099 info commands test_ns_2::*
1100 } {::test_ns_2::cmd2}
1102 test namespace-29.1 {NamespaceInscopeCmd, bad args} {
1103 catch {eval namespace delete [namespace children :: test_ns_*]}
1104 list [catch {namespace inscope} msg] $msg
1105 } {1 {wrong # args: should be "namespace inscope name arg ?arg...?"}}
1106 test namespace-29.2 {NamespaceInscopeCmd, bad args} {
1107 list [catch {namespace inscope ::} msg] $msg
1108 } {1 {wrong # args: should be "namespace inscope name arg ?arg...?"}}
1109 test namespace-29.3 {NamespaceInscopeCmd, specified ns must exist} {
1110 list [catch {namespace inscope test_ns_1 {set v}} msg] $msg
1111 } {1 {unknown namespace "test_ns_1" in inscope namespace command}}
1112 test namespace-29.4 {NamespaceInscopeCmd, simple case} {
1113 namespace eval test_ns_1 {
1117 return "[namespace current]::cmd: v=$v, args=$args"
1120 namespace inscope test_ns_1 cmd
1121 } {::test_ns_1::cmd: v=747, args=}
1122 test namespace-29.5 {NamespaceInscopeCmd, has lappend semantics} {
1123 list [namespace inscope test_ns_1 cmd x y z] \
1124 [namespace eval test_ns_1 [concat cmd [list x y z]]]
1125 } {{::test_ns_1::cmd: v=747, args=x y z} {::test_ns_1::cmd: v=747, args=x y z}}
1126 test namespace-29.6 {NamespaceInscopeCmd, 1400572} knownBug {
1127 namespace inscope test_ns_1 {info level 0}
1128 } {namespace inscope test_ns_1 {info level 0}}
1131 test namespace-30.1 {NamespaceOriginCmd, bad args} {
1132 catch {eval namespace delete [namespace children :: test_ns_*]}
1133 list [catch {namespace origin} msg] $msg
1134 } {1 {wrong # args: should be "namespace origin name"}}
1135 test namespace-30.2 {NamespaceOriginCmd, bad args} {
1136 list [catch {namespace origin x y} msg] $msg
1137 } {1 {wrong # args: should be "namespace origin name"}}
1138 test namespace-30.3 {NamespaceOriginCmd, command not found} {
1139 list [catch {namespace origin fred} msg] $msg
1140 } {1 {invalid command name "fred"}}
1141 test namespace-30.4 {NamespaceOriginCmd, command isn't imported} {
1142 namespace origin set
1144 test namespace-30.5 {NamespaceOriginCmd, imported command} {
1145 namespace eval test_ns_1 {
1146 namespace export cmd*
1147 proc cmd1 {args} {return "cmd1: $args"}
1148 proc cmd2 {args} {return "cmd2: $args"}
1150 namespace eval test_ns_2 {
1152 namespace import ::test_ns_1::*
1155 namespace eval test_ns_3 {
1156 namespace import ::test_ns_2::*
1157 list [namespace origin foreach] \
1158 [namespace origin p] \
1159 [namespace origin cmd1] \
1160 [namespace origin ::test_ns_2::cmd2]
1162 } {::foreach ::test_ns_2::p ::test_ns_1::cmd1 ::test_ns_1::cmd2}
1164 test namespace-31.1 {NamespaceParentCmd, bad args} {
1165 catch {eval namespace delete [namespace children :: test_ns_*]}
1166 list [catch {namespace parent a b} msg] $msg
1167 } {1 {wrong # args: should be "namespace parent ?name?"}}
1168 test namespace-31.2 {NamespaceParentCmd, no args} {
1171 test namespace-31.3 {NamespaceParentCmd, namespace specified} {
1172 namespace eval test_ns_1 {
1173 namespace eval test_ns_2 {
1174 namespace eval test_ns_3 {}
1177 list [namespace parent ::] \
1178 [namespace parent test_ns_1::test_ns_2] \
1179 [namespace eval test_ns_1::test_ns_2::test_ns_3 {namespace parent ::test_ns_1::test_ns_2}]
1180 } {{} ::test_ns_1 ::test_ns_1}
1181 test namespace-31.4 {NamespaceParentCmd, bad namespace specified} {
1182 list [catch {namespace parent test_ns_1::test_ns_foo} msg] $msg
1183 } {1 {unknown namespace "test_ns_1::test_ns_foo" in namespace parent command}}
1185 test namespace-32.1 {NamespaceQualifiersCmd, bad args} {
1186 catch {eval namespace delete [namespace children :: test_ns_*]}
1187 list [catch {namespace qualifiers} msg] $msg
1188 } {1 {wrong # args: should be "namespace qualifiers string"}}
1189 test namespace-32.2 {NamespaceQualifiersCmd, bad args} {
1190 list [catch {namespace qualifiers x y} msg] $msg
1191 } {1 {wrong # args: should be "namespace qualifiers string"}}
1192 test namespace-32.3 {NamespaceQualifiersCmd, simple name} {
1193 namespace qualifiers foo
1195 test namespace-32.4 {NamespaceQualifiersCmd, leading ::} {
1196 namespace qualifiers ::x::y::z
1198 test namespace-32.5 {NamespaceQualifiersCmd, no leading ::} {
1199 namespace qualifiers a::b
1201 test namespace-32.6 {NamespaceQualifiersCmd, :: argument} {
1202 namespace qualifiers ::
1204 test namespace-32.7 {NamespaceQualifiersCmd, odd number of :s} {
1205 namespace qualifiers :::::
1207 test namespace-32.8 {NamespaceQualifiersCmd, odd number of :s} {
1208 namespace qualifiers foo:::
1211 test namespace-33.1 {NamespaceTailCmd, bad args} {
1212 catch {eval namespace delete [namespace children :: test_ns_*]}
1213 list [catch {namespace tail} msg] $msg
1214 } {1 {wrong # args: should be "namespace tail string"}}
1215 test namespace-33.2 {NamespaceTailCmd, bad args} {
1216 list [catch {namespace tail x y} msg] $msg
1217 } {1 {wrong # args: should be "namespace tail string"}}
1218 test namespace-33.3 {NamespaceTailCmd, simple name} {
1221 test namespace-33.4 {NamespaceTailCmd, leading ::} {
1222 namespace tail ::x::y::z
1224 test namespace-33.5 {NamespaceTailCmd, no leading ::} {
1227 test namespace-33.6 {NamespaceTailCmd, :: argument} {
1230 test namespace-33.7 {NamespaceTailCmd, odd number of :s} {
1231 namespace tail :::::
1233 test namespace-33.8 {NamespaceTailCmd, odd number of :s} {
1234 namespace tail foo:::
1237 test namespace-34.1 {NamespaceWhichCmd, bad args} {
1238 catch {eval namespace delete [namespace children :: test_ns_*]}
1239 list [catch {namespace which} msg] $msg
1240 } {1 {wrong # args: should be "namespace which ?-command? ?-variable? name"}}
1241 test namespace-34.2 {NamespaceWhichCmd, bad args} {
1242 list [catch {namespace which -fred} msg] $msg
1243 } {1 {wrong # args: should be "namespace which ?-command? ?-variable? name"}}
1244 test namespace-34.3 {NamespaceWhichCmd, bad args} {
1245 list [catch {namespace which -command} msg] $msg
1246 } {1 {wrong # args: should be "namespace which ?-command? ?-variable? name"}}
1247 test namespace-34.4 {NamespaceWhichCmd, bad args} {
1248 list [catch {namespace which a b} msg] $msg
1249 } {1 {wrong # args: should be "namespace which ?-command? ?-variable? name"}}
1250 test namespace-34.5 {NamespaceWhichCmd, command lookup} {
1251 namespace eval test_ns_1 {
1252 namespace export cmd*
1254 proc cmd1 {args} {return "cmd1: $args"}
1255 proc cmd2 {args} {return "cmd2: $args"}
1257 namespace eval test_ns_2 {
1259 namespace import ::test_ns_1::*
1263 namespace eval test_ns_3 {
1264 namespace import ::test_ns_2::*
1266 list [namespace which -command foreach] \
1267 [namespace which -command p] \
1268 [namespace which -command cmd1] \
1269 [namespace which -command ::test_ns_2::cmd2] \
1270 [catch {namespace which -command ::test_ns_2::noSuchCmd} msg] $msg
1272 } {::foreach ::test_ns_3::p ::test_ns_3::cmd1 ::test_ns_2::cmd2 0 {}}
1273 test namespace-34.6 {NamespaceWhichCmd, -command is default} {
1274 namespace eval test_ns_3 {
1275 list [namespace which foreach] \
1276 [namespace which p] \
1277 [namespace which cmd1] \
1278 [namespace which ::test_ns_2::cmd2]
1280 } {::foreach ::test_ns_3::p ::test_ns_3::cmd1 ::test_ns_2::cmd2}
1281 test namespace-34.7 {NamespaceWhichCmd, variable lookup} {
1282 namespace eval test_ns_3 {
1283 list [namespace which -variable env] \
1284 [namespace which -variable v3] \
1285 [namespace which -variable ::test_ns_2::v2] \
1286 [catch {namespace which -variable ::test_ns_2::noSuchVar} msg] $msg
1288 } {::env ::test_ns_3::v3 ::test_ns_2::v2 0 {}}
1290 test namespace-35.1 {FreeNsNameInternalRep, resulting ref count > 0} {
1291 catch {eval namespace delete [namespace children :: test_ns_*]}
1292 namespace eval test_ns_1 {
1294 namespace delete [namespace current]
1295 return [namespace current]
1300 test namespace-35.2 {FreeNsNameInternalRep, resulting ref count == 0} {
1301 namespace eval test_ns_1 {
1303 return [namespace current]
1306 list [test_ns_1::q] \
1307 [namespace delete test_ns_1] \
1308 [catch {test_ns_1::q} msg] $msg
1309 } {::test_ns_1 {} 1 {invalid command name "test_ns_1::q"}}
1313 test namespace-36.1 {DupNsNameInternalRep} {
1314 catch {eval namespace delete [namespace children :: test_ns_*]}
1315 namespace eval test_ns_1 {}
1317 list [namespace parent $x] [set y $x] [namespace parent $y]
1318 } {:: ::test_ns_1 ::}
1322 test namespace-37.1 {SetNsNameFromAny, ns name found} {
1323 catch {eval namespace delete [namespace children :: test_ns_*]}
1324 namespace eval test_ns_1::test_ns_2 {}
1325 namespace eval test_ns_1 {
1326 namespace children ::test_ns_1
1328 } {::test_ns_1::test_ns_2}
1329 test namespace-37.2 {SetNsNameFromAny, ns name not found} {
1330 namespace eval test_ns_1 {
1331 list [catch {namespace children ::test_ns_1::test_ns_foo} msg] $msg
1333 } {1 {unknown namespace "::test_ns_1::test_ns_foo" in namespace children command}}
1335 test namespace-38.1 {UpdateStringOfNsName} {
1336 catch {eval namespace delete [namespace children :: test_ns_*]}
1337 ;# Tcl_NamespaceObjCmd calls UpdateStringOfNsName to get subcmd name
1338 list [namespace eval {} {namespace current}] \
1339 [namespace eval {} {namespace current}]
1342 test namespace-39.1 {NamespaceExistsCmd} {
1343 catch {eval namespace delete [namespace children :: test_ns_*]}
1344 namespace eval ::test_ns_z::test_me { variable foo }
1345 list [namespace exists ::] \
1346 [namespace exists ::bogus_namespace] \
1347 [namespace exists ::test_ns_z] \
1348 [namespace exists test_ns_z] \
1349 [namespace exists ::test_ns_z::foo] \
1350 [namespace exists ::test_ns_z::test_me] \
1351 [namespace eval ::test_ns_z { namespace exists ::test_me }] \
1352 [namespace eval ::test_ns_z { namespace exists test_me }] \
1353 [namespace exists :::::test_ns_z]
1354 } {1 0 1 1 0 1 0 1 1}
1355 test namespace-39.2 {NamespaceExistsCmd error} {
1356 list [catch {namespace exists} msg] $msg
1357 } {1 {wrong # args: should be "namespace exists name"}}
1358 test namespace-39.3 {NamespaceExistsCmd error} {
1359 list [catch {namespace exists a b} msg] $msg
1360 } {1 {wrong # args: should be "namespace exists name"}}
1362 test namespace-40.1 {Ignoring namespace proc "unknown"} {
1363 rename unknown _unknown
1364 proc unknown args {return global}
1365 namespace eval ns {proc unknown args {return local}}
1366 set l [list [namespace eval ns aaa bbb] [namespace eval ns aaa]]
1368 rename _unknown unknown
1373 test namespace-41.1 {Shadowing byte-compiled commands, Bug: 231259} {
1380 lappend ::res [test]
1384 lappend ::res [test]
1390 test namespace-41.2 {Shadowing byte-compiled commands, Bug: 231259} {
1392 namespace eval ns {}
1395 proc set args {return "New proc is called"}
1402 } {New proc is called}
1404 test namespace-41.3 {Shadowing byte-compiled commands, Bug: 231259} {knownBug} {
1412 proc set args {return "New proc is called"}
1416 set res [list [ns::a 1] $ns::b]
1419 } {{New proc is called} 0}
1422 catch {rename cmd1 {}}
1425 catch {unset trigger}
1426 eval namespace delete [namespace children :: test_ns_*]
1427 ::tcltest::cleanupTests