Skip to content

Commit 9f4be10

Browse files
committed
tests illustrating regression bug [3a2e7bf0e2] - protection of methods seems to be ignored if invoked from body of method of another class (from not a inheritance)
1 parent c2ea6d8 commit 9f4be10

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/protection.test

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,26 @@ test protect-1.1 {define a class with various protection levels} {
4444
}
4545
method do {args} {eval $args}
4646
}
47+
48+
# other class to test private/protected methods and procs of test_pr from there (see [3a2e7bf0e2]):
49+
itcl::class test_pr_b {
50+
public proc testp {} {
51+
set o [test_pr #auto]
52+
set res {}
53+
lappend res [catch { $o prom } v] $v [catch { $o prim } v] $v
54+
lappend res [catch { test_pr::prop } v] $v [catch { test_pr::prip } v] $v
55+
itcl::delete object $o
56+
set res
57+
}
58+
public method testm {} {
59+
set o [test_pr #auto]
60+
set res {}
61+
lappend res [catch { $o prom } v] $v [catch { $o prim } v] $v
62+
lappend res [catch { test_pr::prop } v] $v [catch { test_pr::prip } v] $v
63+
itcl::delete object $o
64+
set res
65+
}
66+
}
4767
} ""
4868

4969
test protect-1.2 {create an object to execute tests} {
@@ -110,6 +130,18 @@ test protect-1.8b {private procs can be accessed from inside} {
110130
list [catch {test_pr0 do prip} msg] $msg
111131
} {0 {private proc}}
112132

133+
test protect-1.8c {protected/private methods/procs are blocked from outside, also in some itcl proc body, [3a2e7bf0e2]} -body {
134+
test_pr_b::testp
135+
} -match glob -result {1 {bad option "prom"*} 1 {bad option "prim"*} 1 {can't access "::test_pr::prop": protected function} 1 {can't access "::test_pr::prip": private function}}
136+
137+
test protect-1.8d {protected/private methods/procs are blocked from outside, also in some itcl method body, [3a2e7bf0e2]} -body {
138+
set b [test_pr_b #auto]
139+
set res [$b testm]
140+
itcl::delete object $b
141+
unset -nocomplain b
142+
set res
143+
} -match glob -result {1 {bad option "prom"*} 1 {bad option "prim"*} 1 {invalid command name "test_pr::prop"} 1 {invalid command name "test_pr::prip"}}
144+
113145
test protect-1.9a {public commons can be accessed from outside} {
114146
list [catch {set test_pr::pubc} msg] $msg
115147
} {0 {public com}}

0 commit comments

Comments
 (0)