Tcl Library Source Code

Check-in [dc845d0c83]
Login
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Integrated Andrew Mangogna's and Nathan Coulter's work on namespacex, with thanks.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: dc845d0c839fe30c2358c91016f106b7c970eba35fb5293ac40667f4ab913c1e
User & Date: aku 2019-03-02 04:18:30
References
2019-06-25
20:08 Closed ticket [a2def27cd9]: The documentation of namespacex is incomplete plus 6 other changes artifact: 491de69eff user: aku
Context
2019-03-06
07:06
Regenerated documentation. check-in: 08c384a6c3 user: aku tags: trunk
04:30
Start overhaul of global docs (for the system, not packages). check-in: 4b85cfed9b user: aku tags: doc-overhaul
2019-03-02
04:18
Integrated Andrew Mangogna's and Nathan Coulter's work on namespacex, with thanks. check-in: dc845d0c83 user: aku tags: trunk
04:17
namespacex - Fill in Extended testsuite to cover new commands `normalize` and `strip`. Extended testsuite to cover wrong#args for `import`. Fixed typo in documentation of `strip`. Split `strip` into public and internal forms, with the public form performing argument normalization and checking not required by the internal form (*), and documented for the public. (*) The internal form has only a minimal check asserting that the prefix namespace is given as an FQN. Closed-Leaf check-in: e993dd5c68 user: aku tags: gam-namespacex-improve
2019-02-26
06:07
Tkt [6e778502b8]. Merged fix for -- handling in `flatten`. check-in: 7963b3dbaf user: aku tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/namespacex/namespacex.man.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21


















22
23
24
25
26
















27












28

















29
30


















31
32
33
34
35
36
37
38
39
40
41






42
43
44
45
46




47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71







72



73
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin namespacex n 0.1]
[keywords {extended namespace}]
[keywords info]
[keywords {namespace unknown}]
[keywords {namespace utilities}]
[keywords {state (de)serialization}]
[keywords {unknown hooking}]
[keywords utilities]
[copyright {200? Neil Madden (http://wiki.tcl.tk/12790)}]
[copyright {200? Various (http://wiki.tcl.tk/1489)}]
[copyright {2010 Documentation, Andreas Kupries}]
[moddesc   {Namespace utility commands}]
[titledesc {Namespace utility commands}]
[require Tcl 8.5]
[require namespacex [opt 0.1]]
[description]

This package provides a number of utility commands for working with
namespaces.



















[section API]

[list_begin definitions]

[call [cmd {::namespacex hook add}]  [opt [arg namespace]] [arg cmdprefix]]
















[call [cmd {::namespacex hook proc}] [opt [arg namespace]] [arg arguments] [arg body]]












[call [cmd {::namespacex hook on}]   [opt [arg namespace]] [arg guardcmdprefix] [arg actioncmdprefix]]

















[call [cmd {::namespacex hook next}] [arg arg]...]



















[call [cmd {::namespacex info allchildren}] [arg namespace]]

This command returns a list containing the names of all child
namespaces in the specified [arg namespace] and its children. The
names are all fully qualified.

[call [cmd {::namespacex info allvars}] [arg namespace]]

This command returns a list containing the names of all variables in
the specified [arg namespace] and its children. The names are all
relative to [arg namespace], and [emph not] fully qualified.







[call [cmd {::namespacex info vars}] [arg namespace] [opt [arg pattern]]]

This command returns a list containing the names of all variables in
the specified [arg namespace].





[call [cmd {::namespacex state get}] [arg namespace]]

This command returns a dictionary holding the names and values of all
variables in the specified [arg namespace] and its child namespaces.

[para]
Note that the names are all relative to [arg namespace],
and [emph not] fully qualified.

[call [cmd {::namespacex state set}] [arg namespace] [arg dict]]

This command takes a dictionary holding the names and values for a set
of variables and replaces the current state of the specified
[arg namespace] and its child namespaces with this state.

The result of the command is the empty string.

[call [cmd {::namespacex state drop}] [arg namespace]]

This command unsets all variables in the specified [arg namespace] and
its child namespaces.

The result of the command is the empty string.








[list_end]



[manpage_end]
>

|













|





>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|




>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>


|
|
|



|
|
|
>
>
>
>
>
>



|

>
>
>
>



|
|

<
|
|



|
|
|





|
|



>
>
>
>
>
>
>

>
>
>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
[vset VERSION 0.2]
[comment {-*- tcl -*- doctools manpage}]
[manpage_begin namespacex n [vset VERSION]]
[keywords {extended namespace}]
[keywords info]
[keywords {namespace unknown}]
[keywords {namespace utilities}]
[keywords {state (de)serialization}]
[keywords {unknown hooking}]
[keywords utilities]
[copyright {200? Neil Madden (http://wiki.tcl.tk/12790)}]
[copyright {200? Various (http://wiki.tcl.tk/1489)}]
[copyright {2010 Documentation, Andreas Kupries}]
[moddesc   {Namespace utility commands}]
[titledesc {Namespace utility commands}]
[require Tcl 8.5]
[require namespacex [opt [vset VERSION]]]
[description]

This package provides a number of utility commands for working with
namespaces.

The commands fall into four categories:

[list_begin enumerated]

[enum] Hook commands provide and manipulate a chain of commands which
replaces the single regular [cmd "namespace unknown"] handler.

[enum] An import command provides the ability to import any command
from another namespace.

[enum] Information commands allow querying of variables and child
namespaces.

[enum] State commands provide a means to serialize variable values in
a namespace.

[list_end]

[section Commands]

[list_begin definitions]

[call [cmd {::namespacex hook add}]  [opt [arg namespace]] [arg cmdprefix]]

Adds the [arg cmdprefix] to the chain of unknown command handlers that
are invoked when the [arg namespace] would otherwise invoke its
unknown handler.

If [arg namespace] is not specified, then [arg cmdprefix] is added to
the chain of handlers for the namespace of the caller.

[para]
The chain of [arg cmdprefix] are executed in reverse order of
addition, [emph i.e.] the most recently added [arg cmdprefix] is
executed first.

When executed, [arg cmdprefix] has additional arguments appended to it
as would any namespace unknown handler.

[call [cmd {::namespacex hook proc}] [opt [arg namespace]] \
     [arg arguments] [arg body]]

Adds an anonymous procedure to the chain of namespace unknown handlers
for the [arg namespace].

[para] If [arg namespace] is not specified, then the handler is added
to the chain of handlers for the namespace of the caller.

[para] The [arg arguments] and [arg body] are specified as for the
core [cmd proc] command.

[call [cmd {::namespacex hook on}] [opt [arg namespace]] \
     [arg guardcmdprefix] [arg actioncmdprefix]]

Adds a guarded action to the chain of namespace unknown handlers for
the [arg namespace].

[para] If [arg namespace] is not specified, then the handler is added
to the chain of handlers for the namespace of the caller.

[para] The [arg guardcmdprefix] is executed first. If it returns a
value that can be interpreted as false, then the next unknown hander
in the chain is executed. Otherwise, [arg actioncmdprefix] is executed
and the return value of the handler is the value returned by
[arg actioncmdprefix].

[para] When executed, both [arg guardcmdprefix] and
[arg actioncmdprefix] have the same additional arguments appended as
for any namespace unknown handler.

[call [cmd {::namespacex hook next}] [arg arg]...]

This command is available to namespace hooks to execute the next hook
in the chain of handlers for the namespace.

[call [cmd {::namespacex import fromns}] [arg "cmdname [opt "[arg newname] ..."]"]]

Imports the command [arg cmdname] from the [arg fromns] namespace into
the namespace of the caller.

The [arg cmdname] command is imported even if the [arg fromns] did not
originally export the command.

[para] If [arg newname] is specified, then the imported command will
be known by that name. Otherwise, the command retains is original name
as given by [arg cmdname].

[para] Additional pairs of [arg cmdname] / [arg newname] arguments may
also be specified.

[call [cmd {::namespacex info allchildren}] [arg namespace]]

Returns a list containing the names of all child namespaces in the
specified [arg namespace] and its children. The names are all fully
qualified.

[call [cmd {::namespacex info allvars}] [arg namespace]]

Returns a list containing the names of all variables in the specified
[arg namespace] and its children. The names are all given relative to
[arg namespace], and [emph not] fully qualified.

[call [cmd {::namespacex normalize}] [arg namespace]]

Returns the absolute name of [arg namespace], which is resolved
relative to the namespace of the caller, with all unneeded colon
characters removed.

[call [cmd {::namespacex info vars}] [arg namespace] [opt [arg pattern]]]

Returns a list containing the names of all variables in
the specified [arg namespace].

If the [arg pattern] argument is specified, then only variables
matching [arg pattern] are returned. Matching is determined using the
same rules as for [cmd {string match}].

[call [cmd {::namespacex state get}] [arg namespace]]

Returns a dictionary holding the names and values of all variables in
the specified [arg namespace] and its child namespaces.


[para] Note that the names are all relative to [arg namespace], and
[emph not] fully qualified.

[call [cmd {::namespacex state set}] [arg namespace] [arg dict]]

Takes a dictionary holding the names and values for a set of variables
and replaces the current state of the specified [arg namespace] and
its child namespaces with this state.

The result of the command is the empty string.

[call [cmd {::namespacex state drop}] [arg namespace]]

Unsets all variables in the specified [arg namespace] and its child
namespaces.

The result of the command is the empty string.

[call [cmd {::namespacex strip}] [arg prefix] [arg namespaces]]

Each item in [arg namespaces] must be the absolute normalized name of
a child namespace of namespace [arg prefix].

Returns the corresponding list of relative names of child namespaces.

[list_end]

[vset CATEGORY namespacex]
[include ../doctools2base/include/feedback.inc]
[manpage_end]

Changes to modules/namespacex/namespacex.tcl.

9
10
11
12
13
14
15
16









17
18
19
20
21
22
23
24
25
...
178
179
180
181
182
183
184
185
186

187























188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

206
207
208

209












210
211
212
213
214



215









216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# namespacex info  - Get all variables/children, direct and indirect
# namespacex state - Save/restore the variable-based state of namespaces.

# # ## ### ##### ######## ############# ######################
## Requisites

package require Tcl 8.5  ; # namespace ensembles, {*}










namespace eval ::namespacex {
    namespace export add hook info state
    namespace ensemble create

    namespace eval hook {
	namespace export add proc on next
	namespace ensemble create

	# add - hook a command prefix into the chain of unknown handlers for a
................................................................................
    } else {
        return -code $rc $result
    }
}

# # ## ### ##### ######## ############# ######################
## Implementation :: Info - Visible API

proc ::namespacex::info::allvars {ns} {

    if {![string match {::*} $ns]} { set ns ::$ns }























    ::set result [::info vars ${ns}::*]
    foreach cns [allchildren $ns] {
	lappend result {*}[::info vars ${cns}::*]
    }
    return [Strip $ns $result]
}

proc ::namespacex::info::allchildren {ns} {
    if {![string match {::*} $ns]} { set ns ::$ns }
    ::set result [list]
    foreach cns [::namespace children $ns] {
	lappend result {*}[allchildren $cns]
	lappend result $cns
    }
    return $result
}

proc ::namespacex::info::vars {ns {pattern *}} {

    return [Strip $ns [::info vars ${ns}::$pattern]]
}


proc ::namespacex::info::Strip {ns itemlist} {












    set n [string length $ns]
    if {![string match {::*} $ns]} {
	incr n 4
    } else {
	incr n 2



    }










    set result {}
    foreach i $itemlist {
	lappend result [string range $i $n end]
    }
    return $result
}

# # ## ### ##### ######## ############# ######################
## Implementation :: State - Visible API

proc ::namespacex::state::drop {ns} {
    if {![string match {::*} $ns]} { ::set ns ::$ns }
    namespace eval $ns [list ::unset {*}[::namespacex info allvars $ns]]
    return
}

proc ::namespacex::state::get {ns} {
    if {![string match {::*} $ns]} { ::set ns ::$ns }
    ::set result {}
    foreach v [::namespacex info allvars $ns] {
	namespace upvar $ns $v value
	lappend result $v $value
    }
    return $result
}

proc ::namespacex::state::set {ns state} {
    if {![string match {::*} $ns]} { ::set ns ::$ns }
    # Inlined 'state drop'.
    namespace eval $ns [list ::unset  {*}[::namespacex info allvars $ns]]
    namespace eval $ns [list variable {*}$state]
    return
}

# # ## ### ##### ######## ############# ######################
## Ready

package provide namespacex 0.1







>
>
>
>
>
>
>
>
>

|







 








|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




|



|









>
|


>
|
>
>
>
>
>
>
>
>
>
>
>
>

<
|
<
<
>
>
>

>
>
>
>
>
>
>
>
>












|





|









|









|
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
...
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

258


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
# namespacex info  - Get all variables/children, direct and indirect
# namespacex state - Save/restore the variable-based state of namespaces.

# # ## ### ##### ######## ############# ######################
## Requisites

package require Tcl 8.5  ; # namespace ensembles, {*}

# The try command is used in the namespacex::import command. For
# backward compatibility we will use the try package from tcllib if
# running on a platform that does not have it as a core command,
# i.e. before 8.6.

if {![llength [info commands try]]} {
    package require try ; # tcllib
}

namespace eval ::namespacex {
    namespace export add hook info import normalize strip state
    namespace ensemble create

    namespace eval hook {
	namespace export add proc on next
	namespace ensemble create

	# add - hook a command prefix into the chain of unknown handlers for a
................................................................................
    } else {
        return -code $rc $result
    }
}

# # ## ### ##### ######## ############# ######################
## Implementation :: Info - Visible API

proc ::namespacex::import {from args} {
    set upns [uplevel 1 {::namespace current}]
    if {![string match ::* $from]} {
	set from ${upns}::$from[set from {}]
    }
    set orig [namespace eval $from {::namespace export}]
    try {
	namespace eval $from {::namespace export *}
	set tmp [::namespace current]::[::info cmdcount]
	namespace eval $tmp [list ::namespace import ${from}::*]
	if {[llength $args] == 1} {
	    lappend args [lindex $args 0]
	}
	dict size $args
	foreach {old new} $args {
	    rename ${tmp}::$old ${upns}::$new
	}
	namespace delete $tmp
    } finally {
	namespace eval $from [list ::namespace export -clear {*}$orig]
    }
    return
}

proc ::namespacex::info::allvars {ns} {
    set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    ::set result [::info vars ${ns}::*]
    foreach cns [allchildren $ns] {
	lappend result {*}[::info vars ${cns}::*]
    }
    return [::namespacex::Strip $ns $result]
}

proc ::namespacex::info::allchildren {ns} {
    set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    ::set result [list]
    foreach cns [::namespace children $ns] {
	lappend result {*}[allchildren $cns]
	lappend result $cns
    }
    return $result
}

proc ::namespacex::info::vars {ns {pattern *}} {
    set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    return [::namespacex::Strip $ns [::info vars ${ns}::$pattern]]
}

# this implementation avoids string operations
proc ::namespacex::normalize {ns} {
    if {[uplevel 1 [list ::namespace exists $ns]]} {
	return [uplevel 1 [list namespace eval $ns {::namespace current}]]
    }
    if {![string match ::* $ns]} {
	set ns [uplevel 1 {::namespace current}]::$ns
    }
    regsub {::+} $ns :: ns
    return $ns
}

proc ::namespacex::strip {ns itemlist} {
    set ns [uplevel 1 [list [namespace current] normalize $ns]]
    set n [string length $ns]

    incr n -1


    foreach i $itemlist {
	if {[string range $i 0 $n] eq "$ns"} continue
	return -code error "Expected $ns as prefix for $i, not found"
    }
    return [Strip $ns $itemlist]
}

proc ::namespacex::Strip {ns itemlist} {
    # Assert: is-fqn (ns)
    if {![string match {::*} $ns]} { error "Expected fqn for ns" }
    
    set n [string length $ns]
    incr n 2

    set result {}
    foreach i $itemlist {
	lappend result [string range $i $n end]
    }
    return $result
}

# # ## ### ##### ######## ############# ######################
## Implementation :: State - Visible API

proc ::namespacex::state::drop {ns} {
    ::set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    namespace eval $ns [list ::unset {*}[::namespacex info allvars $ns]]
    return
}

proc ::namespacex::state::get {ns} {
    ::set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    ::set result {}
    foreach v [::namespacex info allvars $ns] {
	namespace upvar $ns $v value
	lappend result $v $value
    }
    return $result
}

proc ::namespacex::state::set {ns state} {
    ::set ns [uplevel 1 [list [namespace parent] normalize $ns]]
    # Inlined 'state drop'.
    namespace eval $ns [list ::unset  {*}[::namespacex info allvars $ns]]
    namespace eval $ns [list variable {*}$state]
    return
}

# # ## ### ##### ######## ############# ######################
## Ready

package provide namespacex 0.2

Changes to modules/namespacex/namespacex.test.

11
12
13
14
15
16
17

18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46








47

48









































































































































49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72










73

74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89


















90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106


















107

108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132










133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148










149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164










165

166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190










191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206










207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222










223

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250











251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268











269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286











287

288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322














323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344















345
346
347
348
349
350
351
testsNeedTcltest 2.0

testing {
    useLocal namespacex.tcl namespacex
}

# -------------------------------------------------------------------------


proc ns_setup {} {
    namespace eval ::X {
        namespace eval A {}
        namespace eval B {
            namespace eval D {}
        }
        namespace eval C {}
    }
}

proc ns2_setup {} {
    namespace eval ::X {
        variable vXa 1
        variable vXb aleph
        namespace eval B {
            variable vB 3
        }
    }
}

proc ns3_setup {} {
    namespace eval ::X {
        namespace eval B {
            variable vB mjolnir
        }
    }
}









# -------------------------------------------------------------------------











































































































































test namespacex-info-allchildren-1.0 {namespacex info allchildren, wrong\#args} -body {
    namespacex info allchildren
} -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}

test namespacex-info-allchildren-1.1 {namespacex info allchildren, wrong\#args} -body {
    namespacex info allchildren N X
} -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}

test namespacex-info-allchildren-2.0.0 {namespacex info allchildren} -setup {
    ns_setup
} -body {
    lsort -dict [namespacex info allchildren ::X]
} -cleanup {
    namespace delete ::X
} -result {::X::A ::X::B ::X::B::D ::X::C}

test namespacex-info-allchildren-2.0.1 {namespacex info allchildren} -setup {
    ns_setup
} -body {
    lsort -dict [namespacex info allchildren X]
} -cleanup {
    namespace delete ::X
} -result {::X::A ::X::B ::X::B::D ::X::C}











# -------------------------------------------------------------------------


test namespacex-info-vars-1.0 {namespacex info vars, wrong\#args} -body {
    namespacex info vars
} -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}

test namespacex-info-vars-1.1 {namespacex info vars, wrong\#args} -body {
    namespacex info vars N P X
} -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}

test namespacex-info-vars-2.0 {namespacex info vars} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {vXa vXb}



















test namespacex-info-vars-2.1 {namespacex info vars} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-vars-2.2 {namespacex info vars} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {}



















# -------------------------------------------------------------------------


test namespacex-info-allvars-1.0 {namespacex info allvars, wrong\#args} -body {
    namespacex info allvars
} -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}

test namespacex-info-allvars-1.1 {namespacex info allvars, wrong\#args} -body {
    namespacex info allvars N X
} -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}

test namespacex-info-allvars-2.0.0 {namespacex info allvars} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB vXa vXb}

test namespacex-info-allvars-2.0.1 {namespacex info allvars} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {B::vB vXa vXb}











test namespacex-info-allvars-2.1.0 {namespacex info allvars} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-allvars-2.1.1 {namespacex info allvars} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {}











test namespacex-info-allvars-2.2.0 {namespacex info allvars} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB}

test namespacex-info-allvars-2.2.1 {namespacex info allvars} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {B::vB}











# -------------------------------------------------------------------------


test namespacex-state-get-1.0 {namespacex state get, wrong\#args} -body {
    namespacex state get
} -returnCodes error -result {wrong # args: should be "namespacex state get ns"}

test namespacex-state-get-1.1 {namespacex state get, wrong\#args} -body {
    namespacex state get N X
} -returnCodes error -result {wrong # args: should be "namespacex state get ns"}

test namespacex-state-get-2.0.0 {namespacex state get} -setup {
    ns2_setup
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-get-2.0.1 {namespacex state get} -setup {
    ns2_setup
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}











test namespacex-state-get-2.1.0 {namespacex state get} -setup {
    namespace eval ::X {}
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-get-2.1.1 {namespacex state get} -setup {
    namespace eval ::X {}
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}











test namespacex-state-get-2.2.0 {namespacex state get} -setup {
    ns3_setup
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-get-2.2.1 {namespacex state get} -setup {
    ns3_setup
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}











# -------------------------------------------------------------------------


test namespacex-state-drop-1.0 {namespacex state drop, wrong\#args} -body {
    namespacex state drop
} -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}

test namespacex-state-drop-1.1 {namespacex state drop, wrong\#args} -body {
    namespacex state drop N X
} -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}

test namespacex-state-drop-2.0.0 {namespacex state drop} -setup {
    ns2_setup
} -body {
    namespacex state drop ::X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.0.1 {namespacex state drop} -setup {
    ns2_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}












test namespacex-state-drop-2.1.0 {namespacex state drop} -setup {
    namespace eval ::X {}
} -body {
    namespacex state drop X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.1.1 {namespacex state drop} -setup {
    namespace eval ::X {}
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}












test namespacex-state-drop-2.2.0 {namespacex state drop} -setup {
    ns3_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.2.1 {namespacex state drop} -setup {
    ns3_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}












# -------------------------------------------------------------------------


test namespacex-state-set-1.0 {namespacex state set, wrong\#args} -body {
    namespacex state set
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-1.1 {namespacex state set, wrong\#args} -body {
    namespacex state set N
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-1.2 {namespacex state set, wrong\#args} -body {
    namespacex state set N S X
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-2.0.0 {namespacex state set} -setup {
    ns2_setup
    set ST [namespacex state get ::X]
    ns3_setup
} -body {
    namespacex state set ::X $ST
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-set-2.0.1 {namespacex state set} -setup {
    ns2_setup
    set ST [namespacex state get ::X]
    ns3_setup
} -body {
    namespacex state set X $ST
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}















test namespacex-state-set-2.1.0 {namespacex state set} -setup {
    ns3_setup
    set ST [namespacex state get ::X]
    ns2_setup
} -body {
    namespacex state set ::X $ST
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-set-2.1.1 {namespacex state set} -setup {
    ns3_setup
    set ST [namespacex state get ::X]
    ns2_setup
} -body {
    namespacex state set X $ST
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}
















# -------------------------------------------------------------------------
testsuiteCleanup

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End:






>

|
|








|
|








|
|






>
>
>
>
>
>
>
>

>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|



|



|







|







>
>
>
>
>
>
>
>
>
>

>

|



|



|






>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>









|







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

>

|



|



|







|







>
>
>
>
>
>
>
>
>
>
|







|







>
>
>
>
>
>
>
>
>
>
|







|







>
>
>
>
>
>
>
>
>
>

>

|



|



|







|







>
>
>
>
>
>
>
>
>
>
|







|







>
>
>
>
>
>
>
>
>
>
|







|







>
>
>
>
>
>
>
>
>
>

>

|



|



|








|








>
>
>
>
>
>
>
>
>
>
>
|








|








>
>
>
>
>
>
>
>
>
>
>
|








|








>
>
>
>
>
>
>
>
>
>
>

>

|



|



|



|










|










>
>
>
>
>
>
>
>
>
>
>
>
>
>
|










|










>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
testsNeedTcltest 2.0

testing {
    useLocal namespacex.tcl namespacex
}

# -------------------------------------------------------------------------
## helpers

proc ns_setup {{parent {}}} {
    namespace eval ${parent}::X {
        namespace eval A {}
        namespace eval B {
            namespace eval D {}
        }
        namespace eval C {}
    }
}

proc ns2_setup {{parent {}}} {
    namespace eval ${parent}::X {
        variable vXa 1
        variable vXb aleph
        namespace eval B {
            variable vB 3
        }
    }
}

proc ns3_setup {{parent {}}} {
    namespace eval ${parent}::X {
        namespace eval B {
            variable vB mjolnir
        }
    }
}

if {[package vsatisfies [package present Tcl] 8.6]} {
    # 8.6+ args => ?arg ...?
    proc E {text} { string map [list "..." "?arg ...?"] $text }
} else {
    # 8.5- args => ...
    proc E {text} { set text }
}

# -------------------------------------------------------------------------
## hook add

test namespacex-hook-add-1.0 {
    namespacex hook add: add a single hook
} -setup {
    variable hadd1 20

    proc h {args} {
        variable hadd1
        set hadd1 40
        return
    }
    namespace eval ::testHook {
        proc testProc {} {
            foo a b c
        }
    }
} -cleanup {
    namespace delete ::testHook
    rename h {}
} -body {
    namespacex hook add ::testHook [namespace code h]
    ::testHook::testProc
    return $hadd1
} -result {40}

# -------------------------------------------------------------------------
## normalize

test namespacex-normalize-1.0 {namespacex normalize, wrong\#args, not enough} -body {
    namespacex normalize
} -returnCodes error -result {wrong # args: should be "namespacex normalize ns"}

test namespacex-normalize-1.1 {namespacex normalize, wrong\#args, too many} -body {
    namespacex normalize N X
} -returnCodes error -result {wrong # args: should be "namespacex normalize ns"}

test namespacex-normalize-2.0.0 {namespacex normalize, fqn} -body {
    namespacex normalize ::X
} -result {::X}

test namespacex-normalize-2.0.1 {namespacex normalize, relative to global} -body {
    namespacex normalize X
} -result {::X}

test namespacex-normalize-2.0.2 {namespacex normalize, relative to non-global} -body {
    namespace eval ::Q {
        namespacex normalize X
    }
} -cleanup {
    namespace delete ::Q
} -result {::Q::X}

# -------------------------------------------------------------------------
## strip

test namespacex-strip-1.0 {namespacex strip, wrong\#args, not enough} -body {
    namespacex strip
} -returnCodes error -result {wrong # args: should be "namespacex strip ns itemlist"}

test namespacex-strip-1.1 {namespacex strip, wrong\#args, not enough} -body {
    namespacex strip N
} -returnCodes error -result {wrong # args: should be "namespacex strip ns itemlist"}

test namespacex-strip-1.2 {namespacex strip, wrong\#args, too many} -body {
    namespacex strip N I X
} -returnCodes error -result {wrong # args: should be "namespacex strip ns itemlist"}

test namespacex-strip-2.0 {namespacex strip, bad child, relative} -body {
    namespacex strip ::X {Q}
} -returnCodes error -result {Expected ::X as prefix for Q, not found}

test namespacex-strip-2.1 {namespacex strip, bad child, absolute} -body {
    namespacex strip ::X {::Q}
} -returnCodes error -result {Expected ::X as prefix for ::Q, not found}

test namespacex-strip-2.1 {namespacex strip, proper children} -body {
    namespacex strip ::X {::X ::X::Q}
} -result {{} Q}

# -------------------------------------------------------------------------
## import

test namespacex-import-1.0 {namespacex import, wrong\#args, not enough} -body {
    namespacex import
} -returnCodes error -result [E {wrong # args: should be "namespacex import from ..."}]

test namespacex-import-2.0 {
    namespacex import from a child namespace
} -setup {
    namespace eval importTest {
        proc t {} {
            return [namespace current]
        }
    }
} -cleanup {
    namespace delete importTest
} -body {
    namespacex import importTest t
    t
} -result ::importTest

test namespacex-import-2.1 {
    namespacex import from fully qualified namespace
} -setup {
    namespace eval ::importTest {
        proc t {} {
            return [namespace current]
        }
    }
} -cleanup {
    namespace delete ::importTest
} -body {
    namespacex import ::importTest t
    t
} -result {::importTest}

test namespacex-import-2.2 {
    namespacex import multiple commands
} -setup {
    namespace eval ::importTest {
        proc a {} {
            return "a: [namespace current]"
        }
        proc b {} {
            return "b: [namespace current]"
        }
    }
} -cleanup {
    namespace delete ::importTest
} -body {
    namespacex import ::importTest a myA b myB
    append result [myA] " " [myB]
    return $result
} -result {a: ::importTest b: ::importTest}

# -------------------------------------------------------------------------
## info allchildren

test namespacex-info-allchildren-1.0 {namespacex info allchildren, wrong\#args, not enough} -body {
    namespacex info allchildren
} -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}

test namespacex-info-allchildren-1.1 {namespacex info allchildren, wrong\#args, too many} -body {
    namespacex info allchildren N X
} -returnCodes error -result {wrong # args: should be "namespacex info allchildren ns"}

test namespacex-info-allchildren-2.0.0 {namespacex info allchildren, fqn} -setup {
    ns_setup
} -body {
    lsort -dict [namespacex info allchildren ::X]
} -cleanup {
    namespace delete ::X
} -result {::X::A ::X::B ::X::B::D ::X::C}

test namespacex-info-allchildren-2.0.1 {namespacex info allchildren, relative to global} -setup {
    ns_setup
} -body {
    lsort -dict [namespacex info allchildren X]
} -cleanup {
    namespace delete ::X
} -result {::X::A ::X::B ::X::B::D ::X::C}

test namespacex-info-allchildren-2.0.2 {namespacex info allchildren, relative to non-global} -setup {
    ns_setup ::Q
} -body {
    namespace eval ::Q {
        lsort -dict [namespacex info allchildren X]
    }
} -cleanup {
    namespace delete ::Q
} -result {::Q::X::A ::Q::X::B ::Q::X::B::D ::Q::X::C}

# -------------------------------------------------------------------------
## info vars

test namespacex-info-vars-1.0 {namespacex info vars, wrong\#args, not enough} -body {
    namespacex info vars
} -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}

test namespacex-info-vars-1.1 {namespacex info vars, wrong\#args, too many} -body {
    namespacex info vars N P X
} -returnCodes error -result {wrong # args: should be "namespacex info vars ns ?pattern?"}

test namespacex-info-vars-2.0.0 {namespacex info vars, fqn} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {vXa vXb}

test namespacex-info-vars-2.0.1 {namespacex info vars, relative to global} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info vars X]
} -cleanup {
    namespace delete ::X
} -result {vXa vXb}

test namespacex-info-vars-2.0.2 {namespacex info vars, relative to non-global} -setup {
    ns2_setup ::Q
} -body {
    namespace eval ::Q {
        lsort -dict [namespacex info vars X]
    }
} -cleanup {
    namespace delete ::Q
} -result {vXa vXb}

test namespacex-info-vars-2.1 {namespacex info vars} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-vars-2.2.0 {namespacex info vars, fqn} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info vars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-vars-2.2.1 {namespacex info vars, relative to global} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info vars X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-vars-2.2.2 {namespacex info vars, relative to non-global} -setup {
    ns3_setup ::Q
} -body {
    namespace eval ::Q {
        lsort -dict [namespacex info vars X]
    }
} -cleanup {
    namespace delete ::Q
} -result {}

# -------------------------------------------------------------------------
## info allvars

test namespacex-info-allvars-1.0 {namespacex info allvars, wrong\#args, not enough} -body {
    namespacex info allvars
} -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}

test namespacex-info-allvars-1.1 {namespacex info allvars, wrong\#args, too many} -body {
    namespacex info allvars N X
} -returnCodes error -result {wrong # args: should be "namespacex info allvars ns"}

test namespacex-info-allvars-2.0.0 {namespacex info allvars, fqn} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB vXa vXb}

test namespacex-info-allvars-2.0.1 {namespacex info allvars, relative to global} -setup {
    ns2_setup
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {B::vB vXa vXb}

test namespacex-info-allvars-2.0.2 {namespacex info allvars, relative to non-global} -setup {
    ns2_setup ::Q
} -body {
    namespace eval ::Q {
        lsort -dict [namespacex info allvars X]
    }
} -cleanup {
    namespace delete ::Q
} -result {B::vB vXa vXb}

test namespacex-info-allvars-2.1.0 {namespacex info allvars, fqn} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-allvars-2.1.1 {namespacex info allvars, relative to global} -setup {
    namespace eval ::X {}
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-info-allvars-2.1.2 {namespacex info allvars, relative to non-global} -setup {
    namespace eval ::Q::X {}
} -body {
    namespace eval ::Q {
        lsort -dict [namespacex info allvars X]
    }
} -cleanup {
    namespace delete ::Q
} -result {}

test namespacex-info-allvars-2.2.0 {namespacex info allvars, fqn} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info allvars ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB}

test namespacex-info-allvars-2.2.1 {namespacex info allvars, relative to global} -setup {
    ns3_setup
} -body {
    lsort -dict [namespacex info allvars X]
} -cleanup {
    namespace delete ::X
} -result {B::vB}

test namespacex-info-allvars-2.2.2 {namespacex info allvars, relative to non-global} -setup {
    ns3_setup ::Q
} -body {
    namespace eval ::Q {
        lsort -dict [namespacex info allvars X]
    }
} -cleanup {
    namespace delete ::Q
} -result {B::vB}

# -------------------------------------------------------------------------
## state get

test namespacex-state-get-1.0 {namespacex state get, wrong\#args, not enough} -body {
    namespacex state get
} -returnCodes error -result {wrong # args: should be "namespacex state get ns"}

test namespacex-state-get-1.1 {namespacex state get, wrong\#args, too many} -body {
    namespacex state get N X
} -returnCodes error -result {wrong # args: should be "namespacex state get ns"}

test namespacex-state-get-2.0.0 {namespacex state get, fqn} -setup {
    ns2_setup
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-get-2.0.1 {namespacex state get, relative to global} -setup {
    ns2_setup
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-get-2.0.2 {namespacex state get, relative to non-global} -setup {
    ns2_setup ::Q
} -body {
    namespace eval ::Q {
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-get-2.1.0 {namespacex state get, fqn} -setup {
    namespace eval ::X {}
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-get-2.1.1 {namespacex state get, relative to global} -setup {
    namespace eval ::X {}
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-get-2.1.2 {namespacex state get, relative to non-global} -setup {
    namespace eval ::Q::X {}
} -body {
    namespace eval ::Q {
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {}

test namespacex-state-get-2.2.0 {namespacex state get, fqn} -setup {
    ns3_setup
} -body {
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-get-2.2.1 {namespacex state get, relative to global} -setup {
    ns3_setup
} -body {
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-get-2.2.2 {namespacex state get, relative to non-global} -setup {
    ns3_setup ::Q
} -body {
    namespace eval ::Q {
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {B::vB mjolnir}

# -------------------------------------------------------------------------
## state drop

test namespacex-state-drop-1.0 {namespacex state drop, wrong\#args, not enough} -body {
    namespacex state drop
} -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}

test namespacex-state-drop-1.1 {namespacex state drop, wrong\#args, too many} -body {
    namespacex state drop N X
} -returnCodes error -result {wrong # args: should be "namespacex state drop ns"}

test namespacex-state-drop-2.0.0 {namespacex state drop, fqn} -setup {
    ns2_setup
} -body {
    namespacex state drop ::X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.0.1 {namespacex state drop, relative to global} -setup {
    ns2_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.0.2 {namespacex state drop, relative to non-global} -setup {
    ns2_setup ::Q
} -body {
    namespace eval ::Q {
        namespacex state drop X
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {}

test namespacex-state-drop-2.1.0 {namespacex state drop, fqn} -setup {
    namespace eval ::X {}
} -body {
    namespacex state drop X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.1.1 {namespacex state drop, relative to global} -setup {
    namespace eval ::X {}
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.1.2 {namespacex state drop, relative to non-global} -setup {
    namespace eval ::Q::X {}
} -body {
    namespace eval ::Q {
        namespacex state drop X
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {}

test namespacex-state-drop-2.2.0 {namespacex state drop, fqn} -setup {
    ns3_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.2.1 {namespacex state drop, relative to global} -setup {
    ns3_setup
} -body {
    namespacex state drop X
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {}

test namespacex-state-drop-2.2.2 {namespacex state drop, relative to non-global} -setup {
    ns3_setup ::Q
} -body {
    namespace eval ::Q {
        namespacex state drop X
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {}

# -------------------------------------------------------------------------
## state set

test namespacex-state-set-1.0 {namespacex state set, wrong\#args, not enough} -body {
    namespacex state set
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-1.1 {namespacex state set, wrong\#args, not enough} -body {
    namespacex state set N
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-1.2 {namespacex state set, wrong\#args, too many} -body {
    namespacex state set N S X
} -returnCodes error -result {wrong # args: should be "namespacex state set ns state"}

test namespacex-state-set-2.0.0 {namespacex state set, fqn} -setup {
    ns2_setup
    set ST [namespacex state get ::X]
    ns3_setup
} -body {
    namespacex state set ::X $ST
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-set-2.0.1 {namespacex state set, relative to global} -setup {
    ns2_setup
    set ST [namespacex state get ::X]
    ns3_setup
} -body {
    namespacex state set X $ST
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-set-2.0.1 {namespacex state set, relative to non-global} -setup {
    ns2_setup
    set ST [namespacex state get ::X]
    namespace delete ::X
    ns3_setup ::Q
} -body {
    namespace eval ::Q {
        namespacex state set X $ST
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {B::vB 3 vXa 1 vXb aleph}

test namespacex-state-set-2.1.0 {namespacex state set, fqn} -setup {
    ns3_setup
    set ST [namespacex state get ::X]
    ns2_setup
} -body {
    namespacex state set ::X $ST
    dictsort [namespacex state get ::X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-set-2.1.1 {namespacex state set, relative to global} -setup {
    ns3_setup
    set ST [namespacex state get ::X]
    ns2_setup
} -body {
    namespacex state set X $ST
    dictsort [namespacex state get X]
} -cleanup {
    namespace delete ::X
} -result {B::vB mjolnir}

test namespacex-state-set-2.1.2 {namespacex state set, relative to non-global} -setup {
    ns3_setup
    set ST [namespacex state get ::X]
    namespace delete ::X
    ns2_setup ::Q
} -body {
    namespace eval ::Q {
        namespacex state set X $ST
        dictsort [namespacex state get X]
    }
} -cleanup {
    namespace delete ::Q
} -result {B::vB mjolnir}

## done
# -------------------------------------------------------------------------
testsuiteCleanup

# Local variables:
# mode: tcl
# indent-tabs-mode: nil
# End:

Changes to modules/namespacex/pkgIndex.tcl.

1
2
3
4
5
if {![package vsatisfies [package provide Tcl] 8.5]} {
    # PRAGMA: returnok
    return
}
package ifneeded namespacex 0.1 [list source [file join $dir namespacex.tcl]]



|
1
2
3
4
5
if {![package vsatisfies [package provide Tcl] 8.5]} {
    # PRAGMA: returnok
    return
}
package ifneeded namespacex 0.2 [list source [file join $dir namespacex.tcl]]