| 1 |
# Functionality covered: this file contains a collection of tests for the |
| 2 |
# procedures in tclNamesp.c and tclEnsemble.c that implement Tcl's basic |
| 3 |
# support for namespaces. Other namespace-related tests appear in |
| 4 |
# variable.test. |
| 5 |
# |
| 6 |
# Sourcing this file into Tcl runs the tests and generates output for errors. |
| 7 |
# No output means no errors were found. |
| 8 |
# |
| 9 |
# Copyright (c) 1997 Sun Microsystems, Inc. |
| 10 |
# Copyright (c) 1998-2000 by Scriptics Corporation. |
| 11 |
# |
| 12 |
# See the file "license.terms" for information on usage and redistribution of |
| 13 |
# this file, and for a DISCLAIMER OF ALL WARRANTIES. |
| 14 |
|
| 15 |
if {"::tcltest" ni [namespace children]} { |
| 16 |
package require tcltest 2.5 |
| 17 |
namespace import -force ::tcltest::* |
| 18 |
} |
| 19 |
testConstraint memory [llength [info commands memory]] |
| 20 |
|
| 21 |
::tcltest::loadTestedCommands |
| 22 |
catch [list package require -exact Tcltest [info patchlevel]] |
| 23 |
|
| 24 |
# |
| 25 |
# REMARK: the tests for 'namespace upvar' are not done here. They are to be |
| 26 |
# found in the file 'upvar.test'. |
| 27 |
# |
| 28 |
|
| 29 |
# Clear out any namespaces called test_ns_* |
| 30 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 31 |
|
| 32 |
proc fq {ns} { |
| 33 |
if {[string match ::* $ns]} {return $ns} |
| 34 |
set current [uplevel 1 {namespace current}] |
| 35 |
return [string trimright $current :]::[string trimleft $ns :] |
| 36 |
} |
| 37 |
|
| 38 |
test namespace-1.1 {TclInitNamespaces, GetNamespaceFromObj, NamespaceChildrenCmd} { |
| 39 |
namespace children :: test_ns_* |
| 40 |
} {} |
| 41 |
|
| 42 |
catch {unset l} |
| 43 |
test namespace-2.1 {Tcl_GetCurrentNamespace} { |
| 44 |
list [namespace current] [namespace eval {} {namespace current}] \ |
| 45 |
[namespace eval {} {namespace current}] |
| 46 |
} {:: :: ::} |
| 47 |
test namespace-2.2 {Tcl_GetCurrentNamespace} { |
| 48 |
set l {} |
| 49 |
lappend l [namespace current] |
| 50 |
namespace eval test_ns_1 { |
| 51 |
lappend l [namespace current] |
| 52 |
namespace eval foo { |
| 53 |
lappend l [namespace current] |
| 54 |
} |
| 55 |
} |
| 56 |
lappend l [namespace current] |
| 57 |
} {:: ::test_ns_1 ::test_ns_1::foo ::} |
| 58 |
|
| 59 |
test namespace-3.1 {Tcl_GetGlobalNamespace} { |
| 60 |
namespace eval test_ns_1 {namespace eval foo {namespace eval bar {} } } |
| 61 |
# namespace children uses Tcl_GetGlobalNamespace |
| 62 |
namespace eval test_ns_1 {namespace children foo b*} |
| 63 |
} {::test_ns_1::foo::bar} |
| 64 |
|
| 65 |
test namespace-4.1 {Tcl_PushCallFrame with isProcCallFrame=1} { |
| 66 |
namespace eval test_ns_1 { |
| 67 |
variable v 123 |
| 68 |
proc p {} { |
| 69 |
variable v |
| 70 |
return $v |
| 71 |
} |
| 72 |
} |
| 73 |
test_ns_1::p ;# does Tcl_PushCallFrame to push p's namespace |
| 74 |
} {123} |
| 75 |
test namespace-4.2 {Tcl_PushCallFrame with isProcCallFrame=0} { |
| 76 |
namespace eval test_ns_1::baz {} ;# does Tcl_PushCallFrame to create baz |
| 77 |
proc test_ns_1::baz::p {} { |
| 78 |
variable v |
| 79 |
set v 789 |
| 80 |
set v} |
| 81 |
test_ns_1::baz::p |
| 82 |
} {789} |
| 83 |
|
| 84 |
test namespace-5.1 {Tcl_PopCallFrame, no vars} { |
| 85 |
namespace eval test_ns_1::blodge {} ;# pushes then pops frame |
| 86 |
} {} |
| 87 |
test namespace-5.2 {Tcl_PopCallFrame, local vars must be deleted} -setup { |
| 88 |
namespace eval test_ns_1 {} |
| 89 |
} -body { |
| 90 |
proc test_ns_1::r {} { |
| 91 |
set a 123 |
| 92 |
} |
| 93 |
test_ns_1::r ;# pushes then pop's r's frame |
| 94 |
} -result {123} |
| 95 |
|
| 96 |
test namespace-6.1 {Tcl_CreateNamespace} { |
| 97 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 98 |
list [lsort [namespace children :: test_ns_*]] \ |
| 99 |
[namespace eval test_ns_1 {namespace current}] \ |
| 100 |
[namespace eval test_ns_2 {namespace current}] \ |
| 101 |
[namespace eval ::test_ns_3 {namespace current}] \ |
| 102 |
[namespace eval ::test_ns_4 \ |
| 103 |
{namespace eval foo {namespace current}}] \ |
| 104 |
[namespace eval ::test_ns_5 \ |
| 105 |
{namespace eval ::test_ns_6 {namespace current}}] \ |
| 106 |
[lsort [namespace children :: test_ns_*]] |
| 107 |
} {{} ::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}} |
| 108 |
test namespace-6.2 {Tcl_CreateNamespace, odd number of :'s in name is okay} { |
| 109 |
list [namespace eval :::test_ns_1::::foo {namespace current}] \ |
| 110 |
[namespace eval test_ns_2:::::foo {namespace current}] |
| 111 |
} {::test_ns_1::foo ::test_ns_2::foo} |
| 112 |
test namespace-6.3 {Tcl_CreateNamespace, trailing ::s in ns name are ignored} { |
| 113 |
list [catch {namespace eval test_ns_7::: {namespace current}} msg] $msg |
| 114 |
} {0 ::test_ns_7} |
| 115 |
test namespace-6.4 {Tcl_CreateNamespace, trailing ::s in ns name are ignored} { |
| 116 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 117 |
namespace eval test_ns_1:: { |
| 118 |
namespace eval test_ns_2:: {} |
| 119 |
namespace eval test_ns_3:: {} |
| 120 |
} |
| 121 |
lsort [namespace children ::test_ns_1] |
| 122 |
} [lsort {::test_ns_1::test_ns_2 ::test_ns_1::test_ns_3}] |
| 123 |
test namespace-6.5 {Tcl_CreateNamespace, relative ns names now only looked up in current ns} { |
| 124 |
set trigger { |
| 125 |
namespace eval test_ns_2 {namespace current} |
| 126 |
} |
| 127 |
set l {} |
| 128 |
lappend l [namespace eval test_ns_1 $trigger] |
| 129 |
namespace eval test_ns_1::test_ns_2 {} |
| 130 |
lappend l [namespace eval test_ns_1 $trigger] |
| 131 |
} {::test_ns_1::test_ns_2 ::test_ns_1::test_ns_2} |
| 132 |
|
| 133 |
test namespace-7.1 {Tcl_DeleteNamespace, active call frames in ns} { |
| 134 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 135 |
namespace eval test_ns_1 { |
| 136 |
proc p {} { |
| 137 |
namespace delete [namespace current] |
| 138 |
return [namespace current] |
| 139 |
} |
| 140 |
} |
| 141 |
list [test_ns_1::p] [catch {test_ns_1::p} msg] $msg |
| 142 |
} {::test_ns_1 1 {invalid command name "test_ns_1::p"}} |
| 143 |
test namespace-7.2 {Tcl_DeleteNamespace, no active call frames in ns} { |
| 144 |
namespace eval test_ns_2 { |
| 145 |
proc p {} { |
| 146 |
return [namespace current] |
| 147 |
} |
| 148 |
} |
| 149 |
list [test_ns_2::p] [namespace delete test_ns_2] |
| 150 |
} {::test_ns_2 {}} |
| 151 |
test namespace-7.3 {recursive Tcl_DeleteNamespace, active call frames in ns} { |
| 152 |
# [Bug 1355942] |
| 153 |
namespace eval test_ns_2 { |
| 154 |
set x 1 |
| 155 |
trace add variable x unset "namespace delete [namespace current];#" |
| 156 |
namespace delete [namespace current] |
| 157 |
} |
| 158 |
} {} |
| 159 |
test namespace-7.4 {recursive Tcl_DeleteNamespace, active call frames in ns} { |
| 160 |
# [Bug 1355942] |
| 161 |
namespace eval test_ns_2 { |
| 162 |
proc x {} {} |
| 163 |
trace add command x delete "namespace delete [namespace current];#" |
| 164 |
namespace delete [namespace current] |
| 165 |
} |
| 166 |
} {} |
| 167 |
test namespace-7.5 {recursive Tcl_DeleteNamespace, no active call frames in ns} { |
| 168 |
# [Bug 1355942] |
| 169 |
namespace eval test_ns_2 { |
| 170 |
set x 1 |
| 171 |
trace add variable x unset "namespace delete [namespace current];#" |
| 172 |
} |
| 173 |
namespace delete test_ns_2 |
| 174 |
} {} |
| 175 |
test namespace-7.6 {recursive Tcl_DeleteNamespace, no active call frames in ns} { |
| 176 |
# [Bug 1355942] |
| 177 |
namespace eval test_ns_2 { |
| 178 |
proc x {} {} |
| 179 |
trace add command x delete "namespace delete [namespace current];#" |
| 180 |
} |
| 181 |
namespace delete test_ns_2 |
| 182 |
} {} |
| 183 |
test namespace-7.7 {Bug 1655305} -setup { |
| 184 |
interp create child |
| 185 |
# Can't invoke through the ensemble, since deleting the global namespace |
| 186 |
# (indirectly, via deleting ::tcl) deletes the ensemble. |
| 187 |
child eval {rename ::tcl::info::commands ::infocommands} |
| 188 |
child hide infocommands |
| 189 |
child eval { |
| 190 |
proc foo {} { |
| 191 |
namespace delete :: |
| 192 |
} |
| 193 |
} |
| 194 |
} -body { |
| 195 |
child eval foo |
| 196 |
child invokehidden infocommands |
| 197 |
} -cleanup { |
| 198 |
interp delete child |
| 199 |
} -result {} |
| 200 |
|
| 201 |
test namespace-7.8 {Bug ba1419303b4c} -setup { |
| 202 |
namespace eval ns1 { |
| 203 |
namespace ensemble create |
| 204 |
} |
| 205 |
|
| 206 |
trace add command ns1 delete { |
| 207 |
namespace delete ns1 |
| 208 |
} |
| 209 |
} -body { |
| 210 |
# No segmentation fault given --enable-symbols=mem. |
| 211 |
namespace delete ns1 |
| 212 |
} -result {} |
| 213 |
|
| 214 |
test namespace-8.1 {TclTeardownNamespace, delete global namespace} { |
| 215 |
catch {interp delete test_interp} |
| 216 |
interp create test_interp |
| 217 |
interp eval test_interp { |
| 218 |
namespace eval test_ns_1 { |
| 219 |
namespace export p |
| 220 |
proc p {} { |
| 221 |
return [namespace current] |
| 222 |
} |
| 223 |
} |
| 224 |
namespace eval test_ns_2 { |
| 225 |
namespace import ::test_ns_1::p |
| 226 |
variable v 27 |
| 227 |
proc q {} { |
| 228 |
variable v |
| 229 |
return "[p] $v" |
| 230 |
} |
| 231 |
} |
| 232 |
set x [test_ns_2::q] |
| 233 |
catch {set xxxx} |
| 234 |
} |
| 235 |
list [interp eval test_interp {test_ns_2::q}] \ |
| 236 |
[interp eval test_interp {namespace delete ::}] \ |
| 237 |
[catch {interp eval test_interp {set a 123}} msg] $msg \ |
| 238 |
[interp delete test_interp] |
| 239 |
} {{::test_ns_1 27} {} 1 {invalid command name "set"} {}} |
| 240 |
test namespace-8.2 {TclTeardownNamespace, remove deleted ns from parent} { |
| 241 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 242 |
namespace eval test_ns_1::test_ns_2::test_ns_3a {proc p {} {}} |
| 243 |
namespace eval test_ns_1::test_ns_2::test_ns_3b {proc q {} {}} |
| 244 |
list [namespace children test_ns_1] \ |
| 245 |
[namespace delete test_ns_1::test_ns_2] \ |
| 246 |
[namespace children test_ns_1] |
| 247 |
} {::test_ns_1::test_ns_2 {} {}} |
| 248 |
test namespace-8.3 {TclTeardownNamespace, delete child namespaces} { |
| 249 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 250 |
namespace eval test_ns_1::test_ns_2::test_ns_3a {proc p {} {}} |
| 251 |
namespace eval test_ns_1::test_ns_2::test_ns_3b {proc q {} {}} |
| 252 |
list [namespace children test_ns_1] \ |
| 253 |
[namespace delete test_ns_1::test_ns_2] \ |
| 254 |
[namespace children test_ns_1] \ |
| 255 |
[catch {namespace children test_ns_1::test_ns_2} msg] $msg \ |
| 256 |
[info commands test_ns_1::test_ns_2::test_ns_3a::*] |
| 257 |
} {::test_ns_1::test_ns_2 {} {} 1 {namespace "test_ns_1::test_ns_2" not found in "::"} {}} |
| 258 |
test namespace-8.4 {TclTeardownNamespace, cmds imported from deleted ns go away} { |
| 259 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 260 |
namespace eval test_ns_export { |
| 261 |
namespace export cmd1 cmd2 |
| 262 |
proc cmd1 {args} {return "cmd1: $args"} |
| 263 |
proc cmd2 {args} {return "cmd2: $args"} |
| 264 |
} |
| 265 |
namespace eval test_ns_import { |
| 266 |
namespace import ::test_ns_export::* |
| 267 |
proc p {} {return foo} |
| 268 |
} |
| 269 |
list [lsort [info commands test_ns_import::*]] \ |
| 270 |
[namespace delete test_ns_export] \ |
| 271 |
[info commands test_ns_import::*] |
| 272 |
} [list [lsort {::test_ns_import::p ::test_ns_import::cmd1 ::test_ns_import::cmd2}] {} ::test_ns_import::p] |
| 273 |
test namespace-8.5 {TclTeardownNamespace: preserve errorInfo; errorCode values} { |
| 274 |
interp create child |
| 275 |
child eval {trace add execution error leave {namespace delete :: ;#}} |
| 276 |
catch {child eval error foo bar baz} |
| 277 |
interp delete child |
| 278 |
set ::errorInfo |
| 279 |
} {bar |
| 280 |
invoked from within |
| 281 |
"child eval error foo bar baz"} |
| 282 |
test namespace-8.6 {TclTeardownNamespace: preserve errorInfo; errorCode values} { |
| 283 |
interp create child |
| 284 |
child eval {trace add variable errorCode write {namespace delete :: ;#}} |
| 285 |
catch {child eval error foo bar baz} |
| 286 |
interp delete child |
| 287 |
set ::errorInfo |
| 288 |
} {bar |
| 289 |
invoked from within |
| 290 |
"child eval error foo bar baz"} |
| 291 |
test namespace-8.7 {TclTeardownNamespace: preserve errorInfo; errorCode values} { |
| 292 |
interp create child |
| 293 |
child eval {trace add execution error leave {namespace delete :: ;#}} |
| 294 |
catch {child eval error foo bar baz} |
| 295 |
interp delete child |
| 296 |
set ::errorCode |
| 297 |
} baz |
| 298 |
|
| 299 |
test namespace-9.1 {Tcl_Import, empty import pattern} { |
| 300 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 301 |
list [catch {namespace eval test_ns_import {namespace import {}}} msg] $msg |
| 302 |
} {1 {empty import pattern}} |
| 303 |
test namespace-9.2 {Tcl_Import, unknown namespace in import pattern} { |
| 304 |
list [catch {namespace eval test_ns_import {namespace import fred::x}} msg] $msg |
| 305 |
} {1 {unknown namespace in import pattern "fred::x"}} |
| 306 |
test namespace-9.3 {Tcl_Import, import ns == export ns} { |
| 307 |
list [catch {namespace eval test_ns_import {namespace import ::test_ns_import::puts}} msg] $msg |
| 308 |
} {1 {import pattern "::test_ns_import::puts" tries to import from namespace "test_ns_import" into itself}} |
| 309 |
test namespace-9.4 {Tcl_Import, simple import} { |
| 310 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 311 |
namespace eval test_ns_export { |
| 312 |
namespace export cmd1 |
| 313 |
proc cmd1 {args} {return "cmd1: $args"} |
| 314 |
proc cmd2 {args} {return "cmd2: $args"} |
| 315 |
} |
| 316 |
namespace eval test_ns_import { |
| 317 |
namespace import ::test_ns_export::* |
| 318 |
proc p {} {return [cmd1 123]} |
| 319 |
} |
| 320 |
test_ns_import::p |
| 321 |
} {cmd1: 123} |
| 322 |
test namespace-9.5 {Tcl_Import, RFE 1230597} -setup { |
| 323 |
namespace eval test_ns_import {} |
| 324 |
namespace eval test_ns_export {} |
| 325 |
} -body { |
| 326 |
list [catch {namespace eval test_ns_import {namespace import ::test_ns_export::*}} msg] $msg |
| 327 |
} -result {0 {}} |
| 328 |
test namespace-9.6 {Tcl_Import, cmd redefinition ok if allowOverwrite!=0} -setup { |
| 329 |
namespace eval test_ns_import {} |
| 330 |
namespace eval ::test_ns_export { |
| 331 |
proc cmd1 {args} {return "cmd1: $args"} |
| 332 |
namespace export cmd1 |
| 333 |
} |
| 334 |
} -body { |
| 335 |
namespace eval test_ns_import { |
| 336 |
namespace import -force ::test_ns_export::* |
| 337 |
cmd1 555 |
| 338 |
} |
| 339 |
} -result {cmd1: 555} |
| 340 |
test namespace-9.7 {Tcl_Import, links are preserved if cmd is redefined} { |
| 341 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 342 |
namespace eval test_ns_export { |
| 343 |
namespace export cmd1 |
| 344 |
proc cmd1 {args} {return "cmd1: $args"} |
| 345 |
} |
| 346 |
namespace eval test_ns_import { |
| 347 |
namespace import -force ::test_ns_export::* |
| 348 |
} |
| 349 |
list [test_ns_import::cmd1 a b c] \ |
| 350 |
[test_ns_export::cmd1 d e f] \ |
| 351 |
[proc test_ns_export::cmd1 {args} {return "new1: $args"}] \ |
| 352 |
[namespace origin test_ns_import::cmd1] \ |
| 353 |
[namespace origin test_ns_export::cmd1] \ |
| 354 |
[test_ns_import::cmd1 g h i] \ |
| 355 |
[test_ns_export::cmd1 j k l] |
| 356 |
} {{cmd1: a b c} {cmd1: d e f} {} ::test_ns_export::cmd1 ::test_ns_export::cmd1 {new1: g h i} {new1: j k l}} |
| 357 |
test namespace-9.8 {Tcl_Import: Bug 1017299} -setup { |
| 358 |
namespace eval one { |
| 359 |
namespace export cmd |
| 360 |
proc cmd {} {} |
| 361 |
} |
| 362 |
namespace eval two { |
| 363 |
namespace export cmd |
| 364 |
proc other args {} |
| 365 |
} |
| 366 |
namespace eval two \ |
| 367 |
[list namespace import [namespace current]::one::cmd] |
| 368 |
namespace eval three \ |
| 369 |
[list namespace import [namespace current]::two::cmd] |
| 370 |
namespace eval three { |
| 371 |
rename cmd other |
| 372 |
namespace export other |
| 373 |
} |
| 374 |
} -body { |
| 375 |
namespace eval two [list namespace import -force \ |
| 376 |
[namespace current]::three::other] |
| 377 |
namespace origin two::other |
| 378 |
} -cleanup { |
| 379 |
namespace delete one two three |
| 380 |
} -match glob -result *::one::cmd |
| 381 |
test namespace-9.9 {Tcl_Import: Bug 1017299} -setup { |
| 382 |
namespace eval one { |
| 383 |
namespace export cmd |
| 384 |
proc cmd {} {} |
| 385 |
} |
| 386 |
namespace eval two namespace export cmd |
| 387 |
namespace eval two \ |
| 388 |
[list namespace import [namespace current]::one::cmd] |
| 389 |
namespace eval three namespace export cmd |
| 390 |
namespace eval three \ |
| 391 |
[list namespace import [namespace current]::two::cmd] |
| 392 |
} -body { |
| 393 |
namespace eval two [list namespace import -force \ |
| 394 |
[namespace current]::three::cmd] |
| 395 |
namespace origin two::cmd |
| 396 |
} -cleanup { |
| 397 |
namespace delete one two three |
| 398 |
} -returnCodes error -match glob -result {import pattern * would create a loop*} |
| 399 |
|
| 400 |
test namespace-10.1 {Tcl_ForgetImport, check for valid namespaces} { |
| 401 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 402 |
list [catch {namespace forget xyzzy::*} msg] $msg |
| 403 |
} {1 {unknown namespace in namespace forget pattern "xyzzy::*"}} |
| 404 |
test namespace-10.2 {Tcl_ForgetImport, ignores patterns that don't match} { |
| 405 |
namespace eval test_ns_export { |
| 406 |
namespace export cmd1 |
| 407 |
proc cmd1 {args} {return "cmd1: $args"} |
| 408 |
proc cmd2 {args} {return "cmd2: $args"} |
| 409 |
} |
| 410 |
namespace eval test_ns_import { |
| 411 |
namespace forget ::test_ns_export::wombat |
| 412 |
} |
| 413 |
} {} |
| 414 |
test namespace-10.3 {Tcl_ForgetImport, deletes matching imported cmds} -setup { |
| 415 |
namespace eval test_ns_export { |
| 416 |
namespace export cmd1 |
| 417 |
proc cmd1 {args} {return "cmd1: $args"} |
| 418 |
proc cmd2 {args} {return "cmd2: $args"} |
| 419 |
} |
| 420 |
} -body { |
| 421 |
namespace eval test_ns_import { |
| 422 |
namespace import ::test_ns_export::* |
| 423 |
proc p {} {return [cmd1 123]} |
| 424 |
set l {} |
| 425 |
lappend l [lsort [info commands ::test_ns_import::*]] |
| 426 |
namespace forget ::test_ns_export::cmd1 |
| 427 |
lappend l [info commands ::test_ns_import::*] |
| 428 |
lappend l [catch {cmd1 777} msg] $msg |
| 429 |
} |
| 430 |
} -result [list [lsort {::test_ns_import::p ::test_ns_import::cmd1}] ::test_ns_import::p 1 {invalid command name "cmd1"}] |
| 431 |
test namespace-10.4 {Tcl_ForgetImport: Bug 560297} -setup { |
| 432 |
namespace eval origin { |
| 433 |
namespace export cmd |
| 434 |
proc cmd {} {} |
| 435 |
} |
| 436 |
namespace eval unrelated { |
| 437 |
proc cmd {} {} |
| 438 |
} |
| 439 |
namespace eval my \ |
| 440 |
[list namespace import [namespace current]::origin::cmd] |
| 441 |
} -body { |
| 442 |
namespace eval my \ |
| 443 |
[list namespace forget [namespace current]::unrelated::cmd] |
| 444 |
my::cmd |
| 445 |
} -cleanup { |
| 446 |
namespace delete origin unrelated my |
| 447 |
} |
| 448 |
test namespace-10.5 {Tcl_ForgetImport: Bug 560297} -setup { |
| 449 |
namespace eval origin { |
| 450 |
namespace export cmd |
| 451 |
proc cmd {} {} |
| 452 |
} |
| 453 |
namespace eval my \ |
| 454 |
[list namespace import [namespace current]::origin::cmd] |
| 455 |
namespace eval my rename cmd newname |
| 456 |
} -body { |
| 457 |
namespace eval my \ |
| 458 |
[list namespace forget [namespace current]::origin::cmd] |
| 459 |
my::newname |
| 460 |
} -cleanup { |
| 461 |
namespace delete origin my |
| 462 |
} -returnCodes error -match glob -result * |
| 463 |
test namespace-10.6 {Tcl_ForgetImport: Bug 560297} -setup { |
| 464 |
namespace eval origin { |
| 465 |
namespace export cmd |
| 466 |
proc cmd {} {} |
| 467 |
} |
| 468 |
namespace eval my \ |
| 469 |
[list namespace import [namespace current]::origin::cmd] |
| 470 |
namespace eval your {} |
| 471 |
namespace eval my \ |
| 472 |
[list rename cmd [namespace current]::your::newname] |
| 473 |
} -body { |
| 474 |
namespace eval your namespace forget newname |
| 475 |
your::newname |
| 476 |
} -cleanup { |
| 477 |
namespace delete origin my your |
| 478 |
} -returnCodes error -match glob -result * |
| 479 |
test namespace-10.7 {Tcl_ForgetImport: Bug 560297} -setup { |
| 480 |
namespace eval origin { |
| 481 |
namespace export cmd |
| 482 |
proc cmd {} {} |
| 483 |
} |
| 484 |
namespace eval link namespace export cmd |
| 485 |
namespace eval link \ |
| 486 |
[list namespace import [namespace current]::origin::cmd] |
| 487 |
namespace eval link2 namespace export cmd |
| 488 |
namespace eval link2 \ |
| 489 |
[list namespace import [namespace current]::link::cmd] |
| 490 |
namespace eval my \ |
| 491 |
[list namespace import [namespace current]::link2::cmd] |
| 492 |
} -body { |
| 493 |
namespace eval my \ |
| 494 |
[list namespace forget [namespace current]::origin::cmd] |
| 495 |
my::cmd |
| 496 |
} -cleanup { |
| 497 |
namespace delete origin link link2 my |
| 498 |
} -returnCodes error -match glob -result * |
| 499 |
test namespace-10.8 {Tcl_ForgetImport: Bug 560297} -setup { |
| 500 |
namespace eval origin { |
| 501 |
namespace export cmd |
| 502 |
proc cmd {} {} |
| 503 |
} |
| 504 |
namespace eval link namespace export cmd |
| 505 |
namespace eval link \ |
| 506 |
[list namespace import [namespace current]::origin::cmd] |
| 507 |
namespace eval link2 namespace export cmd |
| 508 |
namespace eval link2 \ |
| 509 |
[list namespace import [namespace current]::link::cmd] |
| 510 |
namespace eval my \ |
| 511 |
[list namespace import [namespace current]::link2::cmd] |
| 512 |
} -body { |
| 513 |
namespace eval my \ |
| 514 |
[list namespace forget [namespace current]::link::cmd] |
| 515 |
my::cmd |
| 516 |
} -cleanup { |
| 517 |
namespace delete origin link link2 my |
| 518 |
} |
| 519 |
test namespace-10.9 {Tcl_ForgetImport: Bug 560297} -setup { |
| 520 |
namespace eval origin { |
| 521 |
namespace export cmd |
| 522 |
proc cmd {} {} |
| 523 |
} |
| 524 |
namespace eval link namespace export cmd |
| 525 |
namespace eval link \ |
| 526 |
[list namespace import [namespace current]::origin::cmd] |
| 527 |
namespace eval link2 namespace export cmd |
| 528 |
namespace eval link2 \ |
| 529 |
[list namespace import [namespace current]::link::cmd] |
| 530 |
namespace eval my \ |
| 531 |
[list namespace import [namespace current]::link2::cmd] |
| 532 |
} -body { |
| 533 |
namespace eval my \ |
| 534 |
[list namespace forget [namespace current]::link2::cmd] |
| 535 |
my::cmd |
| 536 |
} -cleanup { |
| 537 |
namespace delete origin link link2 my |
| 538 |
} -returnCodes error -match glob -result * |
| 539 |
|
| 540 |
test namespace-11.1 {TclGetOriginalCommand, check if not imported cmd} -setup { |
| 541 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 542 |
} -body { |
| 543 |
namespace eval test_ns_export { |
| 544 |
namespace export cmd1 |
| 545 |
proc cmd1 {args} {return "cmd1: $args"} |
| 546 |
} |
| 547 |
list [namespace origin set] [namespace origin test_ns_export::cmd1] |
| 548 |
} -result {::set ::test_ns_export::cmd1} |
| 549 |
test namespace-11.2 {TclGetOriginalCommand, directly imported cmd} -setup { |
| 550 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 551 |
namespace eval test_ns_export { |
| 552 |
namespace export cmd1 |
| 553 |
proc cmd1 {args} {return "cmd1: $args"} |
| 554 |
} |
| 555 |
} -body { |
| 556 |
namespace eval test_ns_import1 { |
| 557 |
namespace import ::test_ns_export::* |
| 558 |
namespace export * |
| 559 |
proc p {} {namespace origin cmd1} |
| 560 |
} |
| 561 |
list [test_ns_import1::p] [namespace origin test_ns_import1::cmd1] |
| 562 |
} -result {::test_ns_export::cmd1 ::test_ns_export::cmd1} |
| 563 |
test namespace-11.3 {TclGetOriginalCommand, indirectly imported cmd} -setup { |
| 564 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 565 |
namespace eval test_ns_export { |
| 566 |
namespace export cmd1 |
| 567 |
proc cmd1 {args} {return "cmd1: $args"} |
| 568 |
} |
| 569 |
namespace eval test_ns_import1 { |
| 570 |
namespace import ::test_ns_export::* |
| 571 |
namespace export * |
| 572 |
proc p {} {namespace origin cmd1} |
| 573 |
} |
| 574 |
} -body { |
| 575 |
namespace eval test_ns_import2 { |
| 576 |
namespace import ::test_ns_import1::* |
| 577 |
proc q {} {return [cmd1 123]} |
| 578 |
} |
| 579 |
list [test_ns_import2::q] [namespace origin test_ns_import2::cmd1] |
| 580 |
} -result {{cmd1: 123} ::test_ns_export::cmd1} |
| 581 |
|
| 582 |
test namespace-12.1 {InvokeImportedCmd} { |
| 583 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 584 |
namespace eval test_ns_export { |
| 585 |
namespace export cmd1 |
| 586 |
proc cmd1 {args} {namespace current} |
| 587 |
} |
| 588 |
namespace eval test_ns_import { |
| 589 |
namespace import ::test_ns_export::* |
| 590 |
} |
| 591 |
list [test_ns_import::cmd1] |
| 592 |
} {::test_ns_export} |
| 593 |
|
| 594 |
test namespace-13.1 {DeleteImportedCmd, deletes imported cmds} -setup { |
| 595 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 596 |
namespace eval test_ns_export { |
| 597 |
namespace export cmd1 |
| 598 |
proc cmd1 {args} {namespace current} |
| 599 |
} |
| 600 |
namespace eval test_ns_import { |
| 601 |
namespace import ::test_ns_export::* |
| 602 |
} |
| 603 |
} -body { |
| 604 |
namespace eval test_ns_import { |
| 605 |
set l {} |
| 606 |
lappend l [info commands ::test_ns_import::*] |
| 607 |
namespace forget ::test_ns_export::cmd1 |
| 608 |
lappend l [info commands ::test_ns_import::*] |
| 609 |
} |
| 610 |
} -result {::test_ns_import::cmd1 {}} |
| 611 |
test namespace-13.2 {DeleteImportedCmd, Bug a4494e28ed} { |
| 612 |
# Will panic if still buggy |
| 613 |
namespace eval src {namespace export foo; proc foo {} {}} |
| 614 |
namespace eval dst {namespace import [namespace parent]::src::foo} |
| 615 |
trace add command src::foo delete \ |
| 616 |
"[list namespace delete [namespace current]::dst] ;#" |
| 617 |
proc src::foo {} {} |
| 618 |
namespace delete src |
| 619 |
} {} |
| 620 |
|
| 621 |
test namespace-14.1 {TclGetNamespaceForQualName, absolute names} -setup { |
| 622 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 623 |
variable v 10 |
| 624 |
namespace eval test_ns_1::test_ns_2 { |
| 625 |
variable v 20 |
| 626 |
} |
| 627 |
namespace eval test_ns_2 { |
| 628 |
variable v 30 |
| 629 |
} |
| 630 |
} -body { |
| 631 |
namespace eval test_ns_1 { |
| 632 |
list $::v $::test_ns_2::v $::test_ns_1::test_ns_2::v \ |
| 633 |
[lsort [namespace children :: test_ns_*]] |
| 634 |
} |
| 635 |
} -result [list 10 30 20 [lsort {::test_ns_1 ::test_ns_2}]] |
| 636 |
test namespace-14.2 {TclGetNamespaceForQualName, invalid absolute names} -setup { |
| 637 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 638 |
variable v 10 |
| 639 |
namespace eval test_ns_1::test_ns_2 { |
| 640 |
variable v 20 |
| 641 |
} |
| 642 |
namespace eval test_ns_2 { |
| 643 |
variable v 30 |
| 644 |
} |
| 645 |
} -body { |
| 646 |
namespace eval test_ns_1 { |
| 647 |
list [catch {set ::test_ns_777::v} msg] $msg \ |
| 648 |
[catch {namespace children test_ns_777} msg] $msg |
| 649 |
} |
| 650 |
} -result {1 {can't read "::test_ns_777::v": no such variable} 1 {namespace "test_ns_777" not found in "::test_ns_1"}} |
| 651 |
test namespace-14.3 {TclGetNamespaceForQualName, relative names} -setup { |
| 652 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 653 |
variable v 10 |
| 654 |
namespace eval test_ns_1::test_ns_2 { |
| 655 |
variable v 20 |
| 656 |
} |
| 657 |
namespace eval test_ns_2 { |
| 658 |
variable v 30 |
| 659 |
} |
| 660 |
} -body { |
| 661 |
namespace eval test_ns_1 { |
| 662 |
list $v $test_ns_2::v |
| 663 |
} |
| 664 |
} -result {10 20} |
| 665 |
test namespace-14.4 {TclGetNamespaceForQualName, relative ns names looked up only in current ns} { |
| 666 |
namespace eval test_ns_1::test_ns_2 { |
| 667 |
namespace eval foo {} |
| 668 |
} |
| 669 |
namespace eval test_ns_1 { |
| 670 |
list [namespace children test_ns_2] \ |
| 671 |
[catch {namespace children test_ns_1} msg] $msg |
| 672 |
} |
| 673 |
} {::test_ns_1::test_ns_2::foo 1 {namespace "test_ns_1" not found in "::test_ns_1"}} |
| 674 |
test namespace-14.5 {TclGetNamespaceForQualName, relative ns names looked up only in current ns} { |
| 675 |
namespace eval ::test_ns_2 { |
| 676 |
namespace eval bar {} |
| 677 |
} |
| 678 |
namespace eval test_ns_1 { |
| 679 |
list [catch {namespace delete test_ns_2::bar} msg] $msg |
| 680 |
} |
| 681 |
} {1 {unknown namespace "test_ns_2::bar" in namespace delete command}} |
| 682 |
test namespace-14.6 {TclGetNamespaceForQualName, relative ns names looked up only in current ns} { |
| 683 |
namespace eval test_ns_1::test_ns_2 { |
| 684 |
namespace eval foo {} |
| 685 |
} |
| 686 |
namespace eval test_ns_1 { |
| 687 |
list [namespace children test_ns_2] \ |
| 688 |
[catch {namespace children test_ns_1} msg] $msg |
| 689 |
} |
| 690 |
} {::test_ns_1::test_ns_2::foo 1 {namespace "test_ns_1" not found in "::test_ns_1"}} |
| 691 |
test namespace-14.7 {TclGetNamespaceForQualName, ignore extra :s if ns} -setup { |
| 692 |
namespace eval test_ns_1::test_ns_2::foo {} |
| 693 |
} -body { |
| 694 |
namespace children test_ns_1::: |
| 695 |
} -result {::test_ns_1::test_ns_2} |
| 696 |
test namespace-14.8 {TclGetNamespaceForQualName, ignore extra :s if ns} -setup { |
| 697 |
namespace eval test_ns_1::test_ns_2::foo {} |
| 698 |
} -body { |
| 699 |
namespace children :::test_ns_1:::::test_ns_2::: |
| 700 |
} -result {::test_ns_1::test_ns_2::foo} |
| 701 |
test namespace-14.9 {TclGetNamespaceForQualName, extra ::s are significant for vars} { |
| 702 |
set l {} |
| 703 |
lappend l [catch {set test_ns_1::test_ns_2::} msg] $msg |
| 704 |
namespace eval test_ns_1::test_ns_2 {variable {} 2525} |
| 705 |
lappend l [set test_ns_1::test_ns_2::] |
| 706 |
} {1 {can't read "test_ns_1::test_ns_2::": no such variable} 2525} |
| 707 |
test namespace-14.10 {TclGetNamespaceForQualName, extra ::s are significant for vars} -setup { |
| 708 |
namespace eval test_ns_1::test_ns_2::foo {} |
| 709 |
unset -nocomplain test_ns_1::test_ns_2:: |
| 710 |
set l {} |
| 711 |
} -body { |
| 712 |
lappend l [catch {set test_ns_1::test_ns_2::} msg] $msg |
| 713 |
set test_ns_1::test_ns_2:: 314159 |
| 714 |
lappend l [set test_ns_1::test_ns_2::] |
| 715 |
} -result {1 {can't read "test_ns_1::test_ns_2::": no such variable} 314159} |
| 716 |
test namespace-14.11 {TclGetNamespaceForQualName, extra ::s are significant for commands} -setup { |
| 717 |
namespace eval test_ns_1::test_ns_2::foo {} |
| 718 |
catch {rename test_ns_1::test_ns_2:: {}} |
| 719 |
set l {} |
| 720 |
} -body { |
| 721 |
lappend l [catch {test_ns_1::test_ns_2:: hello} msg] $msg |
| 722 |
proc test_ns_1::test_ns_2:: {args} {return "\{\}: $args"} |
| 723 |
lappend l [test_ns_1::test_ns_2:: hello] |
| 724 |
} -result {1 {invalid command name "test_ns_1::test_ns_2::"} {{}: hello}} |
| 725 |
test namespace-14.12 {TclGetNamespaceForQualName, extra ::s are significant for vars} -setup { |
| 726 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 727 |
} -body { |
| 728 |
namespace eval test_ns_1 { |
| 729 |
variable {} |
| 730 |
set test_ns_1::(x) y |
| 731 |
} |
| 732 |
set test_ns_1::(x) |
| 733 |
} -result y |
| 734 |
test namespace-14.13 {TclGetNamespaceForQualName, namespace other than global ns can't have empty name} -setup { |
| 735 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 736 |
} -returnCodes error -body { |
| 737 |
namespace eval test_ns_1 { |
| 738 |
proc {} {} {} |
| 739 |
namespace eval {} {} |
| 740 |
{} |
| 741 |
} |
| 742 |
} -result {can't create namespace "": only global namespace can have empty name} |
| 743 |
|
| 744 |
test namespace-15.1 {Tcl_FindNamespace, absolute name found} -setup { |
| 745 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 746 |
} -body { |
| 747 |
namespace eval test_ns_delete { |
| 748 |
namespace eval test_ns_delete2 {} |
| 749 |
proc cmd {args} {namespace current} |
| 750 |
} |
| 751 |
list [namespace delete ::test_ns_delete::test_ns_delete2] \ |
| 752 |
[namespace children ::test_ns_delete] |
| 753 |
} -result {{} {}} |
| 754 |
test namespace-15.2 {Tcl_FindNamespace, absolute name not found} -body { |
| 755 |
namespace delete ::test_ns_delete::test_ns_delete2 |
| 756 |
} -returnCodes error -result {unknown namespace "::test_ns_delete::test_ns_delete2" in namespace delete command} |
| 757 |
test namespace-15.3 {Tcl_FindNamespace, relative name found} { |
| 758 |
namespace eval test_ns_delete { |
| 759 |
namespace eval test_ns_delete2 {} |
| 760 |
namespace eval test_ns_delete3 {} |
| 761 |
list [namespace delete test_ns_delete2] \ |
| 762 |
[namespace children [namespace current]] |
| 763 |
} |
| 764 |
} {{} ::test_ns_delete::test_ns_delete3} |
| 765 |
test namespace-15.4 {Tcl_FindNamespace, relative name not found} { |
| 766 |
namespace eval test_ns_delete2 {} |
| 767 |
namespace eval test_ns_delete { |
| 768 |
list [catch {namespace delete test_ns_delete2} msg] $msg |
| 769 |
} |
| 770 |
} {1 {unknown namespace "test_ns_delete2" in namespace delete command}} |
| 771 |
|
| 772 |
test namespace-16.1 {Tcl_FindCommand, absolute name found} -setup { |
| 773 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 774 |
} -body { |
| 775 |
namespace eval test_ns_1 { |
| 776 |
proc cmd {args} {return "[namespace current]::cmd: $args"} |
| 777 |
variable v "::test_ns_1::cmd" |
| 778 |
eval $v one |
| 779 |
} |
| 780 |
} -result {::test_ns_1::cmd: one} |
| 781 |
test namespace-16.2 {Tcl_FindCommand, absolute name found} -setup { |
| 782 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 783 |
namespace eval test_ns_1 { |
| 784 |
proc cmd {args} {return "[namespace current]::cmd: $args"} |
| 785 |
variable v "::test_ns_1::cmd" |
| 786 |
} |
| 787 |
} -body { |
| 788 |
eval $test_ns_1::v two |
| 789 |
} -result {::test_ns_1::cmd: two} |
| 790 |
test namespace-16.3 {Tcl_FindCommand, absolute name not found} { |
| 791 |
namespace eval test_ns_1 { |
| 792 |
variable v2 "::test_ns_1::ladidah" |
| 793 |
list [catch {eval $v2} msg] $msg |
| 794 |
} |
| 795 |
} {1 {invalid command name "::test_ns_1::ladidah"}} |
| 796 |
|
| 797 |
# save the "unknown" proc, which is redefined by the following two tests |
| 798 |
catch {rename unknown unknown.old} |
| 799 |
proc unknown {args} { |
| 800 |
return "unknown: $args" |
| 801 |
} |
| 802 |
test namespace-16.4 {Tcl_FindCommand, absolute name and TCL_GLOBAL_ONLY} { |
| 803 |
::test_ns_1::foobar x y z |
| 804 |
} {unknown: ::test_ns_1::foobar x y z} |
| 805 |
test namespace-16.5 {Tcl_FindCommand, absolute name and TCL_GLOBAL_ONLY} { |
| 806 |
::foobar 1 2 3 4 5 |
| 807 |
} {unknown: ::foobar 1 2 3 4 5} |
| 808 |
test namespace-16.6 {Tcl_FindCommand, relative name and TCL_GLOBAL_ONLY} { |
| 809 |
test_ns_1::foobar x y z |
| 810 |
} {unknown: test_ns_1::foobar x y z} |
| 811 |
test namespace-16.7 {Tcl_FindCommand, relative name and TCL_GLOBAL_ONLY} { |
| 812 |
foobar 1 2 3 4 5 |
| 813 |
} {unknown: foobar 1 2 3 4 5} |
| 814 |
# restore the "unknown" proc saved previously |
| 815 |
catch {rename unknown {}} |
| 816 |
catch {rename unknown.old unknown} |
| 817 |
|
| 818 |
test namespace-16.8 {Tcl_FindCommand, relative name found} -setup { |
| 819 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 820 |
namespace eval test_ns_1 { |
| 821 |
proc cmd {args} {return "[namespace current]::cmd: $args"} |
| 822 |
} |
| 823 |
} -body { |
| 824 |
namespace eval test_ns_1 { |
| 825 |
cmd a b c |
| 826 |
} |
| 827 |
} -result {::test_ns_1::cmd: a b c} |
| 828 |
test namespace-16.9 {Tcl_FindCommand, relative name found} -body { |
| 829 |
proc cmd2 {args} {return "[namespace current]::cmd2: $args"} |
| 830 |
namespace eval test_ns_1 { |
| 831 |
cmd2 a b c |
| 832 |
} |
| 833 |
} -cleanup { |
| 834 |
catch {rename cmd2 {}} |
| 835 |
} -result {::::cmd2: a b c} |
| 836 |
test namespace-16.10 {Tcl_FindCommand, relative name found, only look in current then global ns} -body { |
| 837 |
proc cmd2 {args} {return "[namespace current]::cmd2: $args"} |
| 838 |
namespace eval test_ns_1 { |
| 839 |
proc cmd2 {args} { |
| 840 |
return "[namespace current]::cmd2 in test_ns_1: $args" |
| 841 |
} |
| 842 |
namespace eval test_ns_12 { |
| 843 |
cmd2 a b c |
| 844 |
} |
| 845 |
} |
| 846 |
} -cleanup { |
| 847 |
catch {rename cmd2 {}} |
| 848 |
} -result {::::cmd2: a b c} |
| 849 |
test namespace-16.11 {Tcl_FindCommand, relative name not found} -body { |
| 850 |
namespace eval test_ns_1 { |
| 851 |
cmd3 a b c |
| 852 |
} |
| 853 |
} -returnCodes error -result {invalid command name "cmd3"} |
| 854 |
|
| 855 |
unset -nocomplain x |
| 856 |
test namespace-17.1 {Tcl_FindNamespaceVar, absolute name found} -setup { |
| 857 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 858 |
} -body { |
| 859 |
set x 314159 |
| 860 |
namespace eval test_ns_1 { |
| 861 |
set ::x |
| 862 |
} |
| 863 |
} -result {314159} |
| 864 |
variable ::x 314159 |
| 865 |
test namespace-17.2 {Tcl_FindNamespaceVar, absolute name found} { |
| 866 |
namespace eval test_ns_1 { |
| 867 |
variable x 777 |
| 868 |
set ::test_ns_1::x |
| 869 |
} |
| 870 |
} {777} |
| 871 |
test namespace-17.3 {Tcl_FindNamespaceVar, absolute name found} { |
| 872 |
namespace eval test_ns_1 { |
| 873 |
namespace eval test_ns_2 { |
| 874 |
variable x 1111 |
| 875 |
} |
| 876 |
set ::test_ns_1::test_ns_2::x |
| 877 |
} |
| 878 |
} {1111} |
| 879 |
test namespace-17.4 {Tcl_FindNamespaceVar, absolute name not found} -body { |
| 880 |
namespace eval test_ns_1 { |
| 881 |
namespace eval test_ns_2 { |
| 882 |
variable x 1111 |
| 883 |
} |
| 884 |
set ::test_ns_1::test_ns_2::y |
| 885 |
} |
| 886 |
} -returnCodes error -result {can't read "::test_ns_1::test_ns_2::y": no such variable} |
| 887 |
test namespace-17.5 {Tcl_FindNamespaceVar, absolute name and TCL_GLOBAL_ONLY} -setup { |
| 888 |
namespace eval ::test_ns_1::test_ns_2 {} |
| 889 |
} -body { |
| 890 |
namespace eval test_ns_1 { |
| 891 |
namespace eval test_ns_3 { |
| 892 |
variable ::test_ns_1::test_ns_2::x 2222 |
| 893 |
} |
| 894 |
} |
| 895 |
set ::test_ns_1::test_ns_2::x |
| 896 |
} -result {2222} |
| 897 |
test namespace-17.6 {Tcl_FindNamespaceVar, relative name found} -setup { |
| 898 |
namespace eval test_ns_1 { |
| 899 |
variable x 777 |
| 900 |
} |
| 901 |
} -body { |
| 902 |
namespace eval test_ns_1 { |
| 903 |
set x |
| 904 |
} |
| 905 |
} -result {777} |
| 906 |
test namespace-17.7 {Tcl_FindNamespaceVar, relative name found} { |
| 907 |
namespace eval test_ns_1 { |
| 908 |
variable x 777 |
| 909 |
unset x |
| 910 |
set x ;# must be global x now |
| 911 |
} |
| 912 |
} {314159} |
| 913 |
test namespace-17.8 {Tcl_FindNamespaceVar, relative name not found} -body { |
| 914 |
namespace eval test_ns_1 { |
| 915 |
set wuzzat |
| 916 |
} |
| 917 |
} -returnCodes error -result {can't read "wuzzat": no such variable} |
| 918 |
test namespace-17.9 {Tcl_FindNamespaceVar, relative name and TCL_GLOBAL_ONLY} { |
| 919 |
namespace eval test_ns_1 { |
| 920 |
variable a hello |
| 921 |
} |
| 922 |
set test_ns_1::a |
| 923 |
} {hello} |
| 924 |
test namespace-17.10 {Tcl_FindNamespaceVar, interference with cached varNames} -setup { |
| 925 |
namespace eval test_ns_1 {} |
| 926 |
} -body { |
| 927 |
proc test_ns {} { |
| 928 |
set ::test_ns_1::a 0 |
| 929 |
} |
| 930 |
test_ns |
| 931 |
rename test_ns {} |
| 932 |
namespace eval test_ns_1 unset a |
| 933 |
set a 0 |
| 934 |
namespace eval test_ns_1 set a 1 |
| 935 |
namespace delete test_ns_1 |
| 936 |
return $a |
| 937 |
} -result 1 |
| 938 |
catch {unset a} |
| 939 |
catch {unset x} |
| 940 |
|
| 941 |
catch {unset l} |
| 942 |
catch {rename foo {}} |
| 943 |
test namespace-18.1 {TclResetShadowedCmdRefs, one-level check for command shadowing} -setup { |
| 944 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 945 |
} -body { |
| 946 |
proc foo {} {return "global foo"} |
| 947 |
namespace eval test_ns_1 { |
| 948 |
proc trigger {} { |
| 949 |
return [foo] |
| 950 |
} |
| 951 |
} |
| 952 |
set l "" |
| 953 |
lappend l [test_ns_1::trigger] |
| 954 |
namespace eval test_ns_1 { |
| 955 |
# force invalidation of cached ref to "foo" in proc trigger |
| 956 |
proc foo {} {return "foo in test_ns_1"} |
| 957 |
} |
| 958 |
lappend l [test_ns_1::trigger] |
| 959 |
} -result {{global foo} {foo in test_ns_1}} |
| 960 |
test namespace-18.2 {TclResetShadowedCmdRefs, multilevel check for command shadowing} { |
| 961 |
namespace eval test_ns_2 { |
| 962 |
proc foo {} {return "foo in ::test_ns_2"} |
| 963 |
} |
| 964 |
namespace eval test_ns_1 { |
| 965 |
namespace eval test_ns_2 {} |
| 966 |
proc trigger {} { |
| 967 |
return [test_ns_2::foo] |
| 968 |
} |
| 969 |
} |
| 970 |
set l "" |
| 971 |
lappend l [test_ns_1::trigger] |
| 972 |
namespace eval test_ns_1 { |
| 973 |
namespace eval test_ns_2 { |
| 974 |
# force invalidation of cached ref to "foo" in proc trigger |
| 975 |
proc foo {} {return "foo in ::test_ns_1::test_ns_2"} |
| 976 |
} |
| 977 |
} |
| 978 |
lappend l [test_ns_1::trigger] |
| 979 |
} {{foo in ::test_ns_2} {foo in ::test_ns_1::test_ns_2}} |
| 980 |
catch {unset l} |
| 981 |
catch {rename foo {}} |
| 982 |
|
| 983 |
test namespace-19.1 {GetNamespaceFromObj, global name found} -setup { |
| 984 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 985 |
} -body { |
| 986 |
namespace eval test_ns_1::test_ns_2 {} |
| 987 |
namespace children ::test_ns_1 |
| 988 |
} -result {::test_ns_1::test_ns_2} |
| 989 |
test namespace-19.2 {GetNamespaceFromObj, relative name found} -setup { |
| 990 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 991 |
namespace eval test_ns_1::test_ns_2 {} |
| 992 |
} -body { |
| 993 |
namespace eval test_ns_1 { |
| 994 |
namespace children test_ns_2 |
| 995 |
} |
| 996 |
} -result {} |
| 997 |
test namespace-19.3 {GetNamespaceFromObj, name not found} -setup { |
| 998 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 999 |
} -body { |
| 1000 |
namespace eval test_ns_1 { |
| 1001 |
namespace children test_ns_99 |
| 1002 |
} |
| 1003 |
} -returnCodes error -result {namespace "test_ns_99" not found in "::test_ns_1"} |
| 1004 |
test namespace-19.4 {GetNamespaceFromObj, invalidation of cached ns refs} -setup { |
| 1005 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1006 |
namespace eval test_ns_1::test_ns_2 {} |
| 1007 |
} -body { |
| 1008 |
namespace eval test_ns_1 { |
| 1009 |
proc foo {} { |
| 1010 |
return [namespace children test_ns_2] |
| 1011 |
} |
| 1012 |
list [catch {namespace children test_ns_99} msg] $msg |
| 1013 |
} |
| 1014 |
set l {} |
| 1015 |
lappend l [test_ns_1::foo] |
| 1016 |
namespace delete test_ns_1::test_ns_2 |
| 1017 |
namespace eval test_ns_1::test_ns_2::test_ns_3 {} |
| 1018 |
lappend l [test_ns_1::foo] |
| 1019 |
} -result {{} ::test_ns_1::test_ns_2::test_ns_3} |
| 1020 |
|
| 1021 |
test namespace-20.1 {Tcl_NamespaceObjCmd, bad subcommand} { |
| 1022 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1023 |
list [catch {namespace} msg] $msg |
| 1024 |
} {1 {wrong # args: should be "namespace subcommand ?arg ...?"}} |
| 1025 |
test namespace-20.2 {Tcl_NamespaceObjCmd, bad subcommand} -body { |
| 1026 |
namespace wombat {} |
| 1027 |
} -returnCodes error -match glob -result {unknown or ambiguous subcommand "wombat": must be *} |
| 1028 |
test namespace-20.3 {Tcl_NamespaceObjCmd, abbreviations are okay} { |
| 1029 |
namespace ch :: test_ns_* |
| 1030 |
} {} |
| 1031 |
|
| 1032 |
test namespace-21.1 {NamespaceChildrenCmd, no args} -setup { |
| 1033 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1034 |
} -body { |
| 1035 |
namespace eval test_ns_1::test_ns_2 {} |
| 1036 |
expr {"::test_ns_1" in [namespace children]} |
| 1037 |
} -result {1} |
| 1038 |
test namespace-21.2 {NamespaceChildrenCmd, no args} -setup { |
| 1039 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1040 |
namespace eval test_ns_1::test_ns_2 {} |
| 1041 |
} -body { |
| 1042 |
namespace eval test_ns_1 { |
| 1043 |
namespace children |
| 1044 |
} |
| 1045 |
} -result {::test_ns_1::test_ns_2} |
| 1046 |
test namespace-21.3 {NamespaceChildrenCmd, ns name given} -setup { |
| 1047 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1048 |
namespace eval test_ns_1::test_ns_2 {} |
| 1049 |
} -body { |
| 1050 |
namespace children ::test_ns_1 |
| 1051 |
} -result {::test_ns_1::test_ns_2} |
| 1052 |
test namespace-21.4 {NamespaceChildrenCmd, ns name given} -setup { |
| 1053 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1054 |
namespace eval test_ns_1::test_ns_2 {} |
| 1055 |
} -body { |
| 1056 |
namespace eval test_ns_1 { |
| 1057 |
namespace children test_ns_2 |
| 1058 |
} |
| 1059 |
} -result {} |
| 1060 |
test namespace-21.5 {NamespaceChildrenCmd, too many args} { |
| 1061 |
namespace eval test_ns_1 { |
| 1062 |
list [catch {namespace children test_ns_2 xxx yyy} msg] $msg |
| 1063 |
} |
| 1064 |
} {1 {wrong # args: should be "namespace children ?name? ?pattern?"}} |
| 1065 |
test namespace-21.6 {NamespaceChildrenCmd, glob-style pattern given} { |
| 1066 |
namespace eval test_ns_1::test_ns_foo {} |
| 1067 |
namespace children test_ns_1 *f* |
| 1068 |
} {::test_ns_1::test_ns_foo} |
| 1069 |
test namespace-21.7 {NamespaceChildrenCmd, glob-style pattern given} -setup { |
| 1070 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1071 |
namespace eval test_ns_1::test_ns_2 {} |
| 1072 |
} -body { |
| 1073 |
namespace eval test_ns_1::test_ns_foo {} |
| 1074 |
lsort [namespace children test_ns_1 test*] |
| 1075 |
} -result {::test_ns_1::test_ns_2 ::test_ns_1::test_ns_foo} |
| 1076 |
test namespace-21.8 {NamespaceChildrenCmd, trivial pattern starting with ::} { |
| 1077 |
namespace eval test_ns_1 {} |
| 1078 |
namespace children [namespace current] [fq test_ns_1] |
| 1079 |
} [fq test_ns_1] |
| 1080 |
|
| 1081 |
test namespace-22.1 {NamespaceCodeCmd, bad args} { |
| 1082 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1083 |
list [catch {namespace code} msg] $msg \ |
| 1084 |
[catch {namespace code xxx yyy} msg] $msg |
| 1085 |
} {1 {wrong # args: should be "namespace code arg"} 1 {wrong # args: should be "namespace code arg"}} |
| 1086 |
test namespace-22.2 {NamespaceCodeCmd, arg is already scoped value} { |
| 1087 |
namespace eval test_ns_1 { |
| 1088 |
proc cmd {} {return "test_ns_1::cmd"} |
| 1089 |
} |
| 1090 |
namespace code {::namespace inscope ::test_ns_1 cmd} |
| 1091 |
} {::namespace inscope ::test_ns_1 cmd} |
| 1092 |
test namespace-22.3 {NamespaceCodeCmd, arg is already scoped value} { |
| 1093 |
namespace code {namespace inscope ::test_ns_1 cmd} |
| 1094 |
} {::namespace inscope :: {namespace inscope ::test_ns_1 cmd}} |
| 1095 |
test namespace-22.4 {NamespaceCodeCmd, in :: namespace} { |
| 1096 |
namespace code unknown |
| 1097 |
} {::namespace inscope :: unknown} |
| 1098 |
test namespace-22.5 {NamespaceCodeCmd, in other namespace} { |
| 1099 |
namespace eval test_ns_1 { |
| 1100 |
namespace code cmd |
| 1101 |
} |
| 1102 |
} {::namespace inscope ::test_ns_1 cmd} |
| 1103 |
test namespace-22.6 {NamespaceCodeCmd, in other namespace} { |
| 1104 |
namespace eval test_ns_1 { |
| 1105 |
variable v 42 |
| 1106 |
} |
| 1107 |
namespace eval test_ns_2 { |
| 1108 |
proc namespace args {} |
| 1109 |
} |
| 1110 |
namespace eval test_ns_2 [namespace eval test_ns_1 { |
| 1111 |
namespace code {set v} |
| 1112 |
}] |
| 1113 |
} {42} |
| 1114 |
test namespace-22.7 {NamespaceCodeCmd, Bug 3202171} { |
| 1115 |
namespace eval demo { |
| 1116 |
proc namespace args {puts $args} |
| 1117 |
::namespace code {namespace inscope foo} |
| 1118 |
} |
| 1119 |
} [list ::namespace inscope [fq demo] {namespace inscope foo}] |
| 1120 |
|
| 1121 |
test namespace-23.1 {NamespaceCurrentCmd, bad args} { |
| 1122 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1123 |
list [catch {namespace current xxx} msg] $msg \ |
| 1124 |
[catch {namespace current xxx yyy} msg] $msg |
| 1125 |
} {1 {wrong # args: should be "namespace current"} 1 {wrong # args: should be "namespace current"}} |
| 1126 |
test namespace-23.2 {NamespaceCurrentCmd, at global level} { |
| 1127 |
namespace current |
| 1128 |
} {::} |
| 1129 |
test namespace-23.3 {NamespaceCurrentCmd, in nested ns} { |
| 1130 |
namespace eval test_ns_1::test_ns_2 { |
| 1131 |
namespace current |
| 1132 |
} |
| 1133 |
} {::test_ns_1::test_ns_2} |
| 1134 |
|
| 1135 |
test namespace-24.1 {NamespaceDeleteCmd, no args} { |
| 1136 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1137 |
namespace delete |
| 1138 |
} {} |
| 1139 |
test namespace-24.2 {NamespaceDeleteCmd, one arg} { |
| 1140 |
namespace eval test_ns_1::test_ns_2 {} |
| 1141 |
namespace delete ::test_ns_1 |
| 1142 |
} {} |
| 1143 |
test namespace-24.3 {NamespaceDeleteCmd, two args} { |
| 1144 |
namespace eval test_ns_1::test_ns_2 {} |
| 1145 |
list [namespace delete ::test_ns_1::test_ns_2] [namespace delete ::test_ns_1] |
| 1146 |
} {{} {}} |
| 1147 |
test namespace-24.4 {NamespaceDeleteCmd, unknown ns} { |
| 1148 |
list [catch {namespace delete ::test_ns_foo} msg] $msg |
| 1149 |
} {1 {unknown namespace "::test_ns_foo" in namespace delete command}} |
| 1150 |
|
| 1151 |
test namespace-25.1 {NamespaceEvalCmd, bad args} { |
| 1152 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1153 |
list [catch {namespace eval} msg] $msg |
| 1154 |
} {1 {wrong # args: should be "namespace eval name arg ?arg...?"}} |
| 1155 |
test namespace-25.2 {NamespaceEvalCmd, bad args} -body { |
| 1156 |
namespace test_ns_1 |
| 1157 |
} -returnCodes error -match glob -result {unknown or ambiguous subcommand "test_ns_1": must be *} |
| 1158 |
catch {unset v} |
| 1159 |
test namespace-25.3 {NamespaceEvalCmd, new namespace} { |
| 1160 |
set v 123 |
| 1161 |
namespace eval test_ns_1 { |
| 1162 |
variable v 314159 |
| 1163 |
proc p {} { |
| 1164 |
variable v |
| 1165 |
return $v |
| 1166 |
} |
| 1167 |
} |
| 1168 |
test_ns_1::p |
| 1169 |
} {314159} |
| 1170 |
test namespace-25.4 {NamespaceEvalCmd, existing namespace} -setup { |
| 1171 |
namespace eval test_ns_1 { |
| 1172 |
variable v 314159 |
| 1173 |
proc p {} { |
| 1174 |
variable v |
| 1175 |
return $v |
| 1176 |
} |
| 1177 |
} |
| 1178 |
} -body { |
| 1179 |
namespace eval test_ns_1 { |
| 1180 |
proc q {} {return [expr {[p]+1}]} |
| 1181 |
} |
| 1182 |
test_ns_1::q |
| 1183 |
} -result {314160} |
| 1184 |
test namespace-25.5 {NamespaceEvalCmd, multiple args} -setup { |
| 1185 |
namespace eval test_ns_1 {variable v 314159} |
| 1186 |
} -body { |
| 1187 |
namespace eval test_ns_1 "set" "v" |
| 1188 |
} -result {314159} |
| 1189 |
test namespace-25.6 {NamespaceEvalCmd, error in eval'd script} { |
| 1190 |
list [catch {namespace eval test_ns_1 {xxxx}} msg] $msg $::errorInfo |
| 1191 |
} {1 {invalid command name "xxxx"} {invalid command name "xxxx" |
| 1192 |
while executing |
| 1193 |
"xxxx" |
| 1194 |
(in namespace eval "::test_ns_1" script line 1) |
| 1195 |
invoked from within |
| 1196 |
"namespace eval test_ns_1 {xxxx}"}} |
| 1197 |
test namespace-25.7 {NamespaceEvalCmd, error in eval'd script} { |
| 1198 |
list [catch {namespace eval test_ns_1 {error foo bar baz}} msg] $msg $::errorInfo |
| 1199 |
} {1 foo {bar |
| 1200 |
(in namespace eval "::test_ns_1" script line 1) |
| 1201 |
invoked from within |
| 1202 |
"namespace eval test_ns_1 {error foo bar baz}"}} |
| 1203 |
test namespace-25.8 {NamespaceEvalCmd, error in eval'd script} { |
| 1204 |
list [catch {namespace eval test_ns_1 error foo bar baz} msg] $msg $::errorInfo |
| 1205 |
} {1 foo {bar |
| 1206 |
(in namespace eval "::test_ns_1" script line 1) |
| 1207 |
invoked from within |
| 1208 |
"namespace eval test_ns_1 error foo bar baz"}} |
| 1209 |
catch {unset v} |
| 1210 |
test namespace-25.9 {NamespaceEvalCmd, 545325} { |
| 1211 |
namespace eval test_ns_1 info level 0 |
| 1212 |
} {namespace eval test_ns_1 info level 0} |
| 1213 |
|
| 1214 |
test namespace-26.1 {NamespaceExportCmd, no args and new ns} { |
| 1215 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1216 |
namespace export |
| 1217 |
} {} |
| 1218 |
test namespace-26.2 {NamespaceExportCmd, just -clear arg} { |
| 1219 |
namespace export -clear |
| 1220 |
} {} |
| 1221 |
test namespace-26.3 {NamespaceExportCmd, pattern can't specify a namespace} { |
| 1222 |
namespace eval test_ns_1 { |
| 1223 |
list [catch {namespace export ::zzz} msg] $msg |
| 1224 |
} |
| 1225 |
} {1 {invalid export pattern "::zzz": pattern can't specify a namespace}} |
| 1226 |
test namespace-26.4 {NamespaceExportCmd, one pattern} { |
| 1227 |
namespace eval test_ns_1 { |
| 1228 |
namespace export cmd1 |
| 1229 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1230 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1231 |
proc cmd3 {args} {return "cmd3: $args"} |
| 1232 |
proc cmd4 {args} {return "cmd4: $args"} |
| 1233 |
} |
| 1234 |
namespace eval test_ns_2 { |
| 1235 |
namespace import ::test_ns_1::* |
| 1236 |
} |
| 1237 |
list [info commands test_ns_2::*] [test_ns_2::cmd1 hello] |
| 1238 |
} {::test_ns_2::cmd1 {cmd1: hello}} |
| 1239 |
test namespace-26.5 {NamespaceExportCmd, sequence of patterns, patterns accumulate} -setup { |
| 1240 |
catch {namespace delete {*}[namespace children test_ns_*]} |
| 1241 |
namespace eval test_ns_1 { |
| 1242 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1243 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1244 |
proc cmd3 {args} {return "cmd3: $args"} |
| 1245 |
proc cmd4 {args} {return "cmd4: $args"} |
| 1246 |
namespace export cmd1 cmd3 |
| 1247 |
} |
| 1248 |
} -body { |
| 1249 |
namespace eval test_ns_2 { |
| 1250 |
namespace import -force ::test_ns_1::* |
| 1251 |
} |
| 1252 |
list [lsort [info commands test_ns_2::*]] [test_ns_2::cmd3 hello] |
| 1253 |
} -result {{::test_ns_2::cmd1 ::test_ns_2::cmd3} {cmd3: hello}} |
| 1254 |
test namespace-26.6 {NamespaceExportCmd, no patterns means return uniq'ed export list} -setup { |
| 1255 |
catch {namespace delete {*}[namespace children test_ns_*]} |
| 1256 |
namespace eval test_ns_1 { |
| 1257 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1258 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1259 |
proc cmd3 {args} {return "cmd3: $args"} |
| 1260 |
proc cmd4 {args} {return "cmd4: $args"} |
| 1261 |
namespace export cmd1 cmd3 |
| 1262 |
} |
| 1263 |
} -body { |
| 1264 |
namespace eval test_ns_1 { |
| 1265 |
namespace export |
| 1266 |
} |
| 1267 |
} -result {cmd1 cmd3} |
| 1268 |
test namespace-26.7 {NamespaceExportCmd, -clear resets export list} -setup { |
| 1269 |
catch {namespace delete {*}[namespace children test_ns_*]} |
| 1270 |
namespace eval test_ns_1 { |
| 1271 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1272 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1273 |
proc cmd3 {args} {return "cmd3: $args"} |
| 1274 |
proc cmd4 {args} {return "cmd4: $args"} |
| 1275 |
} |
| 1276 |
} -body { |
| 1277 |
namespace eval test_ns_1 { |
| 1278 |
namespace export cmd1 cmd3 |
| 1279 |
} |
| 1280 |
namespace eval test_ns_2 { |
| 1281 |
namespace import ::test_ns_1::* |
| 1282 |
} |
| 1283 |
namespace eval test_ns_1 { |
| 1284 |
namespace export -clear cmd4 |
| 1285 |
} |
| 1286 |
namespace eval test_ns_2 { |
| 1287 |
namespace import ::test_ns_1::* |
| 1288 |
} |
| 1289 |
list [lsort [info commands test_ns_2::*]] [test_ns_2::cmd4 hello] |
| 1290 |
} -result [list [lsort {::test_ns_2::cmd4 ::test_ns_2::cmd1 ::test_ns_2::cmd3}] {cmd4: hello}] |
| 1291 |
test namespace-26.8 {NamespaceExportCmd, -clear resets export list} { |
| 1292 |
catch {namespace delete foo} |
| 1293 |
namespace eval foo { |
| 1294 |
namespace export x |
| 1295 |
namespace export -clear |
| 1296 |
} |
| 1297 |
list [namespace eval foo namespace export] [namespace delete foo] |
| 1298 |
} {{} {}} |
| 1299 |
|
| 1300 |
test namespace-27.1 {NamespaceForgetCmd, no args} { |
| 1301 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1302 |
namespace forget |
| 1303 |
} {} |
| 1304 |
test namespace-27.2 {NamespaceForgetCmd, args must be valid namespaces} { |
| 1305 |
list [catch {namespace forget ::test_ns_1::xxx} msg] $msg |
| 1306 |
} {1 {unknown namespace in namespace forget pattern "::test_ns_1::xxx"}} |
| 1307 |
test namespace-27.3 {NamespaceForgetCmd, arg is forgotten} { |
| 1308 |
namespace eval test_ns_1 { |
| 1309 |
namespace export cmd* |
| 1310 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1311 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1312 |
} |
| 1313 |
namespace eval test_ns_2 { |
| 1314 |
namespace import ::test_ns_1::* |
| 1315 |
namespace forget ::test_ns_1::cmd1 |
| 1316 |
} |
| 1317 |
info commands ::test_ns_2::* |
| 1318 |
} {::test_ns_2::cmd2} |
| 1319 |
|
| 1320 |
test namespace-28.1 {NamespaceImportCmd, no args} -setup { |
| 1321 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1322 |
} -body { |
| 1323 |
namespace eval ::test_ns_1 { |
| 1324 |
proc foo {} {} |
| 1325 |
proc bar {} {} |
| 1326 |
proc boo {} {} |
| 1327 |
proc glorp {} {} |
| 1328 |
namespace export foo b* |
| 1329 |
} |
| 1330 |
namespace eval ::test_ns_2 { |
| 1331 |
namespace import ::test_ns_1::* |
| 1332 |
lsort [namespace import] |
| 1333 |
} |
| 1334 |
} -cleanup { |
| 1335 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1336 |
} -result {bar boo foo} |
| 1337 |
test namespace-28.2 {NamespaceImportCmd, no args and just "-force"} { |
| 1338 |
namespace import -force |
| 1339 |
} {} |
| 1340 |
test namespace-28.3 {NamespaceImportCmd, arg is imported} { |
| 1341 |
namespace eval test_ns_1 { |
| 1342 |
namespace export cmd2 |
| 1343 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1344 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1345 |
} |
| 1346 |
namespace eval test_ns_2 { |
| 1347 |
namespace import ::test_ns_1::* |
| 1348 |
namespace forget ::test_ns_1::cmd1 |
| 1349 |
} |
| 1350 |
info commands test_ns_2::* |
| 1351 |
} {::test_ns_2::cmd2} |
| 1352 |
|
| 1353 |
test namespace-29.1 {NamespaceInscopeCmd, bad args} { |
| 1354 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1355 |
list [catch {namespace inscope} msg] $msg |
| 1356 |
} {1 {wrong # args: should be "namespace inscope name arg ?arg...?"}} |
| 1357 |
test namespace-29.2 {NamespaceInscopeCmd, bad args} { |
| 1358 |
list [catch {namespace inscope ::} msg] $msg |
| 1359 |
} {1 {wrong # args: should be "namespace inscope name arg ?arg...?"}} |
| 1360 |
test namespace-29.3 {NamespaceInscopeCmd, specified ns must exist} -body { |
| 1361 |
namespace inscope test_ns_1 {set v} |
| 1362 |
} -returnCodes error -result {namespace "test_ns_1" not found in "::"} |
| 1363 |
test namespace-29.4 {NamespaceInscopeCmd, simple case} { |
| 1364 |
namespace eval test_ns_1 { |
| 1365 |
variable v 747 |
| 1366 |
proc cmd {args} { |
| 1367 |
variable v |
| 1368 |
return "[namespace current]::cmd: v=$v, args=$args" |
| 1369 |
} |
| 1370 |
} |
| 1371 |
namespace inscope test_ns_1 cmd |
| 1372 |
} {::test_ns_1::cmd: v=747, args=} |
| 1373 |
test namespace-29.5 {NamespaceInscopeCmd, has lappend semantics} -setup { |
| 1374 |
namespace eval test_ns_1 { |
| 1375 |
variable v 747 |
| 1376 |
proc cmd {args} { |
| 1377 |
variable v |
| 1378 |
return "[namespace current]::cmd: v=$v, args=$args" |
| 1379 |
} |
| 1380 |
} |
| 1381 |
} -body { |
| 1382 |
list [namespace inscope test_ns_1 cmd x y z] \ |
| 1383 |
[namespace eval test_ns_1 [concat cmd [list x y z]]] |
| 1384 |
} -result {{::test_ns_1::cmd: v=747, args=x y z} {::test_ns_1::cmd: v=747, args=x y z}} |
| 1385 |
test namespace-29.6 {NamespaceInscopeCmd, 1400572} -setup { |
| 1386 |
namespace eval test_ns_1 {} |
| 1387 |
} -body { |
| 1388 |
namespace inscope test_ns_1 {info level 0} |
| 1389 |
} -result {namespace inscope test_ns_1 {info level 0}} |
| 1390 |
|
| 1391 |
test namespace-30.1 {NamespaceOriginCmd, bad args} { |
| 1392 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1393 |
list [catch {namespace origin} msg] $msg |
| 1394 |
} {1 {wrong # args: should be "namespace origin name"}} |
| 1395 |
test namespace-30.2 {NamespaceOriginCmd, bad args} { |
| 1396 |
list [catch {namespace origin x y} msg] $msg |
| 1397 |
} {1 {wrong # args: should be "namespace origin name"}} |
| 1398 |
test namespace-30.3 {NamespaceOriginCmd, command not found} { |
| 1399 |
list [catch {namespace origin fred} msg] $msg |
| 1400 |
} {1 {invalid command name "fred"}} |
| 1401 |
test namespace-30.4 {NamespaceOriginCmd, command isn't imported} { |
| 1402 |
namespace origin set |
| 1403 |
} {::set} |
| 1404 |
test namespace-30.5 {NamespaceOriginCmd, imported command} { |
| 1405 |
namespace eval test_ns_1 { |
| 1406 |
namespace export cmd* |
| 1407 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1408 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1409 |
} |
| 1410 |
namespace eval test_ns_2 { |
| 1411 |
namespace export * |
| 1412 |
namespace import ::test_ns_1::* |
| 1413 |
proc p {} {} |
| 1414 |
} |
| 1415 |
namespace eval test_ns_3 { |
| 1416 |
namespace import ::test_ns_2::* |
| 1417 |
list [namespace origin foreach] \ |
| 1418 |
[namespace origin p] \ |
| 1419 |
[namespace origin cmd1] \ |
| 1420 |
[namespace origin ::test_ns_2::cmd2] |
| 1421 |
} |
| 1422 |
} {::foreach ::test_ns_2::p ::test_ns_1::cmd1 ::test_ns_1::cmd2} |
| 1423 |
|
| 1424 |
test namespace-31.1 {NamespaceParentCmd, bad args} { |
| 1425 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1426 |
list [catch {namespace parent a b} msg] $msg |
| 1427 |
} {1 {wrong # args: should be "namespace parent ?name?"}} |
| 1428 |
test namespace-31.2 {NamespaceParentCmd, no args} { |
| 1429 |
namespace parent |
| 1430 |
} {} |
| 1431 |
test namespace-31.3 {NamespaceParentCmd, namespace specified} { |
| 1432 |
namespace eval test_ns_1 { |
| 1433 |
namespace eval test_ns_2 { |
| 1434 |
namespace eval test_ns_3 {} |
| 1435 |
} |
| 1436 |
} |
| 1437 |
list [namespace parent ::] \ |
| 1438 |
[namespace parent test_ns_1::test_ns_2] \ |
| 1439 |
[namespace eval test_ns_1::test_ns_2::test_ns_3 {namespace parent ::test_ns_1::test_ns_2}] |
| 1440 |
} {{} ::test_ns_1 ::test_ns_1} |
| 1441 |
test namespace-31.4 {NamespaceParentCmd, bad namespace specified} -body { |
| 1442 |
namespace parent test_ns_1::test_ns_foo |
| 1443 |
} -returnCodes error -result {namespace "test_ns_1::test_ns_foo" not found in "::"} |
| 1444 |
|
| 1445 |
test namespace-32.1 {NamespaceQualifiersCmd, bad args} { |
| 1446 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1447 |
list [catch {namespace qualifiers} msg] $msg |
| 1448 |
} {1 {wrong # args: should be "namespace qualifiers string"}} |
| 1449 |
test namespace-32.2 {NamespaceQualifiersCmd, bad args} { |
| 1450 |
list [catch {namespace qualifiers x y} msg] $msg |
| 1451 |
} {1 {wrong # args: should be "namespace qualifiers string"}} |
| 1452 |
test namespace-32.3 {NamespaceQualifiersCmd, simple name} { |
| 1453 |
namespace qualifiers foo |
| 1454 |
} {} |
| 1455 |
test namespace-32.4 {NamespaceQualifiersCmd, leading ::} { |
| 1456 |
namespace qualifiers ::x::y::z |
| 1457 |
} {::x::y} |
| 1458 |
test namespace-32.5 {NamespaceQualifiersCmd, no leading ::} { |
| 1459 |
namespace qualifiers a::b |
| 1460 |
} {a} |
| 1461 |
test namespace-32.6 {NamespaceQualifiersCmd, :: argument} { |
| 1462 |
namespace qualifiers :: |
| 1463 |
} {} |
| 1464 |
test namespace-32.7 {NamespaceQualifiersCmd, odd number of :s} { |
| 1465 |
namespace qualifiers ::::: |
| 1466 |
} {} |
| 1467 |
test namespace-32.8 {NamespaceQualifiersCmd, odd number of :s} { |
| 1468 |
namespace qualifiers foo::: |
| 1469 |
} {foo} |
| 1470 |
|
| 1471 |
test namespace-33.1 {NamespaceTailCmd, bad args} { |
| 1472 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1473 |
list [catch {namespace tail} msg] $msg |
| 1474 |
} {1 {wrong # args: should be "namespace tail string"}} |
| 1475 |
test namespace-33.2 {NamespaceTailCmd, bad args} { |
| 1476 |
list [catch {namespace tail x y} msg] $msg |
| 1477 |
} {1 {wrong # args: should be "namespace tail string"}} |
| 1478 |
test namespace-33.3 {NamespaceTailCmd, simple name} { |
| 1479 |
namespace tail foo |
| 1480 |
} {foo} |
| 1481 |
test namespace-33.4 {NamespaceTailCmd, leading ::} { |
| 1482 |
namespace tail ::x::y::z |
| 1483 |
} {z} |
| 1484 |
test namespace-33.5 {NamespaceTailCmd, no leading ::} { |
| 1485 |
namespace tail a::b |
| 1486 |
} {b} |
| 1487 |
test namespace-33.6 {NamespaceTailCmd, :: argument} { |
| 1488 |
namespace tail :: |
| 1489 |
} {} |
| 1490 |
test namespace-33.7 {NamespaceTailCmd, odd number of :s} { |
| 1491 |
namespace tail ::::: |
| 1492 |
} {} |
| 1493 |
test namespace-33.8 {NamespaceTailCmd, odd number of :s} { |
| 1494 |
namespace tail foo::: |
| 1495 |
} {} |
| 1496 |
|
| 1497 |
test namespace-34.1 {NamespaceWhichCmd, bad args} { |
| 1498 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1499 |
list [catch {namespace which} msg] $msg |
| 1500 |
} {1 {wrong # args: should be "namespace which ?-command? ?-variable? name"}} |
| 1501 |
test namespace-34.2 {NamespaceWhichCmd, bad args} { |
| 1502 |
list [catch {namespace which -fred x} msg] $msg |
| 1503 |
} {1 {wrong # args: should be "namespace which ?-command? ?-variable? name"}} |
| 1504 |
test namespace-34.3 {NamespaceWhichCmd, single arg is always command name} { |
| 1505 |
namespace which -command |
| 1506 |
} {} |
| 1507 |
test namespace-34.4 {NamespaceWhichCmd, bad args} { |
| 1508 |
list [catch {namespace which a b} msg] $msg |
| 1509 |
} {1 {wrong # args: should be "namespace which ?-command? ?-variable? name"}} |
| 1510 |
test namespace-34.5 {NamespaceWhichCmd, command lookup} -setup { |
| 1511 |
catch {namespace delete {*}[namespace children test_ns_*]} |
| 1512 |
namespace eval test_ns_1 { |
| 1513 |
namespace export cmd* |
| 1514 |
variable v1 111 |
| 1515 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1516 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1517 |
} |
| 1518 |
namespace eval test_ns_2 { |
| 1519 |
namespace export * |
| 1520 |
namespace import ::test_ns_1::* |
| 1521 |
variable v2 222 |
| 1522 |
proc p {} {} |
| 1523 |
} |
| 1524 |
} -body { |
| 1525 |
namespace eval test_ns_3 { |
| 1526 |
namespace import ::test_ns_2::* |
| 1527 |
variable v3 333 |
| 1528 |
list [namespace which -command foreach] \ |
| 1529 |
[namespace which -command p] \ |
| 1530 |
[namespace which -command cmd1] \ |
| 1531 |
[namespace which -command ::test_ns_2::cmd2] \ |
| 1532 |
[catch {namespace which -command ::test_ns_2::noSuchCmd} msg] $msg |
| 1533 |
} |
| 1534 |
} -result {::foreach ::test_ns_3::p ::test_ns_3::cmd1 ::test_ns_2::cmd2 0 {}} |
| 1535 |
test namespace-34.6 {NamespaceWhichCmd, -command is default} -setup { |
| 1536 |
catch {namespace delete {*}[namespace children test_ns_*]} |
| 1537 |
namespace eval test_ns_1 { |
| 1538 |
namespace export cmd* |
| 1539 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1540 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1541 |
} |
| 1542 |
namespace eval test_ns_2 { |
| 1543 |
namespace export * |
| 1544 |
namespace import ::test_ns_1::* |
| 1545 |
proc p {} {} |
| 1546 |
} |
| 1547 |
namespace eval test_ns_3 { |
| 1548 |
namespace import ::test_ns_2::* |
| 1549 |
} |
| 1550 |
} -body { |
| 1551 |
namespace eval test_ns_3 { |
| 1552 |
list [namespace which foreach] \ |
| 1553 |
[namespace which p] \ |
| 1554 |
[namespace which cmd1] \ |
| 1555 |
[namespace which ::test_ns_2::cmd2] |
| 1556 |
} |
| 1557 |
} -result {::foreach ::test_ns_3::p ::test_ns_3::cmd1 ::test_ns_2::cmd2} |
| 1558 |
test namespace-34.7 {NamespaceWhichCmd, variable lookup} -setup { |
| 1559 |
catch {namespace delete {*}[namespace children test_ns_*]} |
| 1560 |
namespace eval test_ns_1 { |
| 1561 |
namespace export cmd* |
| 1562 |
proc cmd1 {args} {return "cmd1: $args"} |
| 1563 |
proc cmd2 {args} {return "cmd2: $args"} |
| 1564 |
} |
| 1565 |
namespace eval test_ns_2 { |
| 1566 |
namespace export * |
| 1567 |
namespace import ::test_ns_1::* |
| 1568 |
variable v2 222 |
| 1569 |
proc p {} {} |
| 1570 |
} |
| 1571 |
namespace eval test_ns_3 { |
| 1572 |
variable v3 333 |
| 1573 |
namespace import ::test_ns_2::* |
| 1574 |
} |
| 1575 |
} -body { |
| 1576 |
namespace eval test_ns_3 { |
| 1577 |
list [namespace which -variable env] \ |
| 1578 |
[namespace which -variable v3] \ |
| 1579 |
[namespace which -variable ::test_ns_2::v2] \ |
| 1580 |
[catch {namespace which -variable ::test_ns_2::noSuchVar} msg] $msg |
| 1581 |
} |
| 1582 |
} -result {::env ::test_ns_3::v3 ::test_ns_2::v2 0 {}} |
| 1583 |
|
| 1584 |
test namespace-35.1 {FreeNsNameInternalRep, resulting ref count > 0} -setup { |
| 1585 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1586 |
} -body { |
| 1587 |
namespace eval test_ns_1 { |
| 1588 |
proc p {} { |
| 1589 |
namespace delete [namespace current] |
| 1590 |
return [namespace current] |
| 1591 |
} |
| 1592 |
} |
| 1593 |
test_ns_1::p |
| 1594 |
} -result {::test_ns_1} |
| 1595 |
test namespace-35.2 {FreeNsNameInternalRep, resulting ref count == 0} { |
| 1596 |
namespace eval test_ns_1 { |
| 1597 |
proc q {} { |
| 1598 |
return [namespace current] |
| 1599 |
} |
| 1600 |
} |
| 1601 |
list [test_ns_1::q] \ |
| 1602 |
[namespace delete test_ns_1] \ |
| 1603 |
[catch {test_ns_1::q} msg] $msg |
| 1604 |
} {::test_ns_1 {} 1 {invalid command name "test_ns_1::q"}} |
| 1605 |
|
| 1606 |
catch {unset x} |
| 1607 |
catch {unset y} |
| 1608 |
test namespace-36.1 {DupNsNameInternalRep} { |
| 1609 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1610 |
namespace eval test_ns_1 {} |
| 1611 |
set x "::test_ns_1" |
| 1612 |
list [namespace parent $x] [set y $x] [namespace parent $y] |
| 1613 |
} {:: ::test_ns_1 ::} |
| 1614 |
catch {unset x} |
| 1615 |
catch {unset y} |
| 1616 |
|
| 1617 |
test namespace-37.1 {SetNsNameFromAny, ns name found} { |
| 1618 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1619 |
namespace eval test_ns_1::test_ns_2 {} |
| 1620 |
namespace eval test_ns_1 { |
| 1621 |
namespace children ::test_ns_1 |
| 1622 |
} |
| 1623 |
} {::test_ns_1::test_ns_2} |
| 1624 |
test namespace-37.2 {SetNsNameFromAny, ns name not found} -body { |
| 1625 |
namespace eval test_ns_1 { |
| 1626 |
namespace children ::test_ns_1::test_ns_foo |
| 1627 |
} |
| 1628 |
} -returnCodes error -result {namespace "::test_ns_1::test_ns_foo" not found} |
| 1629 |
|
| 1630 |
test namespace-38.1 {UpdateStringOfNsName} { |
| 1631 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1632 |
;# Tcl_NamespaceObjCmd calls UpdateStringOfNsName to get subcmd name |
| 1633 |
list [namespace eval {} {namespace current}] \ |
| 1634 |
[namespace eval {} {namespace current}] |
| 1635 |
} {:: ::} |
| 1636 |
|
| 1637 |
test namespace-39.1 {NamespaceExistsCmd} { |
| 1638 |
catch {namespace delete {*}[namespace children :: test_ns_*]} |
| 1639 |
namespace eval ::test_ns_z::test_me { variable foo } |
| 1640 |
list [namespace exists ::] \ |
| 1641 |
[namespace exists ::bogus_namespace] \ |
| 1642 |
[namespace exists ::test_ns_z] \ |
| 1643 |
[namespace exists test_ns_z] \ |
| 1644 |
[namespace exists ::test_ns_z::foo] \ |
| 1645 |
[namespace exists ::test_ns_z::test_me] \ |
| 1646 |
[namespace eval ::test_ns_z { namespace exists ::test_me }] \ |
| 1647 |
[namespace eval ::test_ns_z { namespace exists test_me }] \ |
| 1648 |
[namespace exists :::::test_ns_z] |
| 1649 |
} {1 0 1 1 0 1 0 1 1} |
| 1650 |
test namespace-39.2 {NamespaceExistsCmd error} { |
| 1651 |
list [catch {namespace exists} msg] $msg |
| 1652 |
} {1 {wrong # args: should be "namespace exists name"}} |
| 1653 |
test namespace-39.3 {NamespaceExistsCmd error} { |
| 1654 |
list [catch {namespace exists a b} msg] $msg |
| 1655 |
} {1 {wrong # args: should be "namespace exists name"}} |
| 1656 |
|
| 1657 |
test namespace-40.1 {Ignoring namespace proc "unknown"} -setup { |
| 1658 |
rename unknown _unknown |
| 1659 |
} -body { |
| 1660 |
proc unknown args {return global} |
| 1661 |
namespace eval ns {proc unknown args {return local}} |
| 1662 |
list [namespace eval ns aaa bbb] [namespace eval ns aaa] |
| 1663 |
} -cleanup { |
| 1664 |
rename unknown {} |
| 1665 |
rename _unknown unknown |
| 1666 |
namespace delete ns |
| 1667 |
} -result {global global} |
| 1668 |
|
| 1669 |
test namespace-41.1 {Shadowing byte-compiled commands, Bug: 231259} { |
| 1670 |
set res {} |
| 1671 |
namespace eval ns { |
| 1672 |
set res {} |
| 1673 |
proc test {} { |
| 1674 |
set ::g 0 |
| 1675 |
} |
| 1676 |
lappend ::res [test] |
| 1677 |
proc set {a b} { |
| 1678 |
::set a [incr b] |
| 1679 |
} |
| 1680 |
lappend ::res [test] |
| 1681 |
} |
| 1682 |
namespace delete ns |
| 1683 |
set res |
| 1684 |
} {0 1} |
| 1685 |
test namespace-41.2 {Shadowing byte-compiled commands, Bug: 231259} { |
| 1686 |
set res {} |
| 1687 |
namespace eval ns {} |
| 1688 |
proc ns::a {i} { |
| 1689 |
variable b |
| 1690 |
proc set args {return "New proc is called"} |
| 1691 |
return [set b $i] |
| 1692 |
} |
| 1693 |
ns::a 1 |
| 1694 |
set res [ns::a 2] |
| 1695 |
namespace delete ns |
| 1696 |
set res |
| 1697 |
} {New proc is called} |
| 1698 |
test namespace-41.3 {Shadowing byte-compiled commands, Bugs: 231259, 729692} { |
| 1699 |
set res {} |
| 1700 |
namespace eval ns { |
| 1701 |
variable b 0 |
| 1702 |
} |
| 1703 |
proc ns::a {i} { |
| 1704 |
variable b |
| 1705 |
proc set args {return "New proc is called"} |
| 1706 |
return [set b $i] |
| 1707 |
} |
| 1708 |
set res [list [ns::a 1] $ns::b] |
| 1709 |
namespace delete ns |
| 1710 |
set res |
| 1711 |
} {{New proc is called} 0} |
| 1712 |
|
| 1713 |
# Ensembles (TIP#112) |
| 1714 |
|
| 1715 |
test namespace-42.1 {ensembles: basic} { |
| 1716 |
namespace eval ns { |
| 1717 |
namespace export x |
| 1718 |
proc x {} {format 1} |
| 1719 |
namespace ensemble create |
| 1720 |
} |
| 1721 |
list [info command ns] [ns x] [namespace delete ns] [info command ns] |
| 1722 |
} {ns 1 {} {}} |
| 1723 |
test namespace-42.2 {ensembles: basic} { |
| 1724 |
namespace eval ns { |
| 1725 |
namespace export x |
| 1726 |
proc x {} {format 1} |
| 1727 |
namespace ensemble create |
| 1728 |
} |
| 1729 |
rename ns foo |
| 1730 |
list [info command foo] [foo x] [namespace delete ns] [info command foo] |
| 1731 |
} {foo 1 {} {}} |
| 1732 |
test namespace-42.3 {ensembles: basic} { |
| 1733 |
namespace eval ns { |
| 1734 |
namespace export x* |
| 1735 |
proc x1 {} {format 1} |
| 1736 |
proc x2 {} {format 2} |
| 1737 |
namespace ensemble create |
| 1738 |
} |
| 1739 |
set result [list [ns x1] [ns x2]] |
| 1740 |
lappend result [catch {ns x} msg] $msg |
| 1741 |
rename ns {} |
| 1742 |
lappend result [info command ns::x1] |
| 1743 |
namespace delete ns |
| 1744 |
lappend result [info command ns::x1] |
| 1745 |
} {1 2 1 {unknown or ambiguous subcommand "x": must be x1, or x2} ::ns::x1 {}} |
| 1746 |
test namespace-42.4 {ensembles: basic} -body { |
| 1747 |
namespace eval ns { |
| 1748 |
namespace export y* |
| 1749 |
proc x1 {} {format 1} |
| 1750 |
proc x2 {} {format 2} |
| 1751 |
namespace ensemble create |
| 1752 |
} |
| 1753 |
list [catch {ns x} msg] $msg |
| 1754 |
} -cleanup { |
| 1755 |
namespace delete ns |
| 1756 |
} -result {1 {unknown subcommand "x": namespace ::ns does not export any commands}} |
| 1757 |
test namespace-42.5 {ensembles: basic} -body { |
| 1758 |
namespace eval ns { |
| 1759 |
namespace export x* |
| 1760 |
proc x1 {} {format 1} |
| 1761 |
proc x2 {} {format 2} |
| 1762 |
proc x3 {} {format 3} |
| 1763 |
namespace ensemble create |
| 1764 |
} |
| 1765 |
list [catch {ns x} msg] $msg |
| 1766 |
} -cleanup { |
| 1767 |
namespace delete ns |
| 1768 |
} -result {1 {unknown or ambiguous subcommand "x": must be x1, x2, or x3}} |
| 1769 |
test namespace-42.6 {ensembles: nested} -body { |
| 1770 |
namespace eval ns { |
| 1771 |
namespace export x* |
| 1772 |
namespace eval x0 { |
| 1773 |
proc z {} {format 0} |
| 1774 |
namespace export z |
| 1775 |
namespace ensemble create |
| 1776 |
} |
| 1777 |
proc x1 {} {format 1} |
| 1778 |
proc x2 {} {format 2} |
| 1779 |
proc x3 {} {format 3} |
| 1780 |
namespace ensemble create |
| 1781 |
} |
| 1782 |
list [ns x0 z] [ns x1] [ns x2] [ns x3] |
| 1783 |
} -cleanup { |
| 1784 |
namespace delete ns |
| 1785 |
} -result {0 1 2 3} |
| 1786 |
test namespace-42.7 {ensembles: nested} -body { |
| 1787 |
namespace eval ns { |
| 1788 |
namespace export x* |
| 1789 |
namespace eval x0 { |
| 1790 |
proc z {} {list [info level] [info level 1]} |
| 1791 |
namespace export z |
| 1792 |
namespace ensemble create |
| 1793 |
} |
| 1794 |
proc x1 {} {format 1} |
| 1795 |
proc x2 {} {format 2} |
| 1796 |
proc x3 {} {format 3} |
| 1797 |
namespace ensemble create |
| 1798 |
} |
| 1799 |
list [ns x0 z] [ns x1] [ns x2] [ns x3] |
| 1800 |
} -cleanup { |
| 1801 |
namespace delete ns |
| 1802 |
} -result {{1 ::ns::x0::z} 1 2 3} |
| 1803 |
test namespace-42.8 { |
| 1804 |
ensembles: [Bug 1670091], panic due to pointer to a deallocated List |
| 1805 |
struct. |
| 1806 |
} -setup { |
| 1807 |
proc demo args {} |
| 1808 |
variable target [list [namespace which demo] x] |
| 1809 |
proc trial args {variable target; string length $target} |
| 1810 |
trace add execution demo enter [namespace code trial] |
| 1811 |
namespace ensemble create -command foo -map [list bar $target] |
| 1812 |
} -body { |
| 1813 |
foo bar |
| 1814 |
} -cleanup { |
| 1815 |
unset target |
| 1816 |
rename demo {} |
| 1817 |
rename trial {} |
| 1818 |
rename foo {} |
| 1819 |
} -result {} |
| 1820 |
|
| 1821 |
test namespace-42.9 { |
| 1822 |
ensembles: [Bug 4f6a1ebd64], segmentation fault due to pointer to a |
| 1823 |
deallocated List struct. |
| 1824 |
} -setup { |
| 1825 |
namespace eval n {namespace ensemble create} |
| 1826 |
set lst [dict create one ::two] |
| 1827 |
namespace ensemble configure n -subcommands $lst -map $lst |
| 1828 |
} -body { |
| 1829 |
n one |
| 1830 |
} -cleanup { |
| 1831 |
namespace delete n |
| 1832 |
unset -nocomplain lst |
| 1833 |
} -returnCodes error -match glob -result {invalid command name*} |
| 1834 |
|
| 1835 |
test namespace-42.10 { |
| 1836 |
ensembles: [Bug 4f6a1ebd64] segmentation fault due to pointer to a |
| 1837 |
deallocated List struct (this time with duplicate of one in "dict"). |
| 1838 |
} -setup { |
| 1839 |
namespace eval n {namespace ensemble create} |
| 1840 |
set lst [list one ::two one ::three] |
| 1841 |
namespace ensemble configure n -subcommands $lst -map $lst |
| 1842 |
} -body { |
| 1843 |
n one |
| 1844 |
} -cleanup { |
| 1845 |
namespace delete n |
| 1846 |
unset -nocomplain lst |
| 1847 |
} -returnCodes error -match glob -result {invalid command name *three*} |
| 1848 |
|
| 1849 |
|
| 1850 |
test namespace-42.11 { |
| 1851 |
ensembles: prefix matching segmentation fault |
| 1852 |
|
| 1853 |
issue ccc448a6bfd59cbd |
| 1854 |
} -body { |
| 1855 |
namespace eval n1 { |
| 1856 |
namespace ensemble create |
| 1857 |
namespace export * |
| 1858 |
proc p1 args {error success} |
| 1859 |
} |
| 1860 |
# segmentation fault only occurs in the non-byte-compiled path, so avoid |
| 1861 |
# byte compilation |
| 1862 |
set cmd {namespace eva n1 {[namespace parent]::n1 p1}} |
| 1863 |
{*}$cmd |
| 1864 |
} -returnCodes error -result success |
| 1865 |
|
| 1866 |
|
| 1867 |
test namespace-43.1 {ensembles: dict-driven} { |
| 1868 |
namespace eval ns { |
| 1869 |
namespace export x* |
| 1870 |
proc x1 {} {format 1} |
| 1871 |
proc x2 {} {format 2} |
| 1872 |
namespace ensemble create -map {a x1 b x2} |
| 1873 |
} |
| 1874 |
set result [list [catch {ns c} msg] $msg [namespace ensemble exists ns]] |
| 1875 |
rename ns {} |
| 1876 |
lappend result [namespace ensemble exists ns] |
| 1877 |
} {1 {unknown or ambiguous subcommand "c": must be a, or b} 1 0} |
| 1878 |
test namespace-43.2 {ensembles: dict-driven} -body { |
| 1879 |
namespace eval ns { |
| 1880 |
namespace export x* |
| 1881 |
proc x1 {args} {list 1 $args} |
| 1882 |
proc x2 {args} {list 2 [llength $args]} |
| 1883 |
namespace ensemble create -map { |
| 1884 |
a ::ns::x1 b ::ns::x2 c {::ns::x1 .} d {::ns::x2 .} |
| 1885 |
} |
| 1886 |
} |
| 1887 |
list [ns a] [ns b] [ns c] [ns c foo] [ns d] [ns d foo] |
| 1888 |
} -cleanup { |
| 1889 |
namespace delete ns |
| 1890 |
} -result {{1 {}} {2 0} {1 .} {1 {. foo}} {2 1} {2 2}} |
| 1891 |
set SETUP { |
| 1892 |
namespace eval ns { |
| 1893 |
namespace export a b |
| 1894 |
proc a args {format 1,[llength $args]} |
| 1895 |
proc b args {format 2,[llength $args]} |
| 1896 |
proc c args {format 3,[llength $args]} |
| 1897 |
proc d args {format 4,[llength $args]} |
| 1898 |
namespace ensemble create -subcommands {b c} |
| 1899 |
} |
| 1900 |
} |
| 1901 |
test namespace-43.3 {ensembles: list-driven} -setup $SETUP -body { |
| 1902 |
namespace delete ns |
| 1903 |
} -result {} |
| 1904 |
test namespace-43.4 {ensembles: list-driven} -setup $SETUP -body { |
| 1905 |
ns a foo bar boo spong wibble |
| 1906 |
} -cleanup {namespace delete ns} -returnCodes error -result {unknown or ambiguous subcommand "a": must be b, or c} |
| 1907 |
test namespace-43.5 {ensembles: list-driven} -setup $SETUP -body { |
| 1908 |
ns b foo bar boo spong wibble |
| 1909 |
} -cleanup {namespace delete ns} -result 2,5 |
| 1910 |
test namespace-43.6 {ensembles: list-driven} -setup $SETUP -body { |
| 1911 |
ns c foo bar boo spong wibble |
| 1912 |
} -cleanup {namespace delete ns} -result 3,5 |
| 1913 |
test namespace-43.7 {ensembles: list-driven} -setup $SETUP -body { |
| 1914 |
ns d foo bar boo spong wibble |
| 1915 |
} -cleanup {namespace delete ns} -returnCodes error -result {unknown or ambiguous subcommand "d": must be b, or c} |
| 1916 |
set SETUP { |
| 1917 |
namespace eval ns { |
| 1918 |
namespace export a b |
| 1919 |
proc a args {format 1,[llength $args]} |
| 1920 |
proc b args {format 2,[llength $args]} |
| 1921 |
proc c args {format 3,[llength $args]} |
| 1922 |
proc d args {format 4,[llength $args]} |
| 1923 |
namespace ensemble create -subcommands {b c} -map {c ::ns::d} |
| 1924 |
} |
| 1925 |
} |
| 1926 |
test namespace-43.8 {ensembles: list-and-map-driven} -setup $SETUP -body { |
| 1927 |
namespace delete ns |
| 1928 |
} -result {} |
| 1929 |
test namespace-43.9 {ensembles: list-and-map-driven} -setup $SETUP -body { |
| 1930 |
ns a foo bar boo spong wibble |
| 1931 |
} -cleanup {namespace delete ns} -returnCodes error -result {unknown or ambiguous subcommand "a": must be b, or c} |
| 1932 |
test namespace-43.10 {ensembles: list-and-map-driven} -setup $SETUP -body { |
| 1933 |
ns b foo bar boo spong wibble |
| 1934 |
} -cleanup {namespace delete ns} -result 2,5 |
| 1935 |
test namespace-43.11 {ensembles: list-and-map-driven} -setup $SETUP -body { |
| 1936 |
ns c foo bar boo spong wibble |
| 1937 |
} -cleanup {namespace delete ns} -result 4,5 |
| 1938 |
test namespace-43.12 {ensembles: list-and-map-driven} -setup $SETUP -body { |
| 1939 |
ns d foo bar boo spong wibble |
| 1940 |
} -cleanup {namespace delete ns} -returnCodes error -result {unknown or ambiguous subcommand "d": must be b, or c} |
| 1941 |
set SETUP { |
| 1942 |
namespace eval ns { |
| 1943 |
namespace export * |
| 1944 |
proc foo args {format bar} |
| 1945 |
proc spong args {format wibble} |
| 1946 |
namespace ensemble create -prefixes off |
| 1947 |
} |
| 1948 |
} |
| 1949 |
test namespace-43.13 {ensembles: turn off prefixes} -setup $SETUP -body { |
| 1950 |
namespace delete ns |
| 1951 |
} -result {} |
| 1952 |
test namespace-43.14 {ensembles: turn off prefixes} -setup $SETUP -body { |
| 1953 |
ns fo |
| 1954 |
} -cleanup {namespace delete ns} -returnCodes error -result {unknown subcommand "fo": must be foo, or spong} |
| 1955 |
test namespace-43.15 {ensembles: turn off prefixes} -setup $SETUP -body { |
| 1956 |
ns foo |
| 1957 |
} -cleanup {namespace delete ns} -result bar |
| 1958 |
test namespace-43.16 {ensembles: turn off prefixes} -setup $SETUP -body { |
| 1959 |
ns s |
| 1960 |
} -cleanup {namespace delete ns} -returnCodes error -result {unknown subcommand "s": must be foo, or spong} |
| 1961 |
test namespace-43.17 {ensembles: turn off prefixes} -setup $SETUP -body { |
| 1962 |
ns spong |
| 1963 |
} -cleanup {namespace delete ns} -result wibble |
| 1964 |
|
| 1965 |
test namespace-44.1 {ensemble: errors} { |
| 1966 |
list [catch {namespace ensemble} msg] $msg |
| 1967 |
} {1 {wrong # args: should be "namespace ensemble subcommand ?arg ...?"}} |
| 1968 |
test namespace-44.2 {ensemble: errors} { |
| 1969 |
list [catch {namespace ensemble ?} msg] $msg |
| 1970 |
} {1 {bad subcommand "?": must be configure, create, or exists}} |
| 1971 |
test namespace-44.3 {ensemble: errors} { |
| 1972 |
namespace eval ns { |
| 1973 |
list [catch {namespace ensemble create -map x} msg] $msg |
| 1974 |
} |
| 1975 |
} {1 {missing value to go with key}} |
| 1976 |
test namespace-44.4 {ensemble: errors} { |
| 1977 |
namespace eval ns { |
| 1978 |
list [catch {namespace ensemble create -map {x {}}} msg] $msg |
| 1979 |
} |
| 1980 |
} {1 {ensemble subcommand implementations must be non-empty lists}} |
| 1981 |
test namespace-44.5 {ensemble: errors} -setup { |
| 1982 |
namespace ensemble create -command foobar -subcommands {foobarcget foobarconfigure} |
| 1983 |
} -body { |
| 1984 |
foobar foobarcon |
| 1985 |
} -cleanup { |
| 1986 |
rename foobar {} |
| 1987 |
} -returnCodes error -result {invalid command name "foobarconfigure"} |
| 1988 |
test namespace-44.6 {ensemble: errors} -returnCodes error -body { |
| 1989 |
namespace ensemble create gorp |
| 1990 |
} -result {wrong # args: should be "namespace ensemble create ?option value ...?"} |
| 1991 |
|
| 1992 |
test namespace-45.1 {ensemble: introspection} { |
| 1993 |
namespace eval ns { |
| 1994 |
namespace export x |
| 1995 |
proc x {} {} |
| 1996 |
namespace ensemble create |
| 1997 |
set ::result [namespace ensemble configure ::ns] |
| 1998 |
} |
| 1999 |
namespace delete ns |
| 2000 |
set result |
| 2001 |
} {-map {} -namespace ::ns -parameters {} -prefixes 1 -subcommands {} -unknown {}} |
| 2002 |
test namespace-45.2 {ensemble: introspection} { |
| 2003 |
namespace eval ns { |
| 2004 |
namespace export x |
| 2005 |
proc x {} {} |
| 2006 |
namespace ensemble create -map {A x} |
| 2007 |
set ::result [namespace ensemble configure ::ns -map] |
| 2008 |
} |
| 2009 |
namespace delete ns |
| 2010 |
set result |
| 2011 |
} {A ::ns::x} |
| 2012 |
|
| 2013 |
test namespace-46.1 {ensemble: modification} { |
| 2014 |
namespace eval ns { |
| 2015 |
namespace export x |
| 2016 |
proc x {} {format 123} |
| 2017 |
# Ensemble maps A->x |
| 2018 |
namespace ensemble create -command ns -map {A ::ns::x} |
| 2019 |
set ::result [list [namespace ensemble configure ns -map] [ns A]] |
| 2020 |
# Ensemble maps B->x |
| 2021 |
namespace ensemble configure ns -map {B ::ns::x} |
| 2022 |
lappend ::result [namespace ensemble configure ns -map] [ns B] |
| 2023 |
# Ensemble maps x->x |
| 2024 |
namespace ensemble configure ns -map {} |
| 2025 |
lappend ::result [namespace ensemble configure ns -map] [ns x] |
| 2026 |
} |
| 2027 |
namespace delete ns |
| 2028 |
set result |
| 2029 |
} {{A ::ns::x} 123 {B ::ns::x} 123 {} 123} |
| 2030 |
test namespace-46.2 {ensemble: ensembles really use current export list} { |
| 2031 |
namespace eval ns { |
| 2032 |
namespace export x1 |
| 2033 |
proc x1 {} {format 1} |
| 2034 |
proc x2 {} {format 1} |
| 2035 |
namespace ensemble create |
| 2036 |
} |
| 2037 |
catch {ns ?} msg; set result [list $msg] |
| 2038 |
namespace eval ns {namespace export x*} |
| 2039 |
catch {ns ?} msg; lappend result $msg |
| 2040 |
rename ns::x1 {} |
| 2041 |
catch {ns ?} msg; lappend result $msg |
| 2042 |
namespace delete ns |
| 2043 |
set result |
| 2044 |
} {{unknown or ambiguous subcommand "?": must be x1} {unknown or ambiguous subcommand "?": must be x1, or x2} {unknown or ambiguous subcommand "?": must be x2}} |
| 2045 |
test namespace-46.3 {ensemble: implementation errors} { |
| 2046 |
namespace eval ns { |
| 2047 |
variable count 0 |
| 2048 |
namespace ensemble create -map { |
| 2049 |
a {::lappend ::result} |
| 2050 |
b {::incr ::ns::count} |
| 2051 |
} |
| 2052 |
} |
| 2053 |
set result {} |
| 2054 |
lappend result [catch { ns } msg] $msg |
| 2055 |
ns a [ns b 10] |
| 2056 |
catch {rename p {}} |
| 2057 |
rename ns p |
| 2058 |
p a [p b 3000] |
| 2059 |
lappend result $ns::count |
| 2060 |
namespace delete ns |
| 2061 |
lappend result [info command p] |
| 2062 |
} {1 {wrong # args: should be "ns subcommand ?arg ...?"} 10 3010 3010 {}} |
| 2063 |
test namespace-46.4 {ensemble: implementation errors} { |
| 2064 |
namespace eval ns { |
| 2065 |
namespace ensemble create |
| 2066 |
} |
| 2067 |
set result [info command ns] |
| 2068 |
lappend result [catch {ns ?} msg] $msg |
| 2069 |
namespace delete ns |
| 2070 |
set result |
| 2071 |
} {ns 1 {unknown subcommand "?": namespace ::ns does not export any commands}} |
| 2072 |
test namespace-46.5 {ensemble: implementation errors} { |
| 2073 |
namespace eval ns { |
| 2074 |
namespace ensemble create -map {makeError ::error} |
| 2075 |
} |
| 2076 |
list [catch {ns makeError "an error happened"} msg] $msg $::errorInfo [namespace delete ns] |
| 2077 |
} {1 {an error happened} {an error happened |
| 2078 |
while executing |
| 2079 |
"ns makeError "an error happened""} {}} |
| 2080 |
test namespace-46.6 {ensemble: implementation renames/deletes itself} { |
| 2081 |
namespace eval ns { |
| 2082 |
namespace ensemble create -map {to ::rename} |
| 2083 |
} |
| 2084 |
ns to ns foo |
| 2085 |
foo to foo bar |
| 2086 |
bar to bar spong |
| 2087 |
spong to spong {} |
| 2088 |
namespace delete ns |
| 2089 |
} {} |
| 2090 |
test namespace-46.7 {ensemble: implementation deletes its namespace} { |
| 2091 |
namespace eval ns { |
| 2092 |
namespace ensemble create -map {kill {::namespace delete}} |
| 2093 |
} |
| 2094 |
ns kill ns |
| 2095 |
} {} |
| 2096 |
test namespace-46.8 {ensemble: implementation deletes its namespace} { |
| 2097 |
namespace eval ns { |
| 2098 |
namespace export * |
| 2099 |
proc foo {} { |
| 2100 |
variable x 1 |
| 2101 |
bar |
| 2102 |
# Tricky; what is the correct return value anyway? |
| 2103 |
info exist x |
| 2104 |
} |
| 2105 |
proc bar {} { |
| 2106 |
namespace delete [namespace current] |
| 2107 |
} |
| 2108 |
namespace ensemble create |
| 2109 |
} |
| 2110 |
list [ns foo] [info exist ns::x] |
| 2111 |
} {1 0} |
| 2112 |
test namespace-46.9 {ensemble: configuring really configures things} { |
| 2113 |
namespace eval ns { |
| 2114 |
namespace ensemble create -map {a a} -prefixes 0 |
| 2115 |
} |
| 2116 |
set result [list [catch {ns x} msg] $msg] |
| 2117 |
namespace ensemble configure ns -map {b b} |
| 2118 |
lappend result [catch {ns x} msg] $msg |
| 2119 |
namespace delete ns |
| 2120 |
set result |
| 2121 |
} {1 {unknown subcommand "x": must be a} 1 {unknown subcommand "x": must be b}} |
| 2122 |
|
| 2123 |
test namespace-47.1 {ensemble: unknown handler} { |
| 2124 |
set log {} |
| 2125 |
namespace eval ns { |
| 2126 |
namespace export {[a-z]*} |
| 2127 |
proc Magic {ensemble subcmd args} { |
| 2128 |
global log |
| 2129 |
if {[string match {[a-z]*} $subcmd]} { |
| 2130 |
lappend log "making $subcmd" |
| 2131 |
proc $subcmd args { |
| 2132 |
global log |
| 2133 |
lappend log "running [info level 0]" |
| 2134 |
llength $args |
| 2135 |
} |
| 2136 |
} else { |
| 2137 |
lappend log "unknown $subcmd - args = $args" |
| 2138 |
return -code error \ |
| 2139 |
"unknown or protected subcommand \"$subcmd\"" |
| 2140 |
} |
| 2141 |
} |
| 2142 |
namespace ensemble create -unknown ::ns::Magic |
| 2143 |
} |
| 2144 |
set result {} |
| 2145 |
lappend result [catch {ns a b c} msg] $msg |
| 2146 |
lappend result [catch {ns a b c} msg] $msg |
| 2147 |
lappend result [catch {ns b c d} msg] $msg |
| 2148 |
lappend result [catch {ns c d e} msg] $msg |
| 2149 |
lappend result [catch {ns Magic foo bar spong wibble} msg] $msg |
| 2150 |
list $result [lsort [info commands ::ns::*]] $log [namespace delete ns] |
| 2151 |
} {{0 2 0 2 0 2 0 2 1 {unknown or protected subcommand "Magic"}} {::ns::Magic ::ns::a ::ns::b ::ns::c} {{making a} {running ::ns::a b c} {running ::ns::a b c} {making b} {running ::ns::b c d} {making c} {running ::ns::c d e} {unknown Magic - args = foo bar spong wibble}} {}} |
| 2152 |
test namespace-47.2 {ensemble: unknown handler} { |
| 2153 |
namespace eval ns { |
| 2154 |
namespace export {[a-z]*} |
| 2155 |
proc Magic {ensemble subcmd args} { |
| 2156 |
error foobar |
| 2157 |
} |
| 2158 |
namespace ensemble create -unknown ::ns::Magic |
| 2159 |
} |
| 2160 |
list [catch {ns spong} msg] $msg $::errorInfo [namespace delete ns] |
| 2161 |
} {1 foobar {foobar |
| 2162 |
while executing |
| 2163 |
"error foobar" |
| 2164 |
(procedure "::ns::Magic" line 2) |
| 2165 |
invoked from within |
| 2166 |
"::ns::Magic ::ns spong" |
| 2167 |
(ensemble unknown subcommand handler) |
| 2168 |
invoked from within |
| 2169 |
"ns spong"} {}} |
| 2170 |
test namespace-47.3 {ensemble: unknown handler} { |
| 2171 |
namespace eval ns { |
| 2172 |
variable count 0 |
| 2173 |
namespace export {[a-z]*} |
| 2174 |
proc a {} {} |
| 2175 |
proc c {} {} |
| 2176 |
proc Magic {ensemble subcmd args} { |
| 2177 |
variable count |
| 2178 |
incr count |
| 2179 |
proc b {} {} |
| 2180 |
} |
| 2181 |
namespace ensemble create -unknown ::ns::Magic |
| 2182 |
} |
| 2183 |
list [catch {ns spong} msg] $msg $ns::count [namespace delete ns] |
| 2184 |
} {1 {unknown or ambiguous subcommand "spong": must be a, b, or c} 1 {}} |
| 2185 |
test namespace-47.4 {ensemble: unknown handler} { |
| 2186 |
namespace eval ns { |
| 2187 |
namespace export {[a-z]*} |
| 2188 |
proc Magic {ensemble subcmd args} { |
| 2189 |
return -code break |
| 2190 |
} |
| 2191 |
namespace ensemble create -unknown ::ns::Magic |
| 2192 |
} |
| 2193 |
list [catch {ns spong} msg] $msg $::errorInfo [namespace delete ns] |
| 2194 |
} {1 {unknown subcommand handler returned bad code: break} {unknown subcommand handler returned bad code: break |
| 2195 |
result of ensemble unknown subcommand handler: ::ns::Magic ::ns spong |
| 2196 |
invoked from within |
| 2197 |
"ns spong"} {}} |
| 2198 |
test namespace-47.5 {ensemble: unknown handler} { |
| 2199 |
namespace ensemble create -command foo -unknown bar |
| 2200 |
proc bar {args} { |
| 2201 |
global result target |
| 2202 |
lappend result "LOG $args" |
| 2203 |
return $target |
| 2204 |
} |
| 2205 |
set result {} |
| 2206 |
set target {} |
| 2207 |
lappend result [catch {foo bar} msg] $msg |
| 2208 |
set target {lappend result boo hoo} |
| 2209 |
lappend result [catch {foo bar} msg] $msg [namespace ensemble config foo] |
| 2210 |
rename foo {} |
| 2211 |
set result |
| 2212 |
} {{LOG ::foo bar} 1 {unknown subcommand "bar": namespace :: does not export any commands} {LOG ::foo bar} boo hoo 0 {{LOG ::foo bar} 1 {unknown subcommand "bar": namespace :: does not export any commands} {LOG ::foo bar} boo hoo} {-map {} -namespace :: -parameters {} -prefixes 1 -subcommands {} -unknown bar}} |
| 2213 |
test namespace-47.6 {ensemble: unknown handler} { |
| 2214 |
namespace ensemble create -command foo -unknown bar |
| 2215 |
proc bar {args} { |
| 2216 |
return "\{" |
| 2217 |
} |
| 2218 |
set result [list [catch {foo bar} msg] $msg $::errorInfo] |
| 2219 |
rename foo {} |
| 2220 |
set result |
| 2221 |
} {1 {unmatched open brace in list} {unmatched open brace in list |
| 2222 |
while parsing result of ensemble unknown subcommand handler |
| 2223 |
invoked from within |
| 2224 |
"foo bar"}} |
| 2225 |
test namespace-47.7 {ensemble: unknown handler, commands with spaces} { |
| 2226 |
namespace ensemble create -command foo -unknown bar |
| 2227 |
proc bar {args} { |
| 2228 |
list ::set ::x [join $args |] |
| 2229 |
} |
| 2230 |
set result [foo {one two three}] |
| 2231 |
rename foo {} |
| 2232 |
set result |
| 2233 |
} {::foo|one two three} |
| 2234 |
test namespace-47.8 {ensemble: unknown handler, commands with spaces} { |
| 2235 |
namespace ensemble create -command foo -unknown {bar boo} |
| 2236 |
proc bar {args} { |
| 2237 |
list ::set ::x [join $args |] |
| 2238 |
} |
| 2239 |
set result [foo {one two three}] |
| 2240 |
rename foo {} |
| 2241 |
set result |
| 2242 |
} {boo|::foo|one two three} |
| 2243 |
|
| 2244 |
test namespace-48.1 {ensembles and namespace import: unknown handler} { |
| 2245 |
namespace eval foo { |
| 2246 |
namespace export bar |
| 2247 |
namespace ensemble create -command bar -unknown ::foo::u -subcomm x |
| 2248 |
proc u {ens args} { |
| 2249 |
global result |
| 2250 |
lappend result $ens $args |
| 2251 |
namespace ensemble config $ens -subcommand {x y} |
| 2252 |
} |
| 2253 |
proc u2 {ens args} { |
| 2254 |
global result |
| 2255 |
lappend result $ens $args |
| 2256 |
namespace ensemble config ::bar -subcommand {x y z} |
| 2257 |
} |
| 2258 |
proc x args { |
| 2259 |
global result |
| 2260 |
lappend result XXX $args |
| 2261 |
} |
| 2262 |
proc y args { |
| 2263 |
global result |
| 2264 |
lappend result YYY $args |
| 2265 |
} |
| 2266 |
proc z args { |
| 2267 |
global result |
| 2268 |
lappend result ZZZ $args |
| 2269 |
} |
| 2270 |
} |
| 2271 |
namespace import -force foo::bar |
| 2272 |
set result [list [namespace ensemble config bar]] |
| 2273 |
bar x 123 |
| 2274 |
bar y 456 |
| 2275 |
namespace ensemble config bar -unknown ::foo::u2 |
| 2276 |
bar z 789 |
| 2277 |
namespace delete foo |
| 2278 |
set result |
| 2279 |
} {{-map {} -namespace ::foo -parameters {} -prefixes 1 -subcommands x -unknown ::foo::u} XXX 123 ::foo::bar {y 456} YYY 456 ::foo::bar {z 789} ZZZ 789} |
| 2280 |
test namespace-48.2 {ensembles and namespace import: exists} { |
| 2281 |
namespace eval foo { |
| 2282 |
namespace ensemble create -command ::foo::bar |
| 2283 |
namespace export bar |
| 2284 |
} |
| 2285 |
set result [namespace ensemble exist foo::bar] |
| 2286 |
lappend result [namespace ensemble exist bar] |
| 2287 |
namespace import foo::bar |
| 2288 |
lappend result [namespace ensemble exist bar] |
| 2289 |
rename foo::bar foo::bar2 |
| 2290 |
lappend result [namespace ensemble exist bar] \ |
| 2291 |
[namespace ensemble exist spong] |
| 2292 |
rename bar spong |
| 2293 |
lappend result [namespace ensemble exist bar] \ |
| 2294 |
[namespace ensemble exist spong] |
| 2295 |
rename foo::bar2 {} |
| 2296 |
lappend result [namespace ensemble exist spong] |
| 2297 |
namespace delete foo |
| 2298 |
set result |
| 2299 |
} {1 0 1 1 0 0 1 0} |
| 2300 |
test namespace-48.3 {ensembles and namespace import: config} { |
| 2301 |
catch {rename spong {}} |
| 2302 |
namespace eval foo { |
| 2303 |
namespace ensemble create -command ::foo::bar |
| 2304 |
namespace export bar boo |
| 2305 |
proc boo {} {} |
| 2306 |
} |
| 2307 |
namespace import foo::bar foo::boo |
| 2308 |
set result [namespace ensemble config bar -namespace] |
| 2309 |
lappend result [catch {namespace ensemble config boo} msg] $msg |
| 2310 |
lappend result [catch {namespace ensemble config spong} msg] $msg |
| 2311 |
namespace delete foo |
| 2312 |
set result |
| 2313 |
} {::foo 1 {"boo" is not an ensemble command} 1 {unknown command "spong"}} |
| 2314 |
|
| 2315 |
test namespace-49.1 {ensemble subcommand caching} -body { |
| 2316 |
namespace ens cre -command a -map {b {lappend result 1}} |
| 2317 |
namespace ens cre -command c -map {b {lappend result 2}} |
| 2318 |
proc x {} {a b; c b; a b; c b} |
| 2319 |
x |
| 2320 |
} -result {1 2 1 2} -cleanup { |
| 2321 |
rename a {} |
| 2322 |
rename c {} |
| 2323 |
rename x {} |
| 2324 |
} |
| 2325 |
test namespace-49.2 {strange delete crash} -body { |
| 2326 |
namespace eval foo {namespace ensemble create -command ::bar} |
| 2327 |
trace add command ::bar delete DeleteTrace |
| 2328 |
proc DeleteTrace {old new op} { |
| 2329 |
trace remove command ::bar delete DeleteTrace |
| 2330 |
rename $old "" |
| 2331 |
# This next line caused a bus error in [Bug 1220058] |
| 2332 |
namespace delete foo |
| 2333 |
} |
| 2334 |
rename ::bar "" |
| 2335 |
} -result "" -cleanup { |
| 2336 |
rename DeleteTrace "" |
| 2337 |
} |
| 2338 |
|
| 2339 |
test namespace-50.1 {ensembles affect proc arguments error messages} -body { |
| 2340 |
namespace ens cre -command a -map {b {bb foo}} |
| 2341 |
proc bb {c d {e f} args} {list $c $args} |
| 2342 |
a b |
| 2343 |
} -returnCodes error -result "wrong # args: should be \"a b d ?e? ?arg ...?\"" -cleanup { |
| 2344 |
rename a {} |
| 2345 |
rename bb {} |
| 2346 |
} |
| 2347 |
test namespace-50.2 {ensembles affect WrongNumArgs error messages} -body { |
| 2348 |
namespace ens cre -command a -map {b {string is}} |
| 2349 |
a b boolean |
| 2350 |
} -returnCodes error -result "wrong # args: should be \"a b class ?-strict? ?-failindex var? str\"" -cleanup { |
| 2351 |
rename a {} |
| 2352 |
} |
| 2353 |
test namespace-50.3 {chained ensembles affect error messages} -body { |
| 2354 |
namespace ens cre -command a -map {b c} |
| 2355 |
namespace ens cre -command c -map {d e} |
| 2356 |
proc e f {} |
| 2357 |
a b d |
| 2358 |
} -returnCodes error -result "wrong # args: should be \"a b d f\"" -cleanup { |
| 2359 |
rename a {} |
| 2360 |
rename c {} |
| 2361 |
} |
| 2362 |
test namespace-50.4 {chained ensembles affect error messages} -body { |
| 2363 |
namespace ens cre -command a -map {b {c d}} |
| 2364 |
namespace ens cre -command c -map {d {e f}} |
| 2365 |
proc e f {} |
| 2366 |
a b d |
| 2367 |
} -returnCodes error -result "wrong # args: should be \"a b\"" -cleanup { |
| 2368 |
rename a {} |
| 2369 |
rename c {} |
| 2370 |
} |
| 2371 |
test namespace-50.5 {[4402cfa58c]} -setup { |
| 2372 |
proc bar {ev} {} |
| 2373 |
proc bingo {xx} {} |
| 2374 |
namespace ensemble create -command launch -map {foo bar event bingo} |
| 2375 |
set result {} |
| 2376 |
} -body { |
| 2377 |
catch {launch foo} m; lappend result $m |
| 2378 |
catch {launch ev} m; lappend result $m |
| 2379 |
catch {launch foo} m; lappend result $m |
| 2380 |
} -cleanup { |
| 2381 |
rename launch {} |
| 2382 |
rename bingo {} |
| 2383 |
rename bar {} |
| 2384 |
} -result {{wrong # args: should be "launch foo ev"} {wrong # args: should be "launch event xx"} {wrong # args: should be "launch foo ev"}} |
| 2385 |
test namespace-50.6 {[4402cfa58c]} -setup { |
| 2386 |
proc target {x y} {} |
| 2387 |
namespace ensemble create -command e2 -map {s2 target} |
| 2388 |
namespace ensemble create -command e1 -map {s1 e2} |
| 2389 |
set result {} |
| 2390 |
} -body { |
| 2391 |
set s s |
| 2392 |
catch {e1 s1 s2 a} m; lappend result $m |
| 2393 |
catch {e1 $s s2 a} m; lappend result $m |
| 2394 |
catch {e1 s1 $s a} m; lappend result $m |
| 2395 |
catch {e1 $s $s a} m; lappend result $m |
| 2396 |
} -cleanup { |
| 2397 |
rename e1 {} |
| 2398 |
rename e2 {} |
| 2399 |
rename target {} |
| 2400 |
} -result {{wrong # args: should be "e1 s1 s2 x y"} {wrong # args: should be "e1 s1 s2 x y"} {wrong # args: should be "e1 s1 s2 x y"} {wrong # args: should be "e1 s1 s2 x y"}} |
| 2401 |
test namespace-50.7 {[4402cfa58c]} -setup { |
| 2402 |
proc target {x y} {} |
| 2403 |
namespace ensemble create -command e2 -map {s2 target} |
| 2404 |
namespace ensemble create -command e1 -map {s1 e2} -parameters foo |
| 2405 |
set result {} |
| 2406 |
} -body { |
| 2407 |
set s s |
| 2408 |
catch {e1 s2 s1 a} m; lappend result $m |
| 2409 |
catch {e1 $s s1 a} m; lappend result $m |
| 2410 |
catch {e1 s2 $s a} m; lappend result $m |
| 2411 |
catch {e1 $s $s a} m; lappend result $m |
| 2412 |
} -cleanup { |
| 2413 |
rename e1 {} |
| 2414 |
rename e2 {} |
| 2415 |
rename target {} |
| 2416 |
} -result {{wrong # args: should be "e1 s2 s1 x y"} {wrong # args: should be "e1 s2 s1 x y"} {wrong # args: should be "e1 s2 s1 x y"} {wrong # args: should be "e1 s2 s1 x y"}} |
| 2417 |
test namespace-50.8 {[f961d7d1dd]} -setup { |
| 2418 |
proc target {} {} |
| 2419 |
namespace ensemble create -command e -map {s target} -parameters {{a b}} |
| 2420 |
} -body { |
| 2421 |
e |
| 2422 |
} -returnCodes error -result {wrong # args: should be "e {a b} subcommand ?arg ...?"} -cleanup { |
| 2423 |
rename e {} |
| 2424 |
rename target {} |
| 2425 |
} |
| 2426 |
test namespace-50.9 {[cea0344a51]} -body { |
| 2427 |
namespace eval foo { |
| 2428 |
namespace eval bar { |
| 2429 |
namespace delete foo |
| 2430 |
} |
| 2431 |
} |
| 2432 |
} -returnCodes error -result {unknown namespace "foo" in namespace delete command} |
| 2433 |
|
| 2434 |
test namespace-51.1 {name resolution path control} -body { |
| 2435 |
namespace eval ::test_ns_1 { |
| 2436 |
namespace eval test_ns_2 { |
| 2437 |
proc pathtestA {} { |
| 2438 |
::return [pathtestB],[pathtestC],[pathtestD],[namespace path] |
| 2439 |
} |
| 2440 |
proc pathtestC {} { |
| 2441 |
::return 2 |
| 2442 |
} |
| 2443 |
} |
| 2444 |
proc pathtestB {} { |
| 2445 |
return 1 |
| 2446 |
} |
| 2447 |
proc pathtestC {} { |
| 2448 |
return 1 |
| 2449 |
} |
| 2450 |
namespace path ::test_ns_1 |
| 2451 |
} |
| 2452 |
proc ::pathtestB {} { |
| 2453 |
return global |
| 2454 |
} |
| 2455 |
proc ::pathtestD {} { |
| 2456 |
return global |
| 2457 |
} |
| 2458 |
test_ns_1::test_ns_2::pathtestA |
| 2459 |
} -result "global,2,global," -cleanup { |
| 2460 |
namespace delete ::test_ns_1 |
| 2461 |
catch {rename ::pathtestB {}} |
| 2462 |
catch {rename ::pathtestD {}} |
| 2463 |
} |
| 2464 |
test namespace-51.2 {name resolution path control} -body { |
| 2465 |
namespace eval ::test_ns_1 { |
| 2466 |
namespace eval test_ns_2 { |
| 2467 |
namespace path ::test_ns_1 |
| 2468 |
proc pathtestA {} { |
| 2469 |
::return [pathtestB],[pathtestC],[pathtestD],[namespace path] |
| 2470 |
} |
| 2471 |
proc pathtestC {} { |
| 2472 |
::return 2 |
| 2473 |
} |
| 2474 |
} |
| 2475 |
proc pathtestB {} { |
| 2476 |
return 1 |
| 2477 |
} |
| 2478 |
proc pathtestC {} { |
| 2479 |
return 1 |
| 2480 |
} |
| 2481 |
} |
| 2482 |
proc ::pathtestB {} { |
| 2483 |
return global |
| 2484 |
} |
| 2485 |
proc ::pathtestD {} { |
| 2486 |
return global |
| 2487 |
} |
| 2488 |
::test_ns_1::test_ns_2::pathtestA |
| 2489 |
} -result "1,2,global,::test_ns_1" -cleanup { |
| 2490 |
namespace delete ::test_ns_1 |
| 2491 |
catch {rename ::pathtestB {}} |
| 2492 |
catch {rename ::pathtestD {}} |
| 2493 |
} |
| 2494 |
test namespace-51.3 {name resolution path control} -body { |
| 2495 |
namespace eval ::test_ns_1 { |
| 2496 |
namespace eval test_ns_2 { |
| 2497 |
proc pathtestA {} { |
| 2498 |
::return [pathtestB],[pathtestC],[pathtestD],[namespace path] |
| 2499 |
} |
| 2500 |
proc pathtestC {} { |
| 2501 |
::return 2 |
| 2502 |
} |
| 2503 |
} |
| 2504 |
proc pathtestB {} { |
| 2505 |
return 1 |
| 2506 |
} |
| 2507 |
proc pathtestC {} { |
| 2508 |
return 1 |
| 2509 |
} |
| 2510 |
} |
| 2511 |
proc ::pathtestB {} { |
| 2512 |
return global |
| 2513 |
} |
| 2514 |
proc ::pathtestD {} { |
| 2515 |
return global |
| 2516 |
} |
| 2517 |
set result [::test_ns_1::test_ns_2::pathtestA] |
| 2518 |
namespace eval ::test_ns_1::test_ns_2 { |
| 2519 |
namespace path ::test_ns_1 |
| 2520 |
} |
| 2521 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2522 |
rename ::test_ns_1::pathtestB {} |
| 2523 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2524 |
} -result "global,2,global, 1,2,global,::test_ns_1 global,2,global,::test_ns_1" -cleanup { |
| 2525 |
namespace delete ::test_ns_1 |
| 2526 |
catch {rename ::pathtestB {}} |
| 2527 |
catch {rename ::pathtestD {}} |
| 2528 |
} |
| 2529 |
test namespace-51.4 {name resolution path control} -body { |
| 2530 |
namespace eval ::test_ns_1 { |
| 2531 |
namespace eval test_ns_2 { |
| 2532 |
proc pathtestA {} { |
| 2533 |
::return [pathtestB],[pathtestC],[pathtestD],[namespace path] |
| 2534 |
} |
| 2535 |
proc pathtestC {} { |
| 2536 |
::return 2 |
| 2537 |
} |
| 2538 |
} |
| 2539 |
proc pathtestB {} { |
| 2540 |
return 1 |
| 2541 |
} |
| 2542 |
proc pathtestC {} { |
| 2543 |
return 1 |
| 2544 |
} |
| 2545 |
} |
| 2546 |
proc ::pathtestB {} { |
| 2547 |
return global |
| 2548 |
} |
| 2549 |
proc ::pathtestD {} { |
| 2550 |
return global |
| 2551 |
} |
| 2552 |
set result [::test_ns_1::test_ns_2::pathtestA] |
| 2553 |
namespace eval ::test_ns_1::test_ns_2 { |
| 2554 |
namespace path ::test_ns_1 |
| 2555 |
} |
| 2556 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2557 |
namespace eval ::test_ns_1::test_ns_2 { |
| 2558 |
namespace path {} |
| 2559 |
} |
| 2560 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2561 |
} -result "global,2,global, 1,2,global,::test_ns_1 global,2,global," -cleanup { |
| 2562 |
namespace delete ::test_ns_1 |
| 2563 |
catch {rename ::pathtestB {}} |
| 2564 |
catch {rename ::pathtestD {}} |
| 2565 |
} |
| 2566 |
test namespace-51.5 {name resolution path control} -body { |
| 2567 |
namespace eval ::test_ns_1 { |
| 2568 |
namespace eval test_ns_2 { |
| 2569 |
proc pathtestA {} { |
| 2570 |
::return [pathtestB],[pathtestC],[pathtestD],[namespace path] |
| 2571 |
} |
| 2572 |
proc pathtestC {} { |
| 2573 |
::return 2 |
| 2574 |
} |
| 2575 |
namespace path ::test_ns_1 |
| 2576 |
} |
| 2577 |
proc pathtestB {} { |
| 2578 |
return 1 |
| 2579 |
} |
| 2580 |
proc pathtestC {} { |
| 2581 |
return 1 |
| 2582 |
} |
| 2583 |
proc pathtestD {} { |
| 2584 |
return 1 |
| 2585 |
} |
| 2586 |
} |
| 2587 |
proc ::pathtestB {} { |
| 2588 |
return global |
| 2589 |
} |
| 2590 |
proc ::pathtestD {} { |
| 2591 |
return global |
| 2592 |
} |
| 2593 |
set result [::test_ns_1::test_ns_2::pathtestA] |
| 2594 |
namespace eval ::test_ns_1::test_ns_2 { |
| 2595 |
namespace path {:: ::test_ns_1} |
| 2596 |
} |
| 2597 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2598 |
rename ::test_ns_1::test_ns_2::pathtestC {} |
| 2599 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2600 |
} -result "1,2,1,::test_ns_1 {global,2,global,:: ::test_ns_1} {global,1,global,:: ::test_ns_1}" -cleanup { |
| 2601 |
namespace delete ::test_ns_1 |
| 2602 |
catch {rename ::pathtestB {}} |
| 2603 |
catch {rename ::pathtestD {}} |
| 2604 |
} |
| 2605 |
test namespace-51.6 {name resolution path control} -body { |
| 2606 |
namespace eval ::test_ns_1 { |
| 2607 |
namespace eval test_ns_2 { |
| 2608 |
proc pathtestA {} { |
| 2609 |
::return [pathtestB],[pathtestC],[pathtestD],[namespace path] |
| 2610 |
} |
| 2611 |
proc pathtestC {} { |
| 2612 |
::return 2 |
| 2613 |
} |
| 2614 |
namespace path ::test_ns_1 |
| 2615 |
} |
| 2616 |
proc pathtestB {} { |
| 2617 |
return 1 |
| 2618 |
} |
| 2619 |
proc pathtestC {} { |
| 2620 |
return 1 |
| 2621 |
} |
| 2622 |
proc pathtestD {} { |
| 2623 |
return 1 |
| 2624 |
} |
| 2625 |
} |
| 2626 |
proc ::pathtestB {} { |
| 2627 |
return global |
| 2628 |
} |
| 2629 |
proc ::pathtestD {} { |
| 2630 |
return global |
| 2631 |
} |
| 2632 |
set result [::test_ns_1::test_ns_2::pathtestA] |
| 2633 |
namespace eval ::test_ns_1::test_ns_2 { |
| 2634 |
namespace path {:: ::test_ns_1} |
| 2635 |
} |
| 2636 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2637 |
rename ::test_ns_1::test_ns_2::pathtestC {} |
| 2638 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2639 |
proc ::pathtestC {} { |
| 2640 |
return global |
| 2641 |
} |
| 2642 |
lappend result [::test_ns_1::test_ns_2::pathtestA] |
| 2643 |
} -result "1,2,1,::test_ns_1 {global,2,global,:: ::test_ns_1} {global,1,global,:: ::test_ns_1} {global,global,global,:: ::test_ns_1}" -cleanup { |
| 2644 |
namespace delete ::test_ns_1 |
| 2645 |
catch {rename ::pathtestB {}} |
| 2646 |
catch {rename ::pathtestD {}} |
| 2647 |
catch {rename ::pathtestC {}} |
| 2648 |
} |
| 2649 |
test namespace-51.7 {name resolution path control} -body { |
| 2650 |
namespace eval ::test_ns_1 { |
| 2651 |
} |
| 2652 |
namespace eval ::test_ns_2 { |
| 2653 |
namespace path ::test_ns_1 |
| 2654 |
proc getpath {} {namespace path} |
| 2655 |
} |
| 2656 |
list [::test_ns_2::getpath] [namespace delete ::test_ns_1] [::test_ns_2::getpath] |
| 2657 |
} -result {::test_ns_1 {} {}} -cleanup { |
| 2658 |
catch {namespace delete ::test_ns_1} |
| 2659 |
namespace delete ::test_ns_2 |
| 2660 |
} |
| 2661 |
test namespace-51.8 {name resolution path control} -body { |
| 2662 |
namespace eval ::test_ns_1 { |
| 2663 |
} |
| 2664 |
namespace eval ::test_ns_2 { |
| 2665 |
} |
| 2666 |
namespace eval ::test_ns_3 { |
| 2667 |
} |
| 2668 |
namespace eval ::test_ns_4 { |
| 2669 |
namespace path {::test_ns_1 ::test_ns_2 ::test_ns_3} |
| 2670 |
proc getpath {} {namespace path} |
| 2671 |
} |
| 2672 |
list [::test_ns_4::getpath] [namespace delete ::test_ns_2] [::test_ns_4::getpath] |
| 2673 |
} -result {{::test_ns_1 ::test_ns_2 ::test_ns_3} {} {::test_ns_1 ::test_ns_3}} -cleanup { |
| 2674 |
catch {namespace delete ::test_ns_1} |
| 2675 |
catch {namespace delete ::test_ns_2} |
| 2676 |
catch {namespace delete ::test_ns_3} |
| 2677 |
catch {namespace delete ::test_ns_4} |
| 2678 |
} |
| 2679 |
test namespace-51.9 {name resolution path control} -body { |
| 2680 |
namespace eval ::test_ns_1 { |
| 2681 |
} |
| 2682 |
namespace eval ::test_ns_2 { |
| 2683 |
} |
| 2684 |
namespace eval ::test_ns_3 { |
| 2685 |
} |
| 2686 |
namespace eval ::test_ns_4 { |
| 2687 |
namespace path {::test_ns_1 ::test_ns_2 ::test_ns_3} |
| 2688 |
proc getpath {} {namespace path} |
| 2689 |
} |
| 2690 |
list [::test_ns_4::getpath] [namespace delete ::test_ns_2] [namespace eval ::test_ns_2 {}] [::test_ns_4::getpath] |
| 2691 |
} -result {{::test_ns_1 ::test_ns_2 ::test_ns_3} {} {} {::test_ns_1 ::test_ns_3}} -cleanup { |
| 2692 |
catch {namespace delete ::test_ns_1} |
| 2693 |
catch {namespace delete ::test_ns_2} |
| 2694 |
catch {namespace delete ::test_ns_3} |
| 2695 |
catch {namespace delete ::test_ns_4} |
| 2696 |
} |
| 2697 |
test namespace-51.10 {name resolution path control} -body { |
| 2698 |
namespace eval ::test_ns_1 { |
| 2699 |
namespace path does::not::exist |
| 2700 |
} |
| 2701 |
} -returnCodes error -result {namespace "does::not::exist" not found in "::test_ns_1"} -cleanup { |
| 2702 |
catch {namespace delete ::test_ns_1} |
| 2703 |
} |
| 2704 |
test namespace-51.11 {name resolution path control} -body { |
| 2705 |
namespace eval ::test_ns_1 { |
| 2706 |
proc foo {} {return 1} |
| 2707 |
} |
| 2708 |
namespace eval ::test_ns_2 { |
| 2709 |
proc foo {} {return 2} |
| 2710 |
} |
| 2711 |
namespace eval ::test_ns_3 { |
| 2712 |
namespace path ::test_ns_1 |
| 2713 |
} |
| 2714 |
namespace eval ::test_ns_4 { |
| 2715 |
namespace path {::test_ns_3 ::test_ns_2} |
| 2716 |
foo |
| 2717 |
} |
| 2718 |
} -result 2 -cleanup { |
| 2719 |
catch {namespace delete ::test_ns_1} |
| 2720 |
catch {namespace delete ::test_ns_2} |
| 2721 |
catch {namespace delete ::test_ns_3} |
| 2722 |
catch {namespace delete ::test_ns_4} |
| 2723 |
} |
| 2724 |
test namespace-51.12 {name resolution path control} -body { |
| 2725 |
namespace eval ::test_ns_1 { |
| 2726 |
proc foo {} {return 1} |
| 2727 |
} |
| 2728 |
namespace eval ::test_ns_2 { |
| 2729 |
proc foo {} {return 2} |
| 2730 |
} |
| 2731 |
namespace eval ::test_ns_3 { |
| 2732 |
namespace path ::test_ns_1 |
| 2733 |
} |
| 2734 |
namespace eval ::test_ns_4 { |
| 2735 |
namespace path {::test_ns_3 ::test_ns_2} |
| 2736 |
list [foo] [namespace delete ::test_ns_3] [foo] |
| 2737 |
} |
| 2738 |
} -result {2 {} 2} -cleanup { |
| 2739 |
catch {namespace delete ::test_ns_1} |
| 2740 |
catch {namespace delete ::test_ns_2} |
| 2741 |
catch {namespace delete ::test_ns_3} |
| 2742 |
catch {namespace delete ::test_ns_4} |
| 2743 |
} |
| 2744 |
test namespace-51.13 {name resolution path control} -body { |
| 2745 |
set ::result {} |
| 2746 |
namespace eval ::test_ns_1 { |
| 2747 |
proc foo {} {lappend ::result 1} |
| 2748 |
} |
| 2749 |
namespace eval ::test_ns_2 { |
| 2750 |
proc foo {} {lappend ::result 2} |
| 2751 |
trace add command foo delete "namespace eval ::test_ns_3 foo;#" |
| 2752 |
} |
| 2753 |
namespace eval ::test_ns_3 { |
| 2754 |
proc foo {} { |
| 2755 |
lappend ::result 3 |
| 2756 |
namespace delete [namespace current] |
| 2757 |
::test_ns_4::bar |
| 2758 |
} |
| 2759 |
} |
| 2760 |
namespace eval ::test_ns_4 { |
| 2761 |
namespace path {::test_ns_2 ::test_ns_3 ::test_ns_1} |
| 2762 |
proc bar {} { |
| 2763 |
list [foo] [namespace delete ::test_ns_2] [foo] |
| 2764 |
} |
| 2765 |
bar |
| 2766 |
} |
| 2767 |
# Should the result be "2 {} {2 3 2 1}" instead? |
| 2768 |
} -result {2 {} {2 3 1 1}} -cleanup { |
| 2769 |
catch {namespace delete ::test_ns_1} |
| 2770 |
catch {namespace delete ::test_ns_2} |
| 2771 |
catch {namespace delete ::test_ns_3} |
| 2772 |
catch {namespace delete ::test_ns_4} |
| 2773 |
} |
| 2774 |
test namespace-51.14 {name resolution path control} -setup { |
| 2775 |
foreach cmd [info commands foo*] { |
| 2776 |
rename $cmd {} |
| 2777 |
} |
| 2778 |
namespace eval ::test_ns_1 {} |
| 2779 |
namespace eval ::test_ns_2 {} |
| 2780 |
namespace eval ::test_ns_3 {} |
| 2781 |
} -body { |
| 2782 |
proc foo0 {} {} |
| 2783 |
proc ::test_ns_1::foo1 {} {} |
| 2784 |
proc ::test_ns_2::foo2 {} {} |
| 2785 |
namespace eval ::test_ns_3 { |
| 2786 |
variable result {} |
| 2787 |
lappend result [info commands foo*] |
| 2788 |
namespace path {::test_ns_1 ::test_ns_2} |
| 2789 |
lappend result [info commands foo*] |
| 2790 |
proc foo2 {} {} |
| 2791 |
lappend result [info commands foo*] |
| 2792 |
rename foo2 {} |
| 2793 |
lappend result [info commands foo*] |
| 2794 |
namespace delete ::test_ns_1 |
| 2795 |
lappend result [info commands foo*] |
| 2796 |
} |
| 2797 |
} -cleanup { |
| 2798 |
catch {namespace delete ::test_ns_1} |
| 2799 |
catch {namespace delete ::test_ns_2} |
| 2800 |
catch {namespace delete ::test_ns_3} |
| 2801 |
} -result {foo0 {foo1 foo2 foo0} {foo2 foo1 foo0} {foo1 foo2 foo0} {foo2 foo0}} |
| 2802 |
test namespace-51.15 {namespace resolution path control} -body { |
| 2803 |
namespace eval ::test_ns_2 { |
| 2804 |
proc foo {} {return 2} |
| 2805 |
} |
| 2806 |
namespace eval ::test_ns_1 { |
| 2807 |
namespace eval test_ns_2 { |
| 2808 |
proc foo {} {return 1_2} |
| 2809 |
} |
| 2810 |
namespace eval test_ns_3 { |
| 2811 |
namespace path ::test_ns_1 |
| 2812 |
test_ns_2::foo |
| 2813 |
} |
| 2814 |
} |
| 2815 |
} -result 1_2 -cleanup { |
| 2816 |
namespace delete ::test_ns_1 |
| 2817 |
namespace delete ::test_ns_2 |
| 2818 |
} |
| 2819 |
test namespace-51.16 {Bug 1566526} { |
| 2820 |
interp create child |
| 2821 |
child eval namespace eval demo namespace path :: |
| 2822 |
interp delete child |
| 2823 |
} {} |
| 2824 |
test namespace-51.17 {resolution epoch handling: Bug 2898722} -setup { |
| 2825 |
set result {} |
| 2826 |
catch {namespace delete ::a} |
| 2827 |
} -body { |
| 2828 |
namespace eval ::a { |
| 2829 |
proc c {} {lappend ::result A} |
| 2830 |
c |
| 2831 |
namespace eval b { |
| 2832 |
variable d c |
| 2833 |
lappend ::result [catch { $d }] |
| 2834 |
} |
| 2835 |
lappend ::result . |
| 2836 |
namespace eval b { |
| 2837 |
namespace path [namespace parent] |
| 2838 |
$d;[format %c 99] |
| 2839 |
} |
| 2840 |
lappend ::result . |
| 2841 |
namespace eval b { |
| 2842 |
proc c {} {lappend ::result B} |
| 2843 |
$d;[format %c 99] |
| 2844 |
} |
| 2845 |
lappend ::result . |
| 2846 |
} |
| 2847 |
namespace eval ::a::b { |
| 2848 |
$d;[format %c 99] |
| 2849 |
lappend ::result . |
| 2850 |
proc ::c {} {lappend ::result G} |
| 2851 |
$d;[format %c 99] |
| 2852 |
lappend ::result . |
| 2853 |
rename ::a::c {} |
| 2854 |
$d;[format %c 99] |
| 2855 |
lappend ::result . |
| 2856 |
rename ::a::b::c {} |
| 2857 |
$d;[format %c 99] |
| 2858 |
} |
| 2859 |
} -cleanup { |
| 2860 |
namespace delete ::a |
| 2861 |
catch {rename ::c {}} |
| 2862 |
unset result |
| 2863 |
} -result {A 1 . A A . B B . B B . B B . B B . G G} |
| 2864 |
test namespace-51.18 {Bug 3185407} -setup { |
| 2865 |
namespace eval ::test_ns_1 {} |
| 2866 |
} -body { |
| 2867 |
namespace eval ::test_ns_1 { |
| 2868 |
variable result {} |
| 2869 |
namespace eval ns {proc foo {} {}} |
| 2870 |
namespace eval ns2 {proc foo {} {}} |
| 2871 |
namespace path {ns ns2} |
| 2872 |
variable x foo |
| 2873 |
lappend result [namespace which $x] |
| 2874 |
proc foo {} {} |
| 2875 |
lappend result [namespace which $x] |
| 2876 |
} |
| 2877 |
} -cleanup { |
| 2878 |
namespace delete ::test_ns_1 |
| 2879 |
} -result {::test_ns_1::ns::foo ::test_ns_1::foo} |
| 2880 |
|
| 2881 |
# TIP 181 - namespace unknown tests |
| 2882 |
test namespace-52.1 {unknown: default handler ::unknown} { |
| 2883 |
set result [list [namespace eval foobar { namespace unknown }]] |
| 2884 |
lappend result [namespace eval :: { namespace unknown }] |
| 2885 |
namespace delete foobar |
| 2886 |
set result |
| 2887 |
} {{} ::unknown} |
| 2888 |
test namespace-52.2 {unknown: default resolution global} { |
| 2889 |
proc ::foo {} { return "GLOBAL" } |
| 2890 |
namespace eval ::bar { proc foo {} { return "NAMESPACE" } } |
| 2891 |
namespace eval ::bar::jim { proc test {} { foo } } |
| 2892 |
set result [::bar::jim::test] |
| 2893 |
namespace delete ::bar |
| 2894 |
rename ::foo {} |
| 2895 |
set result |
| 2896 |
} {GLOBAL} |
| 2897 |
test namespace-52.3 {unknown: default resolution local} { |
| 2898 |
proc ::foo {} { return "GLOBAL" } |
| 2899 |
namespace eval ::bar { |
| 2900 |
proc foo {} { return "NAMESPACE" } |
| 2901 |
proc test {} { foo } |
| 2902 |
} |
| 2903 |
set result [::bar::test] |
| 2904 |
namespace delete ::bar |
| 2905 |
rename ::foo {} |
| 2906 |
set result |
| 2907 |
} {NAMESPACE} |
| 2908 |
test namespace-52.4 {unknown: set handler} { |
| 2909 |
namespace eval foo { |
| 2910 |
namespace unknown [list dispatch] |
| 2911 |
proc dispatch {args} { return $args } |
| 2912 |
proc test {} { |
| 2913 |
UnknownCmd a b c |
| 2914 |
} |
| 2915 |
} |
| 2916 |
set result [foo::test] |
| 2917 |
namespace delete foo |
| 2918 |
set result |
| 2919 |
} {UnknownCmd a b c} |
| 2920 |
test namespace-52.5 {unknown: search path before unknown is unaltered} { |
| 2921 |
proc ::test2 {args} { return "TEST2: $args" } |
| 2922 |
namespace eval foo { |
| 2923 |
namespace unknown [list dispatch] |
| 2924 |
proc dispatch {args} { return "UNKNOWN: $args" } |
| 2925 |
proc test1 {args} { return "TEST1: $args" } |
| 2926 |
proc test {} { |
| 2927 |
set result [list [test1 a b c]] |
| 2928 |
lappend result [test2 a b c] |
| 2929 |
lappend result [test3 a b c] |
| 2930 |
return $result |
| 2931 |
} |
| 2932 |
} |
| 2933 |
set result [foo::test] |
| 2934 |
namespace delete foo |
| 2935 |
rename ::test2 {} |
| 2936 |
set result |
| 2937 |
} {{TEST1: a b c} {TEST2: a b c} {UNKNOWN: test3 a b c}} |
| 2938 |
test namespace-52.6 {unknown: deleting handler restores default} { |
| 2939 |
rename ::unknown ::_unknown_orig |
| 2940 |
proc ::unknown {args} { return "DEFAULT: $args" } |
| 2941 |
namespace eval foo { |
| 2942 |
namespace unknown dummy |
| 2943 |
namespace unknown {} |
| 2944 |
} |
| 2945 |
set result [namespace eval foo { dummy a b c }] |
| 2946 |
rename ::unknown {} |
| 2947 |
rename ::_unknown_orig ::unknown |
| 2948 |
namespace delete foo |
| 2949 |
set result |
| 2950 |
} {DEFAULT: dummy a b c} |
| 2951 |
test namespace-52.7 {unknown: setting global unknown handler} { |
| 2952 |
proc ::myunknown {args} { return "MYUNKNOWN: $args" } |
| 2953 |
namespace eval :: { namespace unknown ::myunknown } |
| 2954 |
set result [namespace eval foo { dummy a b c }] |
| 2955 |
namespace eval :: { namespace unknown {} } |
| 2956 |
rename ::myunknown {} |
| 2957 |
namespace delete foo |
| 2958 |
set result |
| 2959 |
} {MYUNKNOWN: dummy a b c} |
| 2960 |
test namespace-52.8 {unknown: destroying and redefining global namespace} { |
| 2961 |
set i [interp create] |
| 2962 |
$i hide proc |
| 2963 |
$i hide namespace |
| 2964 |
$i hide return |
| 2965 |
$i invokehidden namespace delete :: |
| 2966 |
$i expose return |
| 2967 |
$i invokehidden proc unknown args { return "FINE" } |
| 2968 |
$i eval { foo bar bob } |
| 2969 |
} {FINE} |
| 2970 |
test namespace-52.9 {unknown: refcounting} -setup { |
| 2971 |
proc this args { |
| 2972 |
unset args ;# stop sharing |
| 2973 |
set copy [namespace unknown] |
| 2974 |
string length $copy ;# shimmer away list rep |
| 2975 |
info level 0 |
| 2976 |
} |
| 2977 |
set handler [namespace unknown] |
| 2978 |
namespace unknown {this is a test} |
| 2979 |
catch {rename noSuchCommand {}} |
| 2980 |
} -body { |
| 2981 |
noSuchCommand |
| 2982 |
} -cleanup { |
| 2983 |
namespace unknown $handler |
| 2984 |
rename this {} |
| 2985 |
} -result {this is a test noSuchCommand} |
| 2986 |
testConstraint testevalobjv [llength [info commands testevalobjv]] |
| 2987 |
test namespace-52.10 {unknown: with TCL_EVAL_GLOBAL} -constraints { |
| 2988 |
testevalobjv |
| 2989 |
} -setup { |
| 2990 |
rename ::unknown unknown.save |
| 2991 |
proc ::unknown args { |
| 2992 |
set caller [uplevel 1 {namespace current}] |
| 2993 |
namespace eval $caller { |
| 2994 |
variable foo |
| 2995 |
return $foo |
| 2996 |
} |
| 2997 |
} |
| 2998 |
catch {rename ::noSuchCommand {}} |
| 2999 |
} -body { |
| 3000 |
namespace eval :: { |
| 3001 |
variable foo SUCCESS |
| 3002 |
} |
| 3003 |
namespace eval test_ns_1 { |
| 3004 |
variable foo FAIL |
| 3005 |
testevalobjv 1 noSuchCommand |
| 3006 |
} |
| 3007 |
} -cleanup { |
| 3008 |
unset -nocomplain ::foo |
| 3009 |
namespace delete test_ns_1 |
| 3010 |
rename ::unknown {} |
| 3011 |
rename unknown.save ::unknown |
| 3012 |
} -result SUCCESS |
| 3013 |
test namespace-52.11 {unknown: with TCL_EVAL_INVOKE} -setup { |
| 3014 |
set handler [namespace eval :: {namespace unknown}] |
| 3015 |
namespace eval :: {namespace unknown unknown} |
| 3016 |
rename ::unknown unknown.save |
| 3017 |
namespace eval :: { |
| 3018 |
proc unknown args { |
| 3019 |
return SUCCESS |
| 3020 |
} |
| 3021 |
} |
| 3022 |
catch {rename ::noSuchCommand {}} |
| 3023 |
set ::child [interp create] |
| 3024 |
} -body { |
| 3025 |
$::child alias bar noSuchCommand |
| 3026 |
namespace eval test_ns_1 { |
| 3027 |
namespace unknown unknown |
| 3028 |
proc unknown args { |
| 3029 |
return FAIL |
| 3030 |
} |
| 3031 |
$::child eval bar |
| 3032 |
} |
| 3033 |
} -cleanup { |
| 3034 |
interp delete $::child |
| 3035 |
unset ::child |
| 3036 |
namespace delete test_ns_1 |
| 3037 |
rename ::unknown {} |
| 3038 |
rename unknown.save ::unknown |
| 3039 |
namespace eval :: [list namespace unknown $handler] |
| 3040 |
} -result SUCCESS |
| 3041 |
test namespace-52.12 {unknown: error case must not reset handler} -body { |
| 3042 |
namespace eval foo { |
| 3043 |
namespace unknown ok |
| 3044 |
catch {namespace unknown {{}{}{}}} |
| 3045 |
namespace unknown |
| 3046 |
} |
| 3047 |
} -cleanup { |
| 3048 |
namespace delete foo |
| 3049 |
} -result ok |
| 3050 |
|
| 3051 |
# TIP 314 - ensembles with parameters |
| 3052 |
test namespace-53.1 {ensembles: parameters} { |
| 3053 |
namespace eval ns { |
| 3054 |
namespace export x |
| 3055 |
proc x {para} {list 1 $para} |
| 3056 |
namespace ensemble create -parameters {para1} |
| 3057 |
} |
| 3058 |
list [info command ns] [ns bar x] [namespace delete ns] [info command ns] |
| 3059 |
} {ns {1 bar} {} {}} |
| 3060 |
test namespace-53.2 {ensembles: parameters} -setup { |
| 3061 |
namespace eval ns { |
| 3062 |
namespace export x |
| 3063 |
proc x {para} {list 1 $para} |
| 3064 |
namespace ensemble create |
| 3065 |
} |
| 3066 |
} -body { |
| 3067 |
namespace ensemble configure ns -parameters {para1} |
| 3068 |
rename ns foo |
| 3069 |
list [info command foo] [foo bar x] [namespace delete ns] [info command foo] |
| 3070 |
} -result {foo {1 bar} {} {}} |
| 3071 |
test namespace-53.3 {ensembles: parameters} -setup { |
| 3072 |
namespace eval ns { |
| 3073 |
namespace export x* |
| 3074 |
proc x1 {para} {list 1 $para} |
| 3075 |
proc x2 {para} {list 2 $para} |
| 3076 |
namespace ensemble create -parameters param1 |
| 3077 |
} |
| 3078 |
} -body { |
| 3079 |
set result [list [ns x2 x1] [ns x1 x2]] |
| 3080 |
lappend result [catch {ns x} msg] $msg |
| 3081 |
lappend result [catch {ns x x} msg] $msg |
| 3082 |
rename ns {} |
| 3083 |
lappend result [info command ns::x1] |
| 3084 |
namespace delete ns |
| 3085 |
lappend result [info command ns::x1] |
| 3086 |
} -result\ |
| 3087 |
{{1 x2} {2 x1}\ |
| 3088 |
1 {wrong # args: should be "ns param1 subcommand ?arg ...?"}\ |
| 3089 |
1 {unknown or ambiguous subcommand "x": must be x1, or x2}\ |
| 3090 |
::ns::x1 {}} |
| 3091 |
test namespace-53.4 {ensembles: parameters} -setup { |
| 3092 |
namespace eval ns { |
| 3093 |
namespace export x* |
| 3094 |
proc x1 {a1 a2} {list 1 $a1 $a2} |
| 3095 |
proc x2 {a1 a2} {list 2 $a1 $a2} |
| 3096 |
proc x3 {a1 a2} {list 3 $a1 $a2} |
| 3097 |
namespace ensemble create |
| 3098 |
} |
| 3099 |
} -body { |
| 3100 |
set result {} |
| 3101 |
lappend result [ns x1 x2 x3] |
| 3102 |
namespace ensemble configure ns -parameters p1 |
| 3103 |
lappend result [ns x1 x2 x3] |
| 3104 |
namespace ensemble configure ns -parameters {p1 p2} |
| 3105 |
lappend result [ns x1 x2 x3] |
| 3106 |
} -cleanup { |
| 3107 |
namespace delete ns |
| 3108 |
} -result {{1 x2 x3} {2 x1 x3} {3 x1 x2}} |
| 3109 |
test namespace-53.5 {ensembles: parameters} -setup { |
| 3110 |
namespace eval ns { |
| 3111 |
namespace export x* |
| 3112 |
proc x1 {para} {list 1 $para} |
| 3113 |
proc x2 {para} {list 2 $para} |
| 3114 |
proc x3 {para} {list 3 $para} |
| 3115 |
namespace ensemble create |
| 3116 |
} |
| 3117 |
} -body { |
| 3118 |
set result [list [catch {ns x x1} msg] $msg] |
| 3119 |
lappend result [catch {ns x1 x} msg] $msg |
| 3120 |
namespace ensemble configure ns -parameters p1 |
| 3121 |
lappend result [catch {ns x1 x} msg] $msg |
| 3122 |
lappend result [catch {ns x x1} msg] $msg |
| 3123 |
} -cleanup { |
| 3124 |
namespace delete ns |
| 3125 |
} -result\ |
| 3126 |
{1 {unknown or ambiguous subcommand "x": must be x1, x2, or x3}\ |
| 3127 |
0 {1 x}\ |
| 3128 |
1 {unknown or ambiguous subcommand "x": must be x1, x2, or x3}\ |
| 3129 |
0 {1 x}} |
| 3130 |
test namespace-53.6 {ensembles: nested} -setup { |
| 3131 |
namespace eval ns { |
| 3132 |
namespace export x* |
| 3133 |
namespace eval x0 { |
| 3134 |
proc z {args} {list 0 $args} |
| 3135 |
namespace export z |
| 3136 |
namespace ensemble create |
| 3137 |
} |
| 3138 |
proc x1 {args} {list 1 $args} |
| 3139 |
proc x2 {args} {list 2 $args} |
| 3140 |
proc x3 {args} {list 3 $args} |
| 3141 |
namespace ensemble create -parameters p |
| 3142 |
} |
| 3143 |
} -body { |
| 3144 |
list [ns z x0] [ns z x1] [ns z x2] [ns z x3] |
| 3145 |
} -cleanup { |
| 3146 |
namespace delete ns |
| 3147 |
} -result {{0 {}} {1 z} {2 z} {3 z}} |
| 3148 |
test namespace-53.7 {ensembles: parameters & wrong # args} -setup { |
| 3149 |
namespace eval ns { |
| 3150 |
namespace export x* |
| 3151 |
proc x1 {a1 a2 a3 a4} {list x1 $a1 $a2 $a3 $a4} |
| 3152 |
namespace ensemble create -parameters p1 |
| 3153 |
} |
| 3154 |
} -body { |
| 3155 |
set result {} |
| 3156 |
lappend result [catch {ns} msg] $msg |
| 3157 |
lappend result [catch {ns x1} msg] $msg |
| 3158 |
lappend result [catch {ns x1 x1} msg] $msg |
| 3159 |
lappend result [catch {ns x1 x1 x1} msg] $msg |
| 3160 |
lappend result [catch {ns x1 x1 x1 x1} msg] $msg |
| 3161 |
lappend result [catch {ns x1 x1 x1 x1 x1} msg] $msg |
| 3162 |
} -cleanup { |
| 3163 |
namespace delete ns |
| 3164 |
} -result\ |
| 3165 |
{1 {wrong # args: should be "ns p1 subcommand ?arg ...?"}\ |
| 3166 |
1 {wrong # args: should be "ns p1 subcommand ?arg ...?"}\ |
| 3167 |
1 {wrong # args: should be "ns x1 x1 a2 a3 a4"}\ |
| 3168 |
1 {wrong # args: should be "ns x1 x1 a2 a3 a4"}\ |
| 3169 |
1 {wrong # args: should be "ns x1 x1 a2 a3 a4"}\ |
| 3170 |
0 {x1 x1 x1 x1 x1}} |
| 3171 |
test namespace-53.8 {ensemble: unknown handler changing -parameters} -setup { |
| 3172 |
namespace eval ns { |
| 3173 |
namespace export x* |
| 3174 |
proc x1 {a1} {list 1 $a1} |
| 3175 |
proc Magic {ensemble subcmd args} { |
| 3176 |
namespace ensemble configure $ensemble\ |
| 3177 |
-parameters [lrange p1 [llength [ |
| 3178 |
namespace ensemble configure $ensemble -parameters |
| 3179 |
]] 0] |
| 3180 |
list |
| 3181 |
} |
| 3182 |
namespace ensemble create -unknown ::ns::Magic |
| 3183 |
} |
| 3184 |
} -body { |
| 3185 |
set result {} |
| 3186 |
lappend result [catch {ns x1 x2} msg] $msg [namespace ensemble configure ns -parameters] |
| 3187 |
lappend result [catch {ns x2 x1} msg] $msg [namespace ensemble configure ns -parameters] |
| 3188 |
lappend result [catch {ns x2 x3} msg] $msg [namespace ensemble configure ns -parameters] |
| 3189 |
} -cleanup { |
| 3190 |
namespace delete ns |
| 3191 |
} -result\ |
| 3192 |
{0 {1 x2} {}\ |
| 3193 |
0 {1 x2} p1\ |
| 3194 |
1 {unknown or ambiguous subcommand "x2": must be x1} {}} |
| 3195 |
test namespace-53.9 {ensemble: unknown handler changing -parameters,\ |
| 3196 |
thereby eating all args} -setup { |
| 3197 |
namespace eval ns { |
| 3198 |
namespace export x* |
| 3199 |
proc x1 {args} {list 1 $args} |
| 3200 |
proc Magic {ensemble subcmd args} { |
| 3201 |
namespace ensemble configure $ensemble\ |
| 3202 |
-parameters {p1 p2 p3 p4 p5} |
| 3203 |
list |
| 3204 |
} |
| 3205 |
namespace ensemble create -unknown ::ns::Magic |
| 3206 |
} |
| 3207 |
} -body { |
| 3208 |
set result {} |
| 3209 |
lappend result [catch {ns x1 x2} msg] $msg [namespace ensemble configure ns -parameters] |
| 3210 |
lappend result [catch {ns x2 x1} msg] $msg [namespace ensemble configure ns -parameters] |
| 3211 |
lappend result [catch {ns a1 a2 a3 a4 a5 x1} msg] $msg [namespace ensemble configure ns -parameters] |
| 3212 |
} -cleanup { |
| 3213 |
namespace delete ns |
| 3214 |
} -result\ |
| 3215 |
{0 {1 x2} {}\ |
| 3216 |
1 {wrong # args: should be "ns p1 p2 p3 p4 p5 subcommand ?arg ...?"} {p1 p2 p3 p4 p5}\ |
| 3217 |
0 {1 {a1 a2 a3 a4 a5}} {p1 p2 p3 p4 p5}} |
| 3218 |
test namespace-53.10 {ensembles: nested rewrite} -setup { |
| 3219 |
namespace eval ns { |
| 3220 |
namespace export x |
| 3221 |
namespace eval x { |
| 3222 |
proc z0 {} {list 0} |
| 3223 |
proc z1 {a1} {list 1 $a1} |
| 3224 |
proc z2 {a1 a2} {list 2 $a1 $a2} |
| 3225 |
proc z3 {a1 a2 a3} {list 3 $a1 $a2 $a3} |
| 3226 |
namespace export z* |
| 3227 |
namespace ensemble create |
| 3228 |
} |
| 3229 |
namespace ensemble create -parameters p |
| 3230 |
} |
| 3231 |
} -body { |
| 3232 |
set result {} |
| 3233 |
# In these cases, parsing the subensemble does not grab a new word. |
| 3234 |
lappend result [catch {ns z0 x} msg] $msg |
| 3235 |
lappend result [catch {ns z1 x} msg] $msg |
| 3236 |
lappend result [catch {ns z2 x} msg] $msg |
| 3237 |
lappend result [catch {ns z2 x v} msg] $msg |
| 3238 |
namespace ensemble configure ns::x -parameters q1 |
| 3239 |
# In these cases, parsing the subensemble grabs a new word. |
| 3240 |
lappend result [catch {ns v x z0} msg] $msg |
| 3241 |
lappend result [catch {ns v x z1} msg] $msg |
| 3242 |
lappend result [catch {ns v x z2} msg] $msg |
| 3243 |
lappend result [catch {ns v x z2 v2} msg] $msg |
| 3244 |
} -cleanup { |
| 3245 |
namespace delete ns |
| 3246 |
} -result\ |
| 3247 |
{0 0\ |
| 3248 |
1 {wrong # args: should be "ns z1 x a1"}\ |
| 3249 |
1 {wrong # args: should be "ns z2 x a1 a2"}\ |
| 3250 |
1 {wrong # args: should be "ns z2 x a1 a2"}\ |
| 3251 |
1 {wrong # args: should be "::ns::x::z0"}\ |
| 3252 |
0 {1 v}\ |
| 3253 |
1 {wrong # args: should be "ns v x z2 a2"}\ |
| 3254 |
0 {2 v v2}} |
| 3255 |
test namespace-53.11 {ensembles: nested rewrite} -setup { |
| 3256 |
namespace eval ns { |
| 3257 |
namespace export x |
| 3258 |
namespace eval x { |
| 3259 |
proc z2 {a1 a2} {list 2 $a1 $a2} |
| 3260 |
namespace export z* |
| 3261 |
namespace ensemble create -parameter p |
| 3262 |
} |
| 3263 |
namespace ensemble create |
| 3264 |
} |
| 3265 |
} -body { |
| 3266 |
list [catch {ns x 1 z2} msg] $msg |
| 3267 |
} -cleanup { |
| 3268 |
namespace delete ns |
| 3269 |
unset -nocomplain msg |
| 3270 |
} -result {1 {wrong # args: should be "ns x 1 z2 a2"}} |
| 3271 |
|
| 3272 |
test namespace-54.1 {leak on namespace deletion} -constraints {memory} \ |
| 3273 |
-setup { |
| 3274 |
proc getbytes {} { |
| 3275 |
set lines [split [memory info] "\n"] |
| 3276 |
lindex $lines 3 3 |
| 3277 |
} |
| 3278 |
} -body { |
| 3279 |
set end [getbytes] |
| 3280 |
for {set i 0} {$i < 5} {incr i} { |
| 3281 |
set ns ::y$i |
| 3282 |
namespace eval $ns {} |
| 3283 |
namespace delete $ns |
| 3284 |
set start $end |
| 3285 |
set end [getbytes] |
| 3286 |
} |
| 3287 |
set leakedBytes [expr {$end - $start}] |
| 3288 |
} -cleanup { |
| 3289 |
rename getbytes {} |
| 3290 |
unset i ns start end |
| 3291 |
} -result 0 |
| 3292 |
|
| 3293 |
test namespace-55.1 {compiled ensembles inside compiled ensembles: Bug 6d2f249a01} { |
| 3294 |
info class [format %s constructor] oo::object |
| 3295 |
} "" |
| 3296 |
|
| 3297 |
test namespace-55.2 {compiled ensembles inside safe interpreters (for safe sub-commands), bug [1095bf7f756f9aed]} -setup { |
| 3298 |
interp create -safe si |
| 3299 |
set code { |
| 3300 |
proc test_comp_dict d { dict for {k v} $d {expr $v} } |
| 3301 |
regexp -inline {Command 1:(?:[^\n]*\n){1,5}} [::tcl::unsupported::disassemble proc test_comp_dict] |
| 3302 |
} |
| 3303 |
} -body { |
| 3304 |
set a [ eval $code] |
| 3305 |
set b [si eval $code] |
| 3306 |
list [expr {$a eq $b}] [regexp { dictFirst } $a] [regexp { dictFirst } $b] $a $b |
| 3307 |
} -cleanup { |
| 3308 |
rename test_comp_dict {} |
| 3309 |
unset -nocomplain code a b |
| 3310 |
interp delete si |
| 3311 |
} -match glob -result {1 1 1 *} |
| 3312 |
|
| 3313 |
test namespace-56.1 {bug f97d4ee020: mutually-entangled deletion} { |
| 3314 |
namespace eval ::testing { |
| 3315 |
proc abc {} {} |
| 3316 |
proc def {} {} |
| 3317 |
trace add command abc delete "rename ::testing::def {}; #" |
| 3318 |
trace add command def delete "rename ::testing::abc {}; #" |
| 3319 |
} |
| 3320 |
namespace delete ::testing |
| 3321 |
} {} |
| 3322 |
test namespace-56.2 {bug f97d4ee020: mutually-entangled deletion} { |
| 3323 |
namespace eval ::testing { |
| 3324 |
namespace eval abc {proc xyz {} {}} |
| 3325 |
namespace eval def {proc xyz {} {}} |
| 3326 |
trace add command abc::xyz delete "namespace delete ::testing::def {}; #" |
| 3327 |
trace add command def::xyz delete "namespace delete ::testing::abc {}; #" |
| 3328 |
} |
| 3329 |
namespace delete ::testing |
| 3330 |
} {} |
| 3331 |
test namespace-56.3 {bug f97d4ee020: mutually-entangled deletion} { |
| 3332 |
namespace eval ::testing { |
| 3333 |
variable gone {} |
| 3334 |
oo::class create CB { |
| 3335 |
variable cmd |
| 3336 |
constructor other {set cmd $other} |
| 3337 |
destructor {rename $cmd {}; lappend ::testing::gone $cmd} |
| 3338 |
} |
| 3339 |
namespace eval abc { |
| 3340 |
::testing::CB create def ::testing::abc::ghi |
| 3341 |
::testing::CB create ghi ::testing::abc::def |
| 3342 |
} |
| 3343 |
namespace delete abc |
| 3344 |
try { |
| 3345 |
return [lsort $gone] |
| 3346 |
} finally { |
| 3347 |
namespace delete ::testing |
| 3348 |
} |
| 3349 |
} |
| 3350 |
} {::testing::abc::def ::testing::abc::ghi} |
| 3351 |
|
| 3352 |
test namespace-56.4 {bug 16fe1b5807: names starting with ":"} knownBug { |
| 3353 |
namespace eval : { |
| 3354 |
namespace ensemble create |
| 3355 |
namespace export * |
| 3356 |
proc p1 {} { |
| 3357 |
return 16fe1b5807 |
| 3358 |
} |
| 3359 |
} |
| 3360 |
|
| 3361 |
: p1 |
| 3362 |
} 16fe1b5807 |
| 3363 |
|
| 3364 |
test namespace-56.5 {Bug 8b9854c3d8} -setup { |
| 3365 |
namespace eval namespace-56.5 { |
| 3366 |
proc cmd {} {string match ::* [lindex [[string cat info] level 0] 0]} |
| 3367 |
namespace export * |
| 3368 |
namespace ensemble create |
| 3369 |
} |
| 3370 |
} -body { |
| 3371 |
namespace-56.5 cmd |
| 3372 |
} -cleanup { |
| 3373 |
namespace delete namespace-56.5 |
| 3374 |
} -result 1 |
| 3375 |
|
| 3376 |
|
| 3377 |
test namespace-56.6 { |
| 3378 |
Namespace deletion traces on both the original routine and the imported |
| 3379 |
routine should run without any memory error under a debug build. |
| 3380 |
} -body { |
| 3381 |
variable res 0 |
| 3382 |
|
| 3383 |
proc ondelete {old new op} { |
| 3384 |
$old |
| 3385 |
} |
| 3386 |
|
| 3387 |
namespace eval ns1 {} { |
| 3388 |
namespace export * |
| 3389 |
proc p1 {} { |
| 3390 |
namespace upvar [namespace parent] res res |
| 3391 |
incr res |
| 3392 |
} |
| 3393 |
trace add command p1 delete ondelete |
| 3394 |
} |
| 3395 |
|
| 3396 |
namespace eval ns2 {} { |
| 3397 |
namespace import ::ns1::p1 |
| 3398 |
trace add command p1 delete ondelete |
| 3399 |
} |
| 3400 |
|
| 3401 |
namespace delete ns1 |
| 3402 |
namespace delete ns2 |
| 3403 |
return $res |
| 3404 |
} -cleanup { |
| 3405 |
unset res |
| 3406 |
rename ondelete {} |
| 3407 |
} -result 2 |
| 3408 |
|
| 3409 |
|
| 3410 |
test namespace-57.0 { |
| 3411 |
an imported alias should be usable in the deletion trace for the alias |
| 3412 |
|
| 3413 |
see 29e8848eb976 |
| 3414 |
} -body { |
| 3415 |
variable res {} |
| 3416 |
namespace eval ns2 { |
| 3417 |
namespace export * |
| 3418 |
proc p1 {oldname newname op} { |
| 3419 |
return success |
| 3420 |
} |
| 3421 |
|
| 3422 |
interp alias {} [namespace current]::p2 {} [namespace which p1] |
| 3423 |
} |
| 3424 |
|
| 3425 |
|
| 3426 |
namespace eval ns3 { |
| 3427 |
namespace import ::ns2::p2 |
| 3428 |
} |
| 3429 |
|
| 3430 |
|
| 3431 |
set ondelete [list apply [list {oldname newname op} { |
| 3432 |
variable res |
| 3433 |
catch { |
| 3434 |
ns3::p2 $oldname $newname $op |
| 3435 |
} cres |
| 3436 |
lappend res $cres |
| 3437 |
} [namespace current]]] |
| 3438 |
|
| 3439 |
|
| 3440 |
trace add command ::ns2::p2 delete $ondelete |
| 3441 |
rename ns2::p2 {} |
| 3442 |
return $res |
| 3443 |
} -cleanup { |
| 3444 |
unset res |
| 3445 |
namespace delete ns2 |
| 3446 |
namespace delete ns3 |
| 3447 |
} -result success |
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
# cleanup |
| 3453 |
catch {rename cmd1 {}} |
| 3454 |
catch {unset l} |
| 3455 |
catch {unset msg} |
| 3456 |
catch {unset trigger} |
| 3457 |
namespace delete {*}[namespace children :: test_ns_*] |
| 3458 |
::tcltest::cleanupTests |
| 3459 |
return |
| 3460 |
|
| 3461 |
# Local Variables: |
| 3462 |
# mode: tcl |
| 3463 |
# End: |