From 3b5858bcd23542b0ff0249a128808ef20922beb6 Mon Sep 17 00:00:00 2001 From: oehhar Date: Wed, 10 Jan 2018 23:17:43 +0000 Subject: TIP490: oo for msgcal: new solution enable any command for oo, new command mcpackagenamespacege --- changes | 2 ++ library/msgcat/msgcat.tcl | 49 ++++++++++++++++++++++-------- library/msgcat/pkgIndex.tcl | 2 +- tests/msgcat.test | 74 +++++++++++++++++++++++++++++++++++++++++++++ unix/Makefile.in | 4 +-- win/Makefile.in | 4 +-- 6 files changed, 118 insertions(+), 17 deletions(-) diff --git a/changes b/changes index f89704b..51c0477 100644 --- a/changes +++ b/changes @@ -8879,3 +8879,5 @@ in this changeset (new minor version) rather than bug fixes: 2017-09-02 (bug)[0e4d88] replace command, delete trace kills namespace (porter) --- Released 8.7a1, September 8, 2017 --- http://core.tcl.tk/tcl/ for details + +2017-12-11 (TIP 490) add oo support for msgcat => msgcat 1.6.2 (oehlmann) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 646bc17..849adc6 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -14,12 +14,12 @@ package require Tcl 8.5- # When the version number changes, be sure to update the pkgIndex.tcl file, # and the installation directory in the Makefiles. -package provide msgcat 1.6.1 +package provide msgcat 1.6.2 namespace eval msgcat { namespace export mc mcexists mcload mclocale mcmax mcmset mcpreferences mcset\ mcunknown mcflset mcflmset mcloadedlocales mcforgetpackage\ - mcpackageconfig mcpackagelocale + mcpackagenamespaceget mcpackageconfig mcpackagelocale # Records the list of locales to search variable Loclist {} @@ -193,9 +193,6 @@ namespace eval msgcat { # format command. proc msgcat::mc {src args} { - # this may be replaced by: - # return [mcget -namespace [uplevel 1 [list ::namespace current]] --\ - # $src {*}$args] # Check for the src in each namespace starting from the local and # ending in the global. @@ -203,7 +200,7 @@ proc msgcat::mc {src args} { variable Msgs variable Loclist - set ns [uplevel 1 [list ::namespace current]] + set ns [PackageNamespaceGet] set loclist [PackagePreferences $ns] set nscur $ns @@ -245,7 +242,7 @@ proc msgcat::mcexists {args} { variable Loclist variable PackageConfig - set ns [uplevel 1 [list ::namespace current]] + set ns [PackageNamespaceGet] set loclist [PackagePreferences $ns] while {[llength $args] != 1} { @@ -462,7 +459,7 @@ proc msgcat::mcpackagelocale {subcommand {locale ""}} { } set locale [string tolower $locale] } - set ns [uplevel 1 {::namespace current}] + set ns [PackageNamespaceGet] switch -exact -- $subcommand { get { return [lindex [PackagePreferences $ns] 0] } @@ -551,7 +548,7 @@ proc msgcat::mcforgetpackage {} { # todo: this may be implemented using an ensemble variable PackageConfig variable Msgs - set ns [uplevel 1 {::namespace current}] + set ns [PackageNamespaceGet] # Remove MC items dict unset Msgs $ns # Remove config items @@ -561,6 +558,15 @@ proc msgcat::mcforgetpackage {} { return } +# msgcat::mcgetmynamespace -- +# +# Return the package namespace of the caller +# This consideres to be called from a class or object. + +proc msgcat::mcpackagenamespaceget {} { + return [PackageNamespaceGet] +} + # msgcat::mcpackageconfig -- # # Get or modify the per caller namespace (e.g. packages) config options. @@ -616,7 +622,7 @@ proc msgcat::mcforgetpackage {} { proc msgcat::mcpackageconfig {subcommand option {value ""}} { variable PackageConfig # get namespace - set ns [uplevel 1 {::namespace current}] + set ns [PackageNamespaceGet] if {$option ni {"mcfolder" "loadcmd" "changecmd" "unknowncmd"}} { return -code error "bad option \"$option\": must be mcfolder, loadcmd,\ @@ -923,7 +929,7 @@ proc msgcat::mcset {locale src {dest ""}} { set dest $src } - set ns [uplevel 1 [list ::namespace current]] + set ns [PackageNamespaceGet] set locale [string tolower $locale] @@ -975,7 +981,7 @@ proc msgcat::mcmset {locale pairs} { } set locale [string tolower $locale] - set ns [uplevel 1 [list ::namespace current]] + set ns [PackageNamespaceGet] foreach {src dest} $pairs { dict set Msgs $ns $locale $src $dest @@ -1106,6 +1112,25 @@ proc msgcat::ConvertLocale {value} { return $ret } +# helper function to find package namespace of stack-frame -2 +# There are 3 possibilities: +# - called from a proc +# - called from a oo class +# - called from a classless oo object +proc ::msgcat::PackageNamespaceGet {} { + uplevel 2 { + # Check for no object + if {0 == [llength [info commands self]]} {return [namespace current]} + set Class [info object class [self]] + # Check for classless defined object + if {$Class eq {::oo::object}} { + return [namespace qualifiers [self]] + } + # Class defined object + return [namespace qualifiers $Class] + } +} + # Initialize the default locale proc msgcat::Init {} { global env diff --git a/library/msgcat/pkgIndex.tcl b/library/msgcat/pkgIndex.tcl index 72c5dc0..bc58cbe 100644 --- a/library/msgcat/pkgIndex.tcl +++ b/library/msgcat/pkgIndex.tcl @@ -1,2 +1,2 @@ if {![package vsatisfies [package provide Tcl] 8.5-]} {return} -package ifneeded msgcat 1.6.1 [list source [file join $dir msgcat.tcl]] +package ifneeded msgcat 1.6.2 [list source [file join $dir msgcat.tcl]] diff --git a/tests/msgcat.test b/tests/msgcat.test index 1c3ce58..9dc8b48 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -1073,6 +1073,80 @@ namespace eval ::msgcat::test { } -returnCodes 1\ -result {fail} + + # Tests msgcat-15.*: tcloo coverage + + # There are 3 use-cases, where 2 must be tested now: + # - namespace defined, class defined oo, classless + + test msgcat-15.1 {mc in class} -setup { + namespace eval ::bar { + ::msgcat::mcset foo_BAR con2 con2bar + oo::class create ClassCur + oo::define ClassCur method method1 {} {::msgcat::mc con2} + } + namespace eval ::baz { + set ObjCur [::bar::ClassCur new] + } + variable locale [mclocale] + mclocale foo_BAR + } -cleanup { + mclocale $locale + namespace eval ::bar {::msgcat::mcforgetpackage} + namespace forget ::bar ::baz + } -body { + $::baz::ObjCur method1 + } -result con2bar + + test msgcat-15.2 {mc in classless object} -setup { + namespace eval ::bar { + ::msgcat::mcset foo_BAR con2 con2bar + oo::object create ObjCur + oo::objdefine ObjCur method method1 {} {::msgcat::mc con2} + } + variable locale [mclocale] + mclocale foo_BAR + } -cleanup { + mclocale $locale + namespace eval ::bar {::msgcat::mcforgetpackage} + namespace forget ::bar + } -body { + ::bar::ObjCur method1 + } -result con2bar + + # Test msgcat-16.*: command mcpackagenamespaceget + + test msgcat-16.1 {mcpackagenamespaceget in namespace procedure} -body { + namespace eval ::baz {msgcat::mcpackagenamespaceget} + } -result ::baz + + test msgcat-16.2 {mcpackagenamespaceget in class} -setup { + namespace eval ::bar { + oo::class create ClassCur + oo::define ClassCur method method1 {} {msgcat::mcpackagenamespaceget} + } + namespace eval ::baz { + set ObjCur [::bar::ClassCur new] + } + } -cleanup { + namespace forget ::bar ::baz + } -body { + $::baz::ObjCur method1 + } -result ::bar + + test msgcat-16.3 {mcpackagenamespaceget in classless object} -setup { + namespace eval ::bar { + oo::object create ObjCur + oo::objdefine ObjCur method method1 {} {msgcat::mcpackagenamespaceget} + } + } -cleanup { + namespace forget ::bar + } -body { + ::bar::ObjCur method1 + } -result ::bar + + + interp bgerror {} $bgerrorsaved cleanupTests diff --git a/unix/Makefile.in b/unix/Makefile.in index f3b9782..a343864 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -855,8 +855,8 @@ install-libraries: libraries do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/opt0.4; \ done; - @echo "Installing package msgcat 1.6.1 as a Tcl Module"; - @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.6.1.tm; + @echo "Installing package msgcat 1.6.2 as a Tcl Module"; + @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.6.2.tm; @echo "Installing package tcltest 2.4.1 as a Tcl Module"; @$(INSTALL_DATA) $(TOP_DIR)/library/tcltest/tcltest.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/tcltest-2.4.1.tm; diff --git a/win/Makefile.in b/win/Makefile.in index a3275ba..f3e1bd6 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -664,8 +664,8 @@ install-libraries: libraries install-tzdata install-msgs do \ $(COPY) "$$j" "$(SCRIPT_INSTALL_DIR)/opt0.4"; \ done; - @echo "Installing package msgcat 1.6.1 as a Tcl Module"; - @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.6.1.tm; + @echo "Installing package msgcat 1.6.2 as a Tcl Module"; + @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.6.2.tm; @echo "Installing package tcltest 2.4.0 as a Tcl Module"; @$(COPY) $(ROOT_DIR)/library/tcltest/tcltest.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/tcltest-2.4.0.tm; @echo "Installing package platform 1.0.14 as a Tcl Module"; -- cgit v0.12 From 1fda13591a6eff53b73bfa288078edb56ab8a26c Mon Sep 17 00:00:00 2001 From: oehhar Date: Thu, 11 Jan 2018 16:46:09 +0000 Subject: Corrected test cleanups --- tests/msgcat.test | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/msgcat.test b/tests/msgcat.test index 9dc8b48..387ce85 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -1093,7 +1093,7 @@ namespace eval ::msgcat::test { } -cleanup { mclocale $locale namespace eval ::bar {::msgcat::mcforgetpackage} - namespace forget ::bar ::baz + namespace delete ::bar ::baz } -body { $::baz::ObjCur method1 } -result con2bar @@ -1109,7 +1109,7 @@ namespace eval ::msgcat::test { } -cleanup { mclocale $locale namespace eval ::bar {::msgcat::mcforgetpackage} - namespace forget ::bar + namespace delete ::bar } -body { ::bar::ObjCur method1 } -result con2bar @@ -1129,7 +1129,7 @@ namespace eval ::msgcat::test { set ObjCur [::bar::ClassCur new] } } -cleanup { - namespace forget ::bar ::baz + namespace delete ::bar ::baz } -body { $::baz::ObjCur method1 } -result ::bar @@ -1140,7 +1140,7 @@ namespace eval ::msgcat::test { oo::objdefine ObjCur method method1 {} {msgcat::mcpackagenamespaceget} } } -cleanup { - namespace forget ::bar + namespace delete ::bar } -body { ::bar::ObjCur method1 } -result ::bar -- cgit v0.12 From e9f2695255b873c200a7fc465f860b4fd5c97a02 Mon Sep 17 00:00:00 2001 From: oehhar Date: Fri, 12 Jan 2018 14:03:04 +0000 Subject: replace "return [uplevel 1 [list [namespace origin ..." by tailcall --- library/msgcat/msgcat.tcl | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 849adc6..885240f 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -216,7 +216,7 @@ proc msgcat::mc {src args} { # call package local or default unknown command set args [linsert $args 0 [lindex $loclist 0] $src] switch -exact -- [Invoke unknowncmd $args $ns result 1] { - 0 { return [uplevel 1 [linsert $args 0 [namespace origin mcunknown]]] } + 0 { tailcall mcunknown {*}$args } 1 { return [DefaultUnknown {*}$args] } default { return $result } } @@ -762,8 +762,7 @@ proc msgcat::ListComplement {list1 list2 {inlistname ""}} { # Returns the number of message catalogs that were loaded. proc msgcat::mcload {langdir} { - return [uplevel 1 [list\ - [namespace origin mcpackageconfig] set mcfolder $langdir]] + tailcall mcpackageconfig set mcfolder $langdir } # msgcat::LoadAll -- @@ -957,7 +956,7 @@ proc msgcat::mcflset {src {dest ""}} { return -code error "must only be used inside a message catalog loaded\ with ::msgcat::mcload" } - return [uplevel 1 [list [namespace origin mcset] $FileLocale $src $dest]] + tailcall mcset $FileLocale $src $dest } # msgcat::mcmset -- @@ -1008,7 +1007,7 @@ proc msgcat::mcflmset {pairs} { return -code error "must only be used inside a message catalog loaded\ with ::msgcat::mcload" } - return [uplevel 1 [list [namespace origin mcmset] $FileLocale $pairs]] + tailcal mcmset $FileLocale $pairs } # msgcat::mcunknown -- @@ -1030,7 +1029,7 @@ proc msgcat::mcflmset {pairs} { # Returns the translated value. proc msgcat::mcunknown {args} { - return [uplevel 1 [list [namespace origin DefaultUnknown] {*}$args]] + tailcall DefaultUnknown {*}$args } # msgcat::DefaultUnknown -- -- cgit v0.12 From 2cfe8bb5619eb9a1de655bda6a208e9e2fb8b81b Mon Sep 17 00:00:00 2001 From: oehhar Date: Fri, 12 Jan 2018 14:13:03 +0000 Subject: Use the test "[namespace which self] ne "::oo::Helpers::self"" to check if we are within an object (undocumented test proposed by dkf on clt 2018-01-12 --- library/msgcat/msgcat.tcl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 885240f..66cedea 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -1119,7 +1119,10 @@ proc msgcat::ConvertLocale {value} { proc ::msgcat::PackageNamespaceGet {} { uplevel 2 { # Check for no object - if {0 == [llength [info commands self]]} {return [namespace current]} + # (undocumented test proposed by dkf 2018-01-12) + if { [namespace which self] ne "::oo::Helpers::self"} { + return [namespace current] + } set Class [info object class [self]] # Check for classless defined object if {$Class eq {::oo::object}} { -- cgit v0.12 From e1ffd3f0057b68e75bce64f9c514b9993fb8a79c Mon Sep 17 00:00:00 2001 From: oehhar Date: Fri, 12 Jan 2018 14:52:25 +0000 Subject: Implement the "mcn" command as "mc" with explicit namespace. --- library/msgcat/msgcat.tcl | 32 ++++++++++++++++++++++++++++---- tests/msgcat.test | 12 ++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 66cedea..29ccf0a 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -17,7 +17,8 @@ package require Tcl 8.5- package provide msgcat 1.6.2 namespace eval msgcat { - namespace export mc mcexists mcload mclocale mcmax mcmset mcpreferences mcset\ + namespace export mc mcn mcexists mcload mclocale mcmax\ + mcmset mcpreferences mcset\ mcunknown mcflset mcflmset mcloadedlocales mcforgetpackage\ mcpackagenamespaceget mcpackageconfig mcpackagelocale @@ -192,7 +193,30 @@ namespace eval msgcat { # Returns the translated string. Propagates errors thrown by the # format command. -proc msgcat::mc {src args} { +proc msgcat::mc {args} { + tailcall mcn [PackageNamespaceGet] {*}$args +} + +# msgcat::mcn -- +# +# Find the translation for the given string based on the current +# locale setting. Check the passed namespace first, then look in each +# parent namespace until the source is found. If additional args are +# specified, use the format command to work them into the traslated +# string. +# If no catalog item is found, mcunknown is called in the caller frame +# and its result is returned. +# +# Arguments: +# ns Package namespace of the translation +# src The string to translate. +# args Args to pass to the format command +# +# Results: +# Returns the translated string. Propagates errors thrown by the +# format command. + +proc msgcat::mcn {ns src args} { # Check for the src in each namespace starting from the local and # ending in the global. @@ -200,7 +224,6 @@ proc msgcat::mc {src args} { variable Msgs variable Loclist - set ns [PackageNamespaceGet] set loclist [PackagePreferences $ns] set nscur $ns @@ -1072,8 +1095,9 @@ proc msgcat::DefaultUnknown {locale src args} { proc msgcat::mcmax {args} { set max 0 + set ns [PackageNamespaceGet] foreach string $args { - set translated [uplevel 1 [list [namespace origin mc] $string]] + set translated [uplevel 1 [list [namespace origin mcn] $ns $string]] set len [string length $translated] if {$len>$max} { set max $len diff --git a/tests/msgcat.test b/tests/msgcat.test index 387ce85..c8f325b 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -1144,7 +1144,19 @@ namespace eval ::msgcat::test { } -body { ::bar::ObjCur method1 } -result ::bar + + + # Test msgcat-17.*: mcn command + test msgcat-17.1 {mcn} -setup { + namespace eval bar {::msgcat::mcset foo_BAR con1 con1bar} + variable locale [mclocale] + mclocale foo_BAR + } -cleanup { + mclocale $locale + } -body { + ::msgcat::mcn [namespace current]::bar con1 + } -result con1bar interp bgerror {} $bgerrorsaved -- cgit v0.12 From ecaec63f48c02c5bb7c0e7585ebc1d746b77ffd9 Mon Sep 17 00:00:00 2001 From: oehhar Date: Sat, 13 Jan 2018 15:23:38 +0000 Subject: Extended command msgcat::mcexists by switch "-namespace ns" to explicitly specify namespace --- library/msgcat/msgcat.tcl | 22 ++++++--- tests/msgcat.test | 120 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 109 insertions(+), 33 deletions(-) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 29ccf0a..e57802b 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -265,23 +265,31 @@ proc msgcat::mcexists {args} { variable Loclist variable PackageConfig - set ns [PackageNamespaceGet] - set loclist [PackagePreferences $ns] - while {[llength $args] != 1} { set args [lassign $args option] switch -glob -- $option { - -exactnamespace { set exactnamespace 1 } - -exactlocale { set loclist [lrange $loclist 0 0] } + -exactnamespace - -exactlocale { set $option 1 } + -namespace { + if {[llength $args] < 2} { + return -code error\ + "Argument missing for switch \"-namespace\"" + } + set args [lassign $args ns] + } -* { return -code error "unknown option \"$option\"" } default { return -code error "wrong # args: should be\ \"[lindex [info level 0] 0] ?-exactnamespace?\ - ?-exactlocale? src\"" + ?-exactlocale? ?-namespace ns? src\"" } } } set src [lindex $args 0] + + if {![info exists ns]} { set ns [PackageNamespaceGet] } + + set loclist [PackagePreferences $ns] + if {[info exists -exactlocale]} { set loclist [lrange $loclist 0 0] } while {$ns ne ""} { foreach loc $loclist { @@ -289,7 +297,7 @@ proc msgcat::mcexists {args} { return 1 } } - if {[info exists exactnamespace]} {return 0} + if {[info exists -exactnamespace]} {return 0} set ns [namespace parent $ns] } return 0 diff --git a/tests/msgcat.test b/tests/msgcat.test index c8f325b..a99086d 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -688,7 +688,7 @@ namespace eval ::msgcat::test { test msgcat-9.1 {mcexists no parameter} -body { mcexists } -returnCodes 1\ - -result {wrong # args: should be "mcexists ?-exactnamespace? ?-exactlocale? src"} + -result {wrong # args: should be "mcexists ?-exactnamespace? ?-exactlocale? ?-namespace ns? src"} test msgcat-9.2 {mcexists unknown option} -body { mcexists -unknown src @@ -724,12 +724,34 @@ namespace eval ::msgcat::test { mcset foo k1 v1 } -cleanup { mclocale $locale + namespace delete ::foo } -body { - namespace eval ::msgcat::test::sub { + namespace eval ::foo { list [::msgcat::mcexists k1]\ - [::msgcat::mcexists -exactnamespace k1] + [::msgcat::mcexists -namespace ::msgcat::test k1] } - } -result {1 0} + } -result {0 1} + + test msgcat-9.6 {mcexists -namespace - ns argument missing} -setup { + mcforgetpackage + variable locale [mclocale] + mclocale foo_bar + mcset foo k1 v1 + } -cleanup { + mclocale $locale + namespace delete ::foo + } -body { + namespace eval ::foo { + list [::msgcat::mcexists k1]\ + [::msgcat::mcexists -namespace ::msgcat::test k1] + } + } -result {0 1} + + test msgcat-9.1 {mcexists -namespace with no parameter} -body { + mcexists -namespace src + } -returnCodes 1\ + -result {Argument missing for switch "-namespace"} + # Tests msgcat-10.*: [mcloadedlocales] @@ -1080,26 +1102,29 @@ namespace eval ::msgcat::test { # - namespace defined, class defined oo, classless test msgcat-15.1 {mc in class} -setup { - namespace eval ::bar { + # full namespace is ::msgcat::test:bar + namespace eval bar { ::msgcat::mcset foo_BAR con2 con2bar oo::class create ClassCur oo::define ClassCur method method1 {} {::msgcat::mc con2} } - namespace eval ::baz { - set ObjCur [::bar::ClassCur new] + # full namespace is ::msgcat::test:baz + namespace eval baz { + set ObjCur [::msgcat::test::bar::ClassCur new] } variable locale [mclocale] mclocale foo_BAR } -cleanup { mclocale $locale - namespace eval ::bar {::msgcat::mcforgetpackage} - namespace delete ::bar ::baz + namespace eval bar {::msgcat::mcforgetpackage} + namespace delete bar baz } -body { - $::baz::ObjCur method1 + $baz::ObjCur method1 } -result con2bar test msgcat-15.2 {mc in classless object} -setup { - namespace eval ::bar { + # full namespace is ::msgcat::test:bar + namespace eval bar { ::msgcat::mcset foo_BAR con2 con2bar oo::object create ObjCur oo::objdefine ObjCur method method1 {} {::msgcat::mc con2} @@ -1108,42 +1133,85 @@ namespace eval ::msgcat::test { mclocale foo_BAR } -cleanup { mclocale $locale - namespace eval ::bar {::msgcat::mcforgetpackage} - namespace delete ::bar + namespace eval bar {::msgcat::mcforgetpackage} + namespace delete bar } -body { - ::bar::ObjCur method1 + bar::ObjCur method1 } -result con2bar + test msgcat-15.3 {mc in classless object with explicite namespace eval}\ + -setup { + # full namespace is ::msgcat::test:bar + namespace eval bar { + ::msgcat::mcset foo_BAR con2 con2bar + oo::object create ObjCur + oo::objdefine ObjCur method method1 {} { + namespace eval ::msgcat::test::baz { + ::msgcat::mc con2 + } + } + } + namespace eval baz { + ::msgcat::mcset foo_BAR con2 con2baz + } + variable locale [mclocale] + mclocale foo_BAR + } -cleanup { + mclocale $locale + namespace eval bar {::msgcat::mcforgetpackage} + namespace eval baz {::msgcat::mcforgetpackage} + namespace delete bar baz + } -body { + bar::ObjCur method1 + } -result con2baz + # Test msgcat-16.*: command mcpackagenamespaceget test msgcat-16.1 {mcpackagenamespaceget in namespace procedure} -body { - namespace eval ::baz {msgcat::mcpackagenamespaceget} - } -result ::baz + namespace eval baz {msgcat::mcpackagenamespaceget} + } -result ::msgcat::test::baz test msgcat-16.2 {mcpackagenamespaceget in class} -setup { - namespace eval ::bar { + namespace eval bar { oo::class create ClassCur oo::define ClassCur method method1 {} {msgcat::mcpackagenamespaceget} } - namespace eval ::baz { - set ObjCur [::bar::ClassCur new] + namespace eval baz { + set ObjCur [::msgcat::test::bar::ClassCur new] } } -cleanup { - namespace delete ::bar ::baz + namespace delete bar baz } -body { - $::baz::ObjCur method1 - } -result ::bar + $baz::ObjCur method1 + } -result ::msgcat::test::bar test msgcat-16.3 {mcpackagenamespaceget in classless object} -setup { - namespace eval ::bar { + namespace eval bar { oo::object create ObjCur oo::objdefine ObjCur method method1 {} {msgcat::mcpackagenamespaceget} } } -cleanup { - namespace delete ::bar + namespace delete bar + } -body { + bar::ObjCur method1 + } -result ::msgcat::test::bar + + test msgcat-16.4\ + {mcpackagenamespaceget in classless object with explicite namespace eval}\ + -setup { + namespace eval bar { + oo::object create ObjCur + oo::objdefine ObjCur method method1 {} { + namespace eval ::msgcat::test::baz { + msgcat::mcpackagenamespaceget + } + } + } + } -cleanup { + namespace delete bar baz } -body { - ::bar::ObjCur method1 - } -result ::bar + bar::ObjCur method1 + } -result ::msgcat::test::baz # Test msgcat-17.*: mcn command -- cgit v0.12 From eaacc9bb568b4c69d6a5bda83a9f11d9f0f46a80 Mon Sep 17 00:00:00 2001 From: oehhar Date: Sat, 13 Jan 2018 16:44:38 +0000 Subject: Changed msgcat version from 1.6.2 to 1.7.0 -> this is not a patch release --- changes | 2 +- library/msgcat/msgcat.tcl | 2 +- library/msgcat/pkgIndex.tcl | 2 +- unix/Makefile.in | 4 ++-- win/Makefile.in | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/changes b/changes index 51c0477..5b5a93e 100644 --- a/changes +++ b/changes @@ -8880,4 +8880,4 @@ in this changeset (new minor version) rather than bug fixes: --- Released 8.7a1, September 8, 2017 --- http://core.tcl.tk/tcl/ for details -2017-12-11 (TIP 490) add oo support for msgcat => msgcat 1.6.2 (oehlmann) +2017-12-11 (TIP 490) add oo support for msgcat => msgcat 1.7.0 (oehlmann) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index e57802b..4233005 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -14,7 +14,7 @@ package require Tcl 8.5- # When the version number changes, be sure to update the pkgIndex.tcl file, # and the installation directory in the Makefiles. -package provide msgcat 1.6.2 +package provide msgcat 1.7.0 namespace eval msgcat { namespace export mc mcn mcexists mcload mclocale mcmax\ diff --git a/library/msgcat/pkgIndex.tcl b/library/msgcat/pkgIndex.tcl index bc58cbe..fe3b3a1 100644 --- a/library/msgcat/pkgIndex.tcl +++ b/library/msgcat/pkgIndex.tcl @@ -1,2 +1,2 @@ if {![package vsatisfies [package provide Tcl] 8.5-]} {return} -package ifneeded msgcat 1.6.2 [list source [file join $dir msgcat.tcl]] +package ifneeded msgcat 1.7.0 [list source [file join $dir msgcat.tcl]] diff --git a/unix/Makefile.in b/unix/Makefile.in index a343864..a3c0e4c 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -855,8 +855,8 @@ install-libraries: libraries do \ $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/opt0.4; \ done; - @echo "Installing package msgcat 1.6.2 as a Tcl Module"; - @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.6.2.tm; + @echo "Installing package msgcat 1.7.0 as a Tcl Module"; + @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.7.0.tm; @echo "Installing package tcltest 2.4.1 as a Tcl Module"; @$(INSTALL_DATA) $(TOP_DIR)/library/tcltest/tcltest.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/tcltest-2.4.1.tm; diff --git a/win/Makefile.in b/win/Makefile.in index f3e1bd6..a97f1a1 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -664,8 +664,8 @@ install-libraries: libraries install-tzdata install-msgs do \ $(COPY) "$$j" "$(SCRIPT_INSTALL_DIR)/opt0.4"; \ done; - @echo "Installing package msgcat 1.6.2 as a Tcl Module"; - @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.6.2.tm; + @echo "Installing package msgcat 1.7.0 as a Tcl Module"; + @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.7.0.tm; @echo "Installing package tcltest 2.4.0 as a Tcl Module"; @$(COPY) $(ROOT_DIR)/library/tcltest/tcltest.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/tcltest-2.4.0.tm; @echo "Installing package platform 1.0.14 as a Tcl Module"; -- cgit v0.12 From 87c12599bfbcd60c4b90780c1a7e653c95c2436c Mon Sep 17 00:00:00 2001 From: oehhar Date: Sat, 13 Jan 2018 17:14:22 +0000 Subject: Test numbering and naming corrected --- tests/msgcat.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/msgcat.test b/tests/msgcat.test index a99086d..a71ee3f 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -732,7 +732,7 @@ namespace eval ::msgcat::test { } } -result {0 1} - test msgcat-9.6 {mcexists -namespace - ns argument missing} -setup { + test msgcat-9.6 {mcexists -namespace ns parameter} -setup { mcforgetpackage variable locale [mclocale] mclocale foo_bar @@ -747,7 +747,7 @@ namespace eval ::msgcat::test { } } -result {0 1} - test msgcat-9.1 {mcexists -namespace with no parameter} -body { + test msgcat-9.7 {mcexists -namespace - ns argument missing} -body { mcexists -namespace src } -returnCodes 1\ -result {Argument missing for switch "-namespace"} -- cgit v0.12 From e841295386a779136b49e7ca3843a43279a8c185 Mon Sep 17 00:00:00 2001 From: oehhar Date: Sat, 13 Jan 2018 17:17:39 +0000 Subject: Install msgcat 1.7 in library folder 8.6 instead 8.5. It uses tailcall and will not work with 8.5 --- unix/Makefile.in | 2 +- win/Makefile.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/unix/Makefile.in b/unix/Makefile.in index a3c0e4c..baaab95 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -856,7 +856,7 @@ install-libraries: libraries $(INSTALL_DATA) $$i "$(SCRIPT_INSTALL_DIR)"/opt0.4; \ done; @echo "Installing package msgcat 1.7.0 as a Tcl Module"; - @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/msgcat-1.7.0.tm; + @$(INSTALL_DATA) $(TOP_DIR)/library/msgcat/msgcat.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.6/msgcat-1.7.0.tm; @echo "Installing package tcltest 2.4.1 as a Tcl Module"; @$(INSTALL_DATA) $(TOP_DIR)/library/tcltest/tcltest.tcl "$(SCRIPT_INSTALL_DIR)"/../tcl8/8.5/tcltest-2.4.1.tm; diff --git a/win/Makefile.in b/win/Makefile.in index a97f1a1..131f22b 100644 --- a/win/Makefile.in +++ b/win/Makefile.in @@ -665,7 +665,7 @@ install-libraries: libraries install-tzdata install-msgs $(COPY) "$$j" "$(SCRIPT_INSTALL_DIR)/opt0.4"; \ done; @echo "Installing package msgcat 1.7.0 as a Tcl Module"; - @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/msgcat-1.7.0.tm; + @$(COPY) $(ROOT_DIR)/library/msgcat/msgcat.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.6/msgcat-1.7.0.tm; @echo "Installing package tcltest 2.4.0 as a Tcl Module"; @$(COPY) $(ROOT_DIR)/library/tcltest/tcltest.tcl $(SCRIPT_INSTALL_DIR)/../tcl8/8.5/tcltest-2.4.0.tm; @echo "Installing package platform 1.0.14 as a Tcl Module"; -- cgit v0.12 From e89d1e331e09f13b01ad0436d00bf199214d4d46 Mon Sep 17 00:00:00 2001 From: oehhar Date: Tue, 16 Jan 2018 14:13:14 +0000 Subject: Solve case where msgcat is called within a class definition script (works only for 8.7) --- library/msgcat/msgcat.tcl | 29 +++++++++++++++++---------- tests/msgcat.test | 50 ++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 4233005..0b1079b 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -1151,17 +1151,26 @@ proc msgcat::ConvertLocale {value} { proc ::msgcat::PackageNamespaceGet {} { uplevel 2 { # Check for no object - # (undocumented test proposed by dkf 2018-01-12) - if { [namespace which self] ne "::oo::Helpers::self"} { - return [namespace current] - } - set Class [info object class [self]] - # Check for classless defined object - if {$Class eq {::oo::object}} { - return [namespace qualifiers [self]] + switch -exact -- [namespace which self] { + {::oo::define::self} { + # We are within a class definition + return [namespace qualifiers [self]] + } + {::oo::Helpers::self} { + # We are within an object + set Class [info object class [self]] + # Check for classless defined object + if {$Class eq {::oo::object}} { + return [namespace qualifiers [self]] + } + # Class defined object + return [namespace qualifiers $Class] + } + default { + # Not in object environment + return [namespace current] + } } - # Class defined object - return [namespace qualifiers $Class] } } diff --git a/tests/msgcat.test b/tests/msgcat.test index a71ee3f..7f872ed 100644 --- a/tests/msgcat.test +++ b/tests/msgcat.test @@ -1098,10 +1098,26 @@ namespace eval ::msgcat::test { # Tests msgcat-15.*: tcloo coverage - # There are 3 use-cases, where 2 must be tested now: - # - namespace defined, class defined oo, classless + # There are 4 use-cases, where 3 must be tested now: + # - namespace defined, in class definition, class defined oo, classless - test msgcat-15.1 {mc in class} -setup { + test msgcat-15.1 {mc in class setup} -setup { + # full namespace is ::msgcat::test:bar + namespace eval bar { + ::msgcat::mcset foo_BAR con2 con2bar + oo::class create ClassCur + } + variable locale [mclocale] + mclocale foo_BAR + } -cleanup { + mclocale $locale + namespace eval bar {::msgcat::mcforgetpackage} + namespace delete bar + } -body { + oo::define bar::ClassCur msgcat::mc con2 + } -result con2bar + + test msgcat-15.2 {mc in class} -setup { # full namespace is ::msgcat::test:bar namespace eval bar { ::msgcat::mcset foo_BAR con2 con2bar @@ -1122,7 +1138,7 @@ namespace eval ::msgcat::test { $baz::ObjCur method1 } -result con2bar - test msgcat-15.2 {mc in classless object} -setup { + test msgcat-15.3 {mc in classless object} -setup { # full namespace is ::msgcat::test:bar namespace eval bar { ::msgcat::mcset foo_BAR con2 con2bar @@ -1139,7 +1155,7 @@ namespace eval ::msgcat::test { bar::ObjCur method1 } -result con2bar - test msgcat-15.3 {mc in classless object with explicite namespace eval}\ + test msgcat-15.4 {mc in classless object with explicite namespace eval}\ -setup { # full namespace is ::msgcat::test:bar namespace eval bar { @@ -1171,7 +1187,18 @@ namespace eval ::msgcat::test { namespace eval baz {msgcat::mcpackagenamespaceget} } -result ::msgcat::test::baz - test msgcat-16.2 {mcpackagenamespaceget in class} -setup { + test msgcat-16.2 {mcpackagenamespaceget in class setup} -setup { + namespace eval bar { + oo::class create ClassCur + oo::define ClassCur variable a + } + } -cleanup { + namespace delete bar + } -body { + oo::define bar::ClassCur msgcat::mcpackagenamespaceget + } -result ::msgcat::test::bar + + test msgcat-16.3 {mcpackagenamespaceget in class} -setup { namespace eval bar { oo::class create ClassCur oo::define ClassCur method method1 {} {msgcat::mcpackagenamespaceget} @@ -1185,7 +1212,7 @@ namespace eval ::msgcat::test { $baz::ObjCur method1 } -result ::msgcat::test::bar - test msgcat-16.3 {mcpackagenamespaceget in classless object} -setup { + test msgcat-16.4 {mcpackagenamespaceget in classless object} -setup { namespace eval bar { oo::object create ObjCur oo::objdefine ObjCur method method1 {} {msgcat::mcpackagenamespaceget} @@ -1196,7 +1223,7 @@ namespace eval ::msgcat::test { bar::ObjCur method1 } -result ::msgcat::test::bar - test msgcat-16.4\ + test msgcat-16.5\ {mcpackagenamespaceget in classless object with explicite namespace eval}\ -setup { namespace eval bar { @@ -1216,7 +1243,12 @@ namespace eval ::msgcat::test { # Test msgcat-17.*: mcn command - test msgcat-17.1 {mcn} -setup { + test msgcat-17.1 {mcn no parameters} -body { + mcn + } -returnCodes 1\ + -result {wrong # args: should be "mcn ns src ?arg ...?"} + + test msgcat-17.2 {mcn} -setup { namespace eval bar {::msgcat::mcset foo_BAR con1 con1bar} variable locale [mclocale] mclocale foo_BAR -- cgit v0.12 From 7c60d44ce6b8c71d89857ce711a3f7f62ce2de2c Mon Sep 17 00:00:00 2001 From: oehhar Date: Tue, 16 Jan 2018 14:53:41 +0000 Subject: Comment updated --- library/msgcat/msgcat.tcl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 0b1079b..33ff5cb 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -1144,9 +1144,10 @@ proc msgcat::ConvertLocale {value} { } # helper function to find package namespace of stack-frame -2 -# There are 3 possibilities: +# There are 4 possibilities: # - called from a proc -# - called from a oo class +# - called within a class definition script +# - called from an class defined oo object # - called from a classless oo object proc ::msgcat::PackageNamespaceGet {} { uplevel 2 { -- cgit v0.12 From 67a242e0031c5c5108446b9fc1801d8dec548e70 Mon Sep 17 00:00:00 2001 From: dgp Date: Mon, 12 Mar 2018 13:48:35 +0000 Subject: msgcat 1.7 uses [tailcall], so requires Tcl 8.6. --- library/msgcat/msgcat.tcl | 2 +- library/msgcat/pkgIndex.tcl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/msgcat/msgcat.tcl b/library/msgcat/msgcat.tcl index 33ff5cb..203a1bf 100644 --- a/library/msgcat/msgcat.tcl +++ b/library/msgcat/msgcat.tcl @@ -11,7 +11,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. -package require Tcl 8.5- +package require Tcl 8.6- # When the version number changes, be sure to update the pkgIndex.tcl file, # and the installation directory in the Makefiles. package provide msgcat 1.7.0 diff --git a/library/msgcat/pkgIndex.tcl b/library/msgcat/pkgIndex.tcl index fe3b3a1..74a284f 100644 --- a/library/msgcat/pkgIndex.tcl +++ b/library/msgcat/pkgIndex.tcl @@ -1,2 +1,3 @@ -if {![package vsatisfies [package provide Tcl] 8.5-]} {return} +if {![package vsatisfies [package provide Tcl] 8.5]} {return} +if {![package vsatisfies [package provide Tcl] 8.6-]} {return} package ifneeded msgcat 1.7.0 [list source [file join $dir msgcat.tcl]] -- cgit v0.12