Tcl Source Code

Check-in [4c6197ca80]
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:Added tests for mcforgetpackage, mcpackagelocale and mcpackageconfig
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | msgcat_dyn_locale | tip-412
Files: files | file ages | folders
SHA1: 4c6197ca80269af157c002344de78acc58400160
User & Date: oehhar 2015-06-29 21:26:24
Context
2015-06-29
21:44
[TIP 412] msgcat dynamic locale change and package private locale (msgcat 1.6.0) check-in: 392ff6199d user: oehhar tags: trunk
21:26
Added tests for mcforgetpackage, mcpackagelocale and mcpackageconfig Closed-Leaf check-in: 4c6197ca80 user: oehhar tags: msgcat_dyn_locale, tip-412
2015-06-26
15:16
Tests for mcexists and mcloadedlocales check-in: 9806884e41 user: oehhar tags: msgcat_dyn_locale
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to library/msgcat/msgcat.tcl.

   464    464       }
   465    465       set ns [uplevel 1 {::namespace current}]
   466    466       
   467    467       switch -exact -- $subcommand {
   468    468   	get { return [lindex [PackagePreferences $ns] 0] }
   469    469   	preferences { return [PackagePreferences $ns] }
   470    470   	loaded { return [PackageLocales $ns] }
   471         -	isset {	return [dict exists $PackageConfig loclist $ns] }
   472         -	set {	# set a package locale or add a package locale
          471  +	present { return [expr {$locale in [PackageLocales $ns]} ]}
          472  +	isset { return [dict exists $PackageConfig loclist $ns] }
          473  +	set { # set a package locale or add a package locale
   473    474   
   474    475   	    # Copy the default locale if no package locale set so far
   475    476   	    if {![dict exists $PackageConfig loclist $ns]} {
   476    477   		dict set PackageConfig loclist $ns $Loclist
   477    478   		dict set PackageConfig loadedlocales $ns $LoadedLocales
   478    479   	    }
   479    480   
................................................................................
   663    664   		mcfolder { return [Load $ns [PackageLocales $ns]] }
   664    665   		loadcmd { return [Load $ns [PackageLocales $ns] 1] }
   665    666   	    }
   666    667   	    return 0
   667    668   	}
   668    669   	default {
   669    670   	    return -code error "unknown subcommand \"$subcommand\":\
   670         -		    must be get, isset, unset, or set"
          671  +		    must be get, isset, set, or unset"
   671    672   	}
   672    673       }
   673    674       return
   674    675   }
   675    676   
   676    677   # msgcat::PackagePreferences --
   677    678   #

