Skip to content

Commit 01bbca0

Browse files
committed
Add -encoding option to superseded source command
Fix superseding definition of "source" Tcl command when "source_cache" configuration option is enabled to support "-encoding" option. The value set to this encoding option is currently ignored. Closes #627 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
1 parent b46f000 commit 01bbca0

5 files changed

Lines changed: 59 additions & 1 deletion

File tree

NEWS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ Modules 5.7.0 (not yet released)
7373
* Improve the performance of the module’s column output by removing the costly
7474
optimization that attempts to fit more columns within the available screen
7575
width. (fix issue #622)
76+
* Fix superseding definition of ``source`` Tcl command when
77+
:mconfig:`source_cache` configuration option is enabled to support
78+
``-encoding`` option. (fix issue #627)
7679

7780

7881
.. _5.6 release notes:

tcl/mfcmd.tcl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2278,7 +2278,23 @@ proc unique-name-conflict {} {
22782278
conflict {*}$root_name_list
22792279
}
22802280
2281-
proc sourceModfileCmd {itrp filename} {
2281+
proc sourceModfileCmd {itrp args} {
2282+
# argument parsing: catch encoding arg but ignore it
2283+
switch -- [llength $args] {
2284+
1 {}
2285+
3 {
2286+
set option [lindex $args 0]
2287+
if {$option ne {-encoding}} {
2288+
knerror "Invalid option '$option'"
2289+
}
2290+
}
2291+
default {
2292+
knerror {wrong # args: should be "source ?-encoding? ?encodingName?\
2293+
fileName"}
2294+
}
2295+
}
2296+
set filename [lindex $args end]
2297+
22822298
if {![info exists ::source_cache($filename)]} {
22832299
set ::source_cache($filename) [readFile $filename]
22842300
}

testsuite/modulefiles.4/source/1.0

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,17 @@ if {[info exists env(TESTSUITE_SOURCE_CACHE)]} {
3131
source ../path/to/unk
3232
setenv VAR bar
3333
}
34+
arg1 {
35+
source -encoding utf-8 [file dirname $ModulesCurrentModulefile]/source_file
36+
}
37+
bad_arg1 {
38+
source -encoding [file dirname $ModulesCurrentModulefile]/source_file
39+
}
40+
bad_arg2 {
41+
source -foo bar [file dirname $ModulesCurrentModulefile]/source_file
42+
}
43+
bad_arg3 {
44+
source -encoding utf-8 -foo bar [file dirname $ModulesCurrentModulefile]/source_file
45+
}
3446
}
3547
}

testsuite/modulefiles.4/source/source_file

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ if {[info exists env(TESTSUITE_SOURCE_CACHE)]} {
4040
break1 {
4141
break
4242
}
43+
arg1 - bad_arg1 - bad_arg2 {
44+
setenv VAR bar
45+
}
4346
}
4447
}

testsuite/modules.50-cmds/620-source_cache.exp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,30 @@ testouterr_cmd_re bash {load source/1.0} $ans_load $ts_load
290290

291291
}
292292

293+
294+
# check argument management
295+
setenv_var MODULES_SOURCE_CACHE 1
296+
setenv_var TESTSUITE_SOURCE_CACHE arg1
297+
set ans [list]
298+
lappend ans [list set VAR bar]
299+
lappend ans [list set _LMFILES_ $mp/source/1.0]
300+
lappend ans [list set LOADEDMODULES source/1.0]
301+
testouterr_cmd bash {load source/1.0} $ans {}
302+
303+
setenv_var TESTSUITE_SOURCE_CACHE bad_arg1
304+
set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 38}]
305+
set tserr [escre [msg_load source/1.0 [msg_moderr {wrong # args: should be "source ?-encoding? ?encodingName? fileName"} {source<EXM>} $mp/source/1.0 $line_num]]]
306+
testouterr_cmd_re bash {load source/1.0} ERR $tserr
307+
set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 41}]
308+
set tserr [escre [msg_load source/1.0 [msg_moderr {Invalid option '-foo'} {source<EXM>} $mp/source/1.0 $line_num]]]
309+
setenv_var TESTSUITE_SOURCE_CACHE bad_arg2
310+
testouterr_cmd_re bash {load source/1.0} ERR $tserr
311+
setenv_var TESTSUITE_SOURCE_CACHE bad_arg3
312+
set line_num [expr {[cmpversion $tclsh_version 8.6] == -1 ? 2 : 44}]
313+
set tserr [escre [msg_load source/1.0 [msg_moderr {wrong # args: should be "source ?-encoding? ?encodingName? fileName"} {source<EXM>} $mp/source/1.0 $line_num]]]
314+
testouterr_cmd_re bash {load source/1.0} ERR $tserr
315+
316+
293317
# cannot test access if cannot change file permission
294318
if {!$is_file_perms_editable} {
295319
send_user "\tskipping access tests as file permissions cannot be changed\n"

0 commit comments

Comments
 (0)