Raise error when reserved tag name is set

Raise an error when a reserved tag name is defined with module-tag.
Reserved names are currently: loaded, auto-loaded, forbidden,
nearly-forbidden and hidden.
This commit is contained in:
Xavier Delaruelle
2020-11-25 21:33:32 +01:00
parent 7b745207de
commit 4e6319be9d
4 changed files with 103 additions and 0 deletions

View File

@@ -48,6 +48,10 @@ Specification
- ``super-sticky``: loaded module cannot be unloaded even if forced
- ``hidden-loaded``: loaded module not reported by default in ``list`` result
- Tags inherited from module state cannot be set with ``module-tag`` command
- An error is otherwise thrown
- Modules project may introduce in the future new tags inherited from new states or new specific behaviors
- These new tags will supersede tags set by users using the same naming

View File

@@ -2675,6 +2675,10 @@ proc module-tag {args} {
if {![info exists modarglist]} {
knerror {No module specified in argument}
}
if {[isInList [list loaded auto-loaded forbidden nearly-forbidden hidden]\
$tag]} {
knerror "'$tag' is a reserved tag name and cannot be set"
}
# skip tag record if application criteria are not met
if {$apply} {

View File

@@ -23,6 +23,21 @@ if {[info exists env(TESTSUITE_MODULE_TAG_ERR4)]} {
if {[info exists env(TESTSUITE_MODULE_TAG_ERR5)]} {
module-tag --after 2020-11-01 foo tag/5.0
}
if {[info exists env(TESTSUITE_MODULE_TAG_ERR6)]} {
module-tag loaded tag/5.0
}
if {[info exists env(TESTSUITE_MODULE_TAG_ERR7)]} {
module-tag auto-loaded tag/5.0
}
if {[info exists env(TESTSUITE_MODULE_TAG_ERR8)]} {
module-tag forbidden tag/5.0
}
if {[info exists env(TESTSUITE_MODULE_TAG_ERR9)]} {
module-tag nearly-forbidden tag/5.0
}
if {[info exists env(TESTSUITE_MODULE_TAG_ERR10)]} {
module-tag hidden tag/5.0
}
if {[info exists env(TESTSUITE_MODULE_TAG_SET1)]} {
module-tag foo tag/5.0 tag/6.0

View File

@@ -134,6 +134,86 @@ unsetenv_var TESTSUITE_MODULE_TAG_ERR5
# same error rendering than module-tag/module-forbid, so rely on tests made for
# these two modulefile commands to check contexts other than load
# test use of reserved tag name
setenv_var TESTSUITE_MODULE_TAG_ERR6 1
set errmsg {module-tag loaded tag/5.0}
if {[cmpversion $tclsh_version 8.6] == -1} {
set custom " invoked from within
\"if \{\[info exists env(TESTSUITE_MODULE_TAG_ERR6)\]\} \{
$errmsg
\}\""
set linenum 26
} else {
set custom {}
set linenum 27
}
set tserr [msg_moderr {'loaded' is a reserved tag name and cannot be set} $errmsg $mp/tag/.modulerc $linenum { } {} {} $custom]
testouterr_cmd sh {load tag/5.0} $ans $tserr
unsetenv_var TESTSUITE_MODULE_TAG_ERR6
setenv_var TESTSUITE_MODULE_TAG_ERR7 1
set errmsg {module-tag auto-loaded tag/5.0}
if {[cmpversion $tclsh_version 8.6] == -1} {
set custom " invoked from within
\"if \{\[info exists env(TESTSUITE_MODULE_TAG_ERR7)\]\} \{
$errmsg
\}\""
set linenum 29
} else {
set custom {}
set linenum 30
}
set tserr [msg_moderr {'auto-loaded' is a reserved tag name and cannot be set} $errmsg $mp/tag/.modulerc $linenum { } {} {} $custom]
testouterr_cmd sh {load tag/5.0} $ans $tserr
unsetenv_var TESTSUITE_MODULE_TAG_ERR7
setenv_var TESTSUITE_MODULE_TAG_ERR8 1
set errmsg {module-tag forbidden tag/5.0}
if {[cmpversion $tclsh_version 8.6] == -1} {
set custom " invoked from within
\"if \{\[info exists env(TESTSUITE_MODULE_TAG_ERR8)\]\} \{
$errmsg
\}\""
set linenum 32
} else {
set custom {}
set linenum 33
}
set tserr [msg_moderr {'forbidden' is a reserved tag name and cannot be set} $errmsg $mp/tag/.modulerc $linenum { } {} {} $custom]
testouterr_cmd sh {load tag/5.0} $ans $tserr
unsetenv_var TESTSUITE_MODULE_TAG_ERR8
setenv_var TESTSUITE_MODULE_TAG_ERR9 1
set errmsg {module-tag nearly-forbidden tag/5.0}
if {[cmpversion $tclsh_version 8.6] == -1} {
set custom " invoked from within
\"if \{\[info exists env(TESTSUITE_MODULE_TAG_ERR9)\]\} \{
$errmsg
\}\""
set linenum 35
} else {
set custom {}
set linenum 36
}
set tserr [msg_moderr {'nearly-forbidden' is a reserved tag name and cannot be set} $errmsg $mp/tag/.modulerc $linenum { } {} {} $custom]
testouterr_cmd sh {load tag/5.0} $ans $tserr
unsetenv_var TESTSUITE_MODULE_TAG_ERR9
setenv_var TESTSUITE_MODULE_TAG_ERR10 1
set errmsg {module-tag hidden tag/5.0}
if {[cmpversion $tclsh_version 8.6] == -1} {
set custom " invoked from within
\"if \{\[info exists env(TESTSUITE_MODULE_TAG_ERR10)\]\} \{
$errmsg
\}\""
set linenum 38
} else {
set custom {}
set linenum 39
}
set tserr [msg_moderr {'hidden' is a reserved tag name and cannot be set} $errmsg $mp/tag/.modulerc $linenum { } {} {} $custom]
testouterr_cmd sh {load tag/5.0} $ans $tserr
unsetenv_var TESTSUITE_MODULE_TAG_ERR10
#
# regular usages