Changes to tests/msgcat.test.

   431    431       # Even though foo_BAR_notexist does not exist,
   432    432       # foo_BAR, foo and the root should be loaded.
   433    433   	test msgcat-5.4 {mcload} -setup {
   434    434   	    variable locale [mclocale]
   435    435   	    mclocale foo_BAR_notexist
   436    436   	} -cleanup {
   437    437   	    mclocale $locale
   438         -	    ::msgcat::mcloadedlocales clear
   439         -	    ::msgcat::mcpackageconfig unset mcfolder 
          438  +	    mcloadedlocales clear
          439  +	    mcpackageconfig unset mcfolder 
   440    440   	} -body {
   441    441   	    mcload $msgdir
   442    442   	} -result 3
   443    443   
   444    444   	test msgcat-5.5 {mcload} -setup {
   445    445   	    variable locale [mclocale]
   446    446   	    mclocale no_FI_notexist
   447    447   	} -cleanup {
   448    448   	    mclocale $locale
   449         -	    ::msgcat::mcloadedlocales clear
   450         -	    ::msgcat::mcpackageconfig unset mcfolder 
          449  +	    mcloadedlocales clear
          450  +	    mcpackageconfig unset mcfolder 
   451    451   	} -body {
   452    452   	    mcload $msgdir
   453    453   	} -result 1
   454    454   
   455    455   	test msgcat-5.6 {mcload} -setup {
   456    456   	    variable locale [mclocale]
   457    457   	    mclocale foo
................................................................................
   503    503   	} -cleanup {
   504    504   	    mclocale $locale
   505    505   	    rename ::msgcat::mcunknown {}
   506    506   	    rename SavedMcunknown ::msgcat::mcunknown
   507    507   	} -body {
   508    508   	    mc def
   509    509   	} -result unknown:no_fi_notexist:def
          510  +
          511  +	test msgcat-5.11 {mcpackageconfig mcfolder} -setup {
          512  +	    variable locale [mclocale]
          513  +	    mclocale ""
          514  +	    mcloadedlocales clear
          515  +	    mcpackageconfig unset mcfolder
          516  +	} -cleanup {
          517  +	    mclocale $locale
          518  +	    mcloadedlocales clear
          519  +	    mcpackageconfig unset mcfolder 
          520  +	} -body {
          521  +	    mclocale foo
          522  +	    mcpackageconfig set mcfolder $msgdir
          523  +	} -result 2
   510    524   
   511    525       foreach loc $locales {
   512    526   	if { $loc eq {} } {
   513    527   	    set msg ROOT
   514    528           } else {
   515    529   	    set msg [string tolower $loc]
   516    530   	}
................................................................................
   733    747   	    variable locale [mclocale]
   734    748   	    mclocale {}
   735    749   	    mcloadedlocales clear
   736    750   	} -cleanup {
   737    751   	    mclocale $locale
   738    752   	} -body {
   739    753   	    mclocale foo_bar
   740         -	    set resultlist [mcloadedlocales loaded]
   741         -	    # The result is position independent so check length and existence
   742         -	    list [llength $resultlist] [expr {"" in $resultlist}]\
   743         -		    [expr {"foo" in $resultlist}]\
   744         -		    [expr {"foo_bar" in $resultlist}]
   745         -	} -result {3 1 1 1}
          754  +	    # The result is position independent so sort
          755  +	    set resultlist [lsort [mcloadedlocales loaded]]
          756  +	} -result {{} foo foo_bar}
   746    757       
   747    758   	test msgcat-10.4 {mcloadedlocales clear} -setup {
   748    759   	    mcforgetpackage
   749    760   	    variable locale [mclocale]
   750    761   	    mclocale {}
   751    762   	    mcloadedlocales clear
   752    763   	} -cleanup {
................................................................................
   756    767   	    mcset foo k1 v1
   757    768   	    set res [mcexists k1]
   758    769   	    mclocale ""
   759    770   	    mcloadedlocales clear
   760    771   	    mclocale foo
   761    772   	    lappend res [mcexists k1]
   762    773   	} -result {1 0}
          774  +
          775  +    # Tests msgcat-11.*: [mcforgetpackage]
          776  +
          777  +	test msgcat-11.1 {mcforgetpackage translation} -setup {
          778  +	    variable locale [mclocale]
          779  +	} -cleanup {
          780  +	    mclocale $locale
          781  +	} -body {
          782  +	    mclocale foo
          783  +	    mcset foo k1 v1
          784  +	    set res [mcexists k1]
          785  +	    mcforgetpackage
          786  +	    lappend res [mcexists k1]
          787  +	} -result {1 0}
          788  +
          789  +	test msgcat-11.2 {mcforgetpackage locale} -setup {
          790  +	    variable locale [mclocale]
          791  +	} -cleanup {
          792  +	    mclocale $locale
          793  +	} -body {
          794  +	    mclocale foo
          795  +	    mcpackagelocale set bar
          796  +	    set res [mcpackagelocale get]
          797  +	    mcforgetpackage
          798  +	    lappend res [mcpackagelocale get]
          799  +	} -result {bar foo}
          800  +
          801  +	test msgcat-11.3 {mcforgetpackage options} -body {
          802  +	    mcpackageconfig set loadcmd ""
          803  +	    set res [mcpackageconfig isset loadcmd]
          804  +	    mcforgetpackage
          805  +	    lappend res [mcpackageconfig isset loadcmd]
          806  +	} -result {1 0}
          807  +
          808  +    # Tests msgcat-12.*: [mcpackagelocale]
          809  +
          810  +	test msgcat-12.1 {mcpackagelocale no subcommand} -body {
          811  +	    mcpackagelocale
          812  +	} -returnCodes 1\
          813  +	-result {wrong # args: should be "mcpackagelocale subcommand ?locale?"}
          814  +
          815  +	test msgcat-12.2 {mclpackagelocale wrong subcommand} -body {
          816  +	    mcpackagelocale junk
          817  +	} -returnCodes 1\
          818  +	-result {unknown subcommand "junk": must be clear, get, isset, loaded, present, set, or unset}
          819  +
          820  +	test msgcat-12.3 {mcpackagelocale set} -setup {
          821  +	    variable locale [mclocale]
          822  +	} -cleanup {
          823  +	    mclocale $locale
          824  +	    mcforgetpackage
          825  +	} -body {
          826  +	    mclocale foo
          827  +	    mcpackagelocale set bar
          828  +	    list [mcpackagelocale get] [mclocale]
          829  +	} -result {bar foo}
          830  +
          831  +	test msgcat-12.4 {mcpackagelocale get} -setup {
          832  +	    variable locale [mclocale]
          833  +	} -cleanup {
          834  +	    mclocale $locale
          835  +	    mcforgetpackage
          836  +	} -body {
          837  +	    mclocale foo
          838  +	    set res [mcpackagelocale get]
          839  +	    mcpackagelocale set bar
          840  +	    lappend res [mcpackagelocale get]
          841  +	} -result {foo bar}
          842  +
          843  +	test msgcat-12.5 {mcpackagelocale preferences} -setup {
          844  +	    variable locale [mclocale]
          845  +	} -cleanup {
          846  +	    mclocale $locale
          847  +	    mcforgetpackage
          848  +	} -body {
          849  +	    mclocale foo
          850  +	    set res [list [mcpackagelocale preferences]]
          851  +	    mcpackagelocale set bar
          852  +	    lappend res [mcpackagelocale preferences]
          853  +	} -result {{foo {}} {bar {}}}
          854  +
          855  +	test msgcat-12.6 {mcpackagelocale loaded} -setup {
          856  +	    variable locale [mclocale]
          857  +	} -cleanup {
          858  +	    mclocale $locale
          859  +	    mcforgetpackage
          860  +	} -body {
          861  +	    mclocale ""
          862  +	    mcloadedlocales clear
          863  +	    mclocale foo
          864  +	    # The result is position independent so sort
          865  +	    set res [list [lsort [mcpackagelocale loaded]]]
          866  +	    mcpackagelocale set bar
          867  +	    lappend res [lsort [mcpackagelocale loaded]]
          868  +	} -result {{{} foo} {{} bar foo}}
          869  +
          870  +	test msgcat-12.7 {mcpackagelocale isset} -setup {
          871  +	    variable locale [mclocale]
          872  +	} -cleanup {
          873  +	    mclocale $locale
          874  +	    mcforgetpackage
          875  +	} -body {
          876  +	    mclocale foo
          877  +	    set res [mcpackagelocale isset]
          878  +	    mcpackagelocale set bar
          879  +	    lappend res [mcpackagelocale isset]
          880  +	} -result {0 1}
          881  +
          882  +	test msgcat-12.8 {mcpackagelocale unset} -setup {
          883  +	    variable locale [mclocale]
          884  +	} -cleanup {
          885  +	    mclocale $locale
          886  +	    mcforgetpackage
          887  +	} -body {
          888  +	    mcpackagelocale set bar
          889  +	    set res [mcpackagelocale isset]
          890  +	    mcpackagelocale unset
          891  +	    lappend res [mcpackagelocale isset]
          892  +	} -result {1 0}
          893  +
          894  +	test msgcat-12.9 {mcpackagelocale present} -setup {
          895  +	    variable locale [mclocale]
          896  +	} -cleanup {
          897  +	    mclocale $locale
          898  +	    mcforgetpackage
          899  +	} -body {
          900  +	    mclocale ""
          901  +	    mcloadedlocales clear
          902  +	    mclocale foo
          903  +	    set res [mcpackagelocale present foo]
          904  +	    lappend res [mcpackagelocale present bar]
          905  +	    mcpackagelocale set bar
          906  +	    lappend res [mcpackagelocale present foo]\
          907  +		    [mcpackagelocale present bar]
          908  +	} -result {1 0 1 1}
          909  +
          910  +	test msgcat-12.10 {mcpackagelocale clear} -setup {
          911  +	    variable locale [mclocale]
          912  +	} -cleanup {
          913  +	    mclocale $locale
          914  +	    mcforgetpackage
          915  +	} -body {
          916  +	    mclocale ""
          917  +	    mcloadedlocales clear
          918  +	    mclocale foo
          919  +	    mcpackagelocale set bar
          920  +	    mcpackagelocale clear
          921  +	    list [mcpackagelocale present foo] [mcpackagelocale present bar]
          922  +	} -result {0 1}
          923  +
          924  +    # Tests msgcat-13.*: [mcpackageconfig subcmds]
          925  +
          926  +	test msgcat-13.1 {mcpackageconfig no subcommand} -body {
          927  +	    mcpackageconfig
          928  +	} -returnCodes 1\
          929  +	-result {wrong # args: should be "mcpackageconfig subcommand option ?value?"}
          930  +
          931  +	test msgcat-13.2 {mclpackageconfig wrong subcommand} -body {
          932  +	    mcpackageconfig junk mcfolder
          933  +	} -returnCodes 1\
          934  +	-result {unknown subcommand "junk": must be get, isset, set, or unset}
          935  +
          936  +	test msgcat-13.3 {mclpackageconfig wrong option} -body {
          937  +	    mcpackageconfig get junk
          938  +	} -returnCodes 1\
          939  +	-result {bad option "junk": must be mcfolder, loadcmd, changecmd, or unknowncmd}
          940  +
          941  +	test msgcat-13.4 {mcpackageconfig get} -setup {
          942  +	    mcforgetpackage
          943  +	} -cleanup {
          944  +	    mcforgetpackage
          945  +	} -body {
          946  +	    mcpackageconfig set loadcmd ""
          947  +	    mcpackageconfig get loadcmd
          948  +	} -result {}
          949  +
          950  +	test msgcat-13.5 {mcpackageconfig (is/un)set} -setup {
          951  +	    mcforgetpackage
          952  +	} -cleanup {
          953  +	    mcforgetpackage
          954  +	} -body {
          955  +	    set res [mcpackageconfig isset loadcmd]
          956  +	    lappend res [mcpackageconfig set loadcmd ""]
          957  +	    lappend res [mcpackageconfig isset loadcmd]
          958  +	    mcpackageconfig unset loadcmd
          959  +	    lappend res [mcpackageconfig isset loadcmd]
          960  +	} -result {0 0 1 0}
          961  +
          962  +    # option mcfolder is already tested with 5.11
          963  +    
          964  +    # Tests msgcat-14.*: callbacks: loadcmd, changecmd, unknowncmd
          965  +    
          966  +    # This routine is used as bgerror and by direct callback invocation
          967  +    proc callbackproc args {
          968  +	variable resultvariable
          969  +	set resultvariable $args
          970  +    }
          971  +    proc callbackfailproc args {
          972  +	return -code error fail
          973  +    }
          974  +    set bgerrorsaved [interp bgerror {}]
          975  +    interp bgerror {} [namespace code callbackproc]
   763    976       
          977  +	test msgcat-14.1 {invokation loadcmd} -setup {
          978  +	    mcforgetpackage
          979  +    	    mclocale $locale
          980  +	    mclocale ""
          981  +	    mcloadedlocales clear
          982  +	    set resultvariable ""
          983  +	} -cleanup {
          984  +	    mcforgetpackage
          985  +	} -body {
          986  +	    mcpackageconfig set loadcmd [namespace code callbackproc]
          987  +	    mclocale foo_bar
          988  +	    lsort $resultvariable
          989  +	} -result {foo foo_bar}
          990  +
          991  +	test msgcat-14.2 {invokation failed in loadcmd} -setup {
          992  +	    mcforgetpackage
          993  +    	    mclocale $locale
          994  +	    mclocale ""
          995  +	    mcloadedlocales clear
          996  +	} -cleanup {
          997  +	    mcforgetpackage
          998  +	} -body {
          999  +	    mcpackageconfig set loadcmd [namespace code callbackfailproc]
         1000  +	    mclocale foo_bar
         1001  +	    # let the bgerror run
         1002  +	    after 100 set [namespace current]::resultvariable timeout
         1003  +	    vwait [namespace current]::resultvariable
         1004  +	    lassign $resultvariable err errdict
         1005  +	    list $err [dict get $errdict -code]
         1006  +	} -result {fail 1}
         1007  +
         1008  +	test msgcat-14.3 {invokation changecmd} -setup {
         1009  +	    mcforgetpackage
         1010  +    	    mclocale $locale
         1011  +	    mclocale ""
         1012  +	    set resultvariable ""
         1013  +	} -cleanup {
         1014  +	    mcforgetpackage
         1015  +	} -body {
         1016  +	    mcpackageconfig set changecmd [namespace code callbackproc]
         1017  +	    mclocale foo_bar
         1018  +	    set resultvariable
         1019  +	} -result {foo_bar foo {}}
         1020  +
         1021  +	test msgcat-14.4 {invokation unknowncmd} -setup {
         1022  +	    mcforgetpackage
         1023  +    	    mclocale $locale
         1024  +	    mclocale ""
         1025  +	    mcloadedlocales clear
         1026  +	    set resultvariable ""
         1027  +	} -cleanup {
         1028  +	    mcforgetpackage
         1029  +	} -body {
         1030  +	    mcpackageconfig set unknowncmd [namespace code callbackproc]
         1031  +	    mclocale foo_bar
         1032  +	    mc k1 p1
         1033  +	    set resultvariable
         1034  +	} -result {foo_bar k1 p1}
         1035  +
         1036  +	test msgcat-14.5 {disable global unknowncmd} -setup {
         1037  +	    mcforgetpackage
         1038  +    	    mclocale $locale
         1039  +	    mclocale ""
         1040  +	    mcloadedlocales clear
         1041  +	    set resultvariable ""
         1042  +	    rename ::msgcat::mcunknown SavedMcunknown
         1043  +	    proc ::msgcat::mcunknown {dom s} {
         1044  +		return unknown:$dom:$s
         1045  +	    }
         1046  +	} -cleanup {
         1047  +	    mcforgetpackage
         1048  +	    rename ::msgcat::mcunknown {}
         1049  +	    rename SavedMcunknown ::msgcat::mcunknown
         1050  +	} -body {
         1051  +	    mcpackageconfig set unknowncmd ""
         1052  +	    mclocale foo_bar
         1053  +	    mc k1%s p1
         1054  +	} -result {k1p1}
         1055  +
         1056  +	test msgcat-14.6 {unknowncmd failing} -setup {
         1057  +	    mcforgetpackage
         1058  +    	    mclocale $locale
         1059  +	    mclocale ""
         1060  +	    mcloadedlocales clear
         1061  +	    set resultvariable ""
         1062  +	} -cleanup {
         1063  +	    mcforgetpackage
         1064  +	} -body {
         1065  +	    mcpackageconfig set unknowncmd [namespace code callbackfailproc]
         1066  +	    mclocale foo_bar
         1067  +	    mc k1
         1068  +	} -returnCodes 1\
         1069  +	-result {fail}
         1070  +
         1071  +    interp bgerror {} $bgerrorsaved
         1072  +
   764   1073       cleanupTests
   765   1074   }
   766   1075   namespace delete ::msgcat::test
   767   1076   return
   768   1077