Debian Codegraph @

testsuite/modules.70-maint/420-lint.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: modules.70-maint/%M%
6 # Revision: %I%
7 # First Edition: 2022/06/20
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command: lint
14 # Modulefiles: lint
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Test lint sub-command
19 # }C%
20 #
21 ##############################################################################
22
23 # ensure lint tests have implicit default enabled
24 setenv_var MODULES_IMPLICIT_DEFAULT 1
25
26 set mp $modpath.3
27 set mpre $modpathre.3
28 setenv_path_var MODULEPATH $mp
29
30 # empty linter defined
31 setenv_var MODULES_TCL_LINTER {}
32 testouterr_cmd sh {lint lint/1.3} ERR "$error_msgs: No Tcl linter program configured"
33
34 # unknown linter defined
35 setenv_var MODULES_TCL_LINTER unk
36 testouterr_cmd sh {lint lint/1.3} ERR "$error_msgs: Command 'unk' cannot be found"
37 setenv_var MODULES_TCL_LINTER "/path/to/unk -arg val"
38 testouterr_cmd sh {lint lint/1.3} ERR "$error_msgs: Command '/path/to/unk' cannot be found"
39 setenv_var MODULES_TCL_LINTER "unk -arg val"
40 testouterr_cmd sh {lint lint/1.3} ERR "$error_msgs: Command 'unk' cannot be found"
41 testouterr_cmd sh {lint lint/1.3 lint/1.4} ERR "$error_msgs: Command 'unk' cannot be found"
42
43 # a specific linter defined
44 setenv_var MODULES_TCL_LINTER cat
45 testouterr_cmd sh {lint lint/1.3} ERR [msg_lint $mp/lint/1.3 "$error_msgs: #%Module"]
46 testouterr_cmd sh {lint lint/1.4} ERR [msg_lint $mp/lint/1.4 "$error_msgs: #%Module\nsource ./1.2\nsource ./unk"]
47
48 set nafelgar_script [glob -nocomplain nagelfar*/nagelfar.tcl]
49 if {[string length $nafelgar_script]} {
50
51 setenv_var MODULES_TCL_LINTER $nafelgar_script
52
53 # modulefile with no error
54 testouterr_cmd sh {lint lint/1.3} OK {}
55 testouterr_cmd sh {lint -v lint/1.3} OK [msg_lint $mp/lint/1.3]
56
57 # modulefile with warning
58 set lintmsg10 "$warn_msgs line 3: Unknown command \"unk\""
59 testouterr_cmd sh {lint lint/1.0} OK [msg_lint $mp/lint/1.0 $lintmsg10]
60 testouterr_cmd sh {lint lint/1.0 -s} OK {}
61
62 skip_if_quick_mode
63
64 # modulefile with error
65 set lintmsg11 {ERROR line 3: Bad expression: invalid bareword "test"
66 in expression "test";
67 should be "$test" or "{test}" or "test(...)" or ...}
68 testouterr_cmd sh {lint lint/1.1} ERR [msg_lint $mp/lint/1.1 $lintmsg11]
69 testouterr_cmd sh {lint lint/1.1 -s} ERR {}
70
71 # modulefile with multiple errors
72 set lintmsg12 [list {ERROR line 3: Could not complete statement.
73 One close brace would complete the first line
74 One close brace would complete at end of line 6.
75 One close brace would complete the script body at line 9.
76 Assuming completeness for further processing.} \
77 {ERROR line 3: Bad expression: missing operand at _@_
78 in expression ""str" eq_@_"} \
79 {WARNING line 5: Unknown command "else"} \
80 {NOTICE line 6: Close brace not aligned with line 5 (1 0)} \
81 {WARNING line 8: Unknown command "unk"}]
82 testouterr_cmd sh {lint lint/1.2} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]
83 testouterr_cmd sh {lint lint/1.2 -s} ERR {}
84
85 # test argument on linter command
86 setenv_var MODULES_TCL_LINTER "$nafelgar_script -len 78"
87 testouterr_cmd sh {lint lint/1.0} OK [msg_lint $mp/lint/1.0 $lintmsg10]
88 setenv_var MODULES_TCL_LINTER $nafelgar_script
89
90 # test linter location resolution through PATH
91 if {$install_tcllinter eq {nagelfar.tcl}} {
92 setenv_var PATH [file dirname $nafelgar_script]:$env(PATH)
93 unsetenv_var MODULES_TCL_LINTER
94 testouterr_cmd sh {lint lint/1.2} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]
95 setenv_var PATH $ORIG_PATH
96 setenv_var MODULES_TCL_LINTER $nafelgar_script
97 }
98
99 # modulefile sourcing other file
100 testouterr_cmd sh {lint lint/1.4} OK {}
101
102 # test implicit default disabled
103 if {![is_config_locked implicit_default]} {
104 setenv_var MODULES_ADVANCED_VERSION_SPEC 1
105 setenv_var MODULES_IMPLICIT_DEFAULT 1
106
107 # boolean variant test
108 testouterr_cmd sh {lint lint@1: -bool} ERR [err_invopt -bool]
109
110 # module resolution
111 testouterr_cmd sh {lint -v lint} OK [msg_lint $mp/lint/2.0]
112
113 # test advanced version spec
114 testouterr_cmd sh {lint -v lint @2:} OK [msg_lint $mp/lint/2.0]
115 testouterr_cmd sh {lint -v lint @1.0:1.3} OK [msg_lint $mp/lint/1.3]
116 testouterr_cmd sh {lint -v lint @1.0:1.3} OK [msg_lint $mp/lint/1.3]
117
118 unsetenv_var MODULES_ADVANCED_VERSION_SPEC
119 unsetenv_var MODULES_IMPLICIT_DEFAULT
120 }
121
122 # full path spec
123 testouterr_cmd sh "lint $mp/lint/1.3" OK {}
124 testouterr_cmd sh "lint $mp/lint/1.1" ERR [msg_lint $mp/lint/1.1 $lintmsg11]
125 testouterr_cmd sh "lint ./testsuite/modulefiles.3/lint/1.1 lint/1.0" ERR [msg_lint $mp/lint/1.0 $lintmsg10]\n\n[msg_lint $mp/lint/1.1 $lintmsg11]
126
127 # unexistent module
128 testouterr_cmd sh {lint lint/unk} ERR $err_path'lint/unk'
129 testouterr_cmd sh {lint -v lint/unk lint/2.0} ERR $err_path'lint/unk'\n[msg_lint $mp/lint/2.0]
130 testouterr_cmd sh {lint /path/to/unk} ERR $err_file'/path/to/unk'
131
132 # forbidden module
133 setenv_var TESTSUITE_LINT forbid1
134 testouterr_cmd sh {lint lint/1.0} ERR [err_accessdenied lint/1.0]
135 testouterr_cmd sh {lint lint/1.0 lint/1.1} ERR [err_accessdenied lint/1.0]\n\n[msg_lint $mp/lint/1.1 $lintmsg11]
136 unsetenv_var TESTSUITE_LINT
137
138 # multiple module specified on command line
139 # test error on first none on second
140 testouterr_cmd sh {lint lint/1.2 lint/1.3} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]
141 testouterr_cmd sh {lint -v lint/1.2 lint/1.3} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]\n\n[msg_lint $mp/lint/1.3]
142 # test none on first error on second
143 testouterr_cmd sh {lint lint/1.3 lint/1.2} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]
144 testouterr_cmd sh {lint -v lint/1.3 lint/1.2} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]\n\n[msg_lint $mp/lint/1.3]
145 # test error on both files checked
146 testouterr_cmd sh {lint lint/1.1 lint/1.2} ERR [msg_lint $mp/lint/1.1 $lintmsg11]\n\n[msg_lint $mp/lint/1.2 {*}$lintmsg12]
147 testouterr_cmd sh {lint -v lint/1.1 lint/1.2} ERR [msg_lint $mp/lint/1.1 $lintmsg11]\n\n[msg_lint $mp/lint/1.2 {*}$lintmsg12]
148 # test no error on both files checked
149 testouterr_cmd sh {lint lint/1.3 lint/2.0} OK {}
150 testouterr_cmd sh {lint -v lint/1.3 lint/2.0} OK [msg_lint $mp/lint/1.3]\n[msg_lint $mp/lint/2.0]
151
152 # file set as global rc file
153 setenv_var MODULERCFILE $env(TESTSUITEDIR)/etc/rc
154 testouterr_cmd sh "lint ${env(MODULERCFILE)}" OK {}
155
156 # modulefile commands used in global rc file
157 setenv_var MODULERCFILE $mp/lint/1.0
158 set tserr [msg_moderr {invalid command name "unk"} {unk} $mp/lint/1.0 3 { }]\n\n[msg_lint $mp/lint/1.0 $lintmsg10]
159 testouterr_cmd sh "lint ${env(MODULERCFILE)}" ERR $tserr
160
161 setenv_var MODULERCFILE $mp/keep/1.0
162 set lintmsgkeep10 [list {WARNING line 3: Command "module-whatis" should not be be used in global rc file}\
163 {WARNING line 8: Command "module" should not be be used in global rc file}\
164 {WARNING line 11: Command "prereq" should not be be used in global rc file}\
165 {WARNING line 14: Command "module" should not be be used in global rc file}\
166 {WARNING line 17: Command "always-load" should not be be used in global rc file}]
167 set tserr [msg_lint $mp/keep/1.0 {*}$lintmsgkeep10]
168 testouterr_cmd sh "lint ${env(MODULERCFILE)}" OK $tserr
169 setenv_var MODULERCFILE $ORIG_MODULERCFILE
170
171
172 # ml
173 # test implicit default disabled
174 if {![is_config_locked implicit_default]} {
175 setenv_var MODULES_ADVANCED_VERSION_SPEC 1
176 setenv_var MODULES_IMPLICIT_DEFAULT 1
177 testouterr_cmd sh {ml lint -v lint @2:} OK [msg_lint $mp/lint/2.0]
178 unsetenv_var MODULES_IMPLICIT_DEFAULT
179 unsetenv_var MODULES_ADVANCED_VERSION_SPEC
180 }
181 testouterr_cmd sh {ml lint lint/1.2} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]
182
183 # icase test
184 testouterr_cmd sh {lint -i lINt/1.2} ERR [msg_lint $mp/lint/1.2 {*}$lintmsg12]
185
186
187 # full linting
188 set lintmsgfoo10 [list "$warn_msgs line 21: Unknown command \"unk\""]
189 set lintmsgloadany10 "$warn_msgs line 8: Unknown command \"unk\""
190 set lintmsglist10 [list "$warn_msgs line 8: Command \"module list\" should not be used in modulefile"\
191 "$warn_msgs line 11: Command \"module list\" should not be used in modulefile"\
192 "$warn_msgs line 14: Command \"module list\" should not be used in modulefile"\
193 "$warn_msgs line 17: Command \"module list\" should not be used in modulefile"\
194 "$warn_msgs line 20: Command \"module list\" should not be used in modulefile"]
195 set lintmsgmodrc [list {ERROR line 35: Wrong number of arguments (3) to "module-alias"}\
196 {ERROR line 41: Wrong number of arguments (3) to "module-virtual"}]
197 set tserr .*[escre [msg_lint $mp/foo/1.0 {*}$lintmsgfoo10]]\n.*[escre [msg_lint $mp/lint/1.0 $lintmsg10]\n\n[msg_lint $mp/lint/1.1 $lintmsg11]\n\n[msg_lint $mp/lint/1.2 {*}$lintmsg12]\n\n[msg_lint $mp/list/1.0 {*}$lintmsglist10]\n\n[msg_lint $mp/loadany/1.0 $lintmsgloadany10]].*
198 testouterr_cmd_re sh {lint} ERR $tserr
199
200 # check modulepath and module-specific .modulerc
201 set tserr [msg_lint $env(MODULERCFILE)]\n
202 if {[file exists $mp/.modulecache]} {
203 append tserr [msg_lint $mpre/.modulecache]\n
204 }
205 append tserr \n[escre [msg_lint $mpre/.modulerc {*}$lintmsgmodrc]]\n\n[msg_lint $mpre/advvers/1.0]\n[msg_lint $mpre/advvers2/.modulerc].*
206 testouterr_cmd_re sh {lint -v} ERR $tserr
207
208 # check generated modulecache if any
209 if {[file exists $mp/.modulecache]} {
210 testouterr_cmd sh "lint $mp/.modulecache" OK {}
211 testouterr_cmd sh "lint -v $mp/.modulecache" OK [msg_lint $mp/.modulecache]
212 }
213
214 # check modulepath without error or warning
215 setenv_path_var MODULEPATH $modpath.path1
216 testouterr_cmd sh {lint} OK {}
217 setenv_path_var MODULEPATH $mp
218
219 # hidden module test
220 set tserr .*[msg_lint $mpre/key/5.0].*[escre [msg_lint $mp/lint/1.0 $lintmsg10]\n\n[msg_lint $mp/lint/1.1 $lintmsg11]\n\n[msg_lint $mp/lint/1.2 {*}$lintmsg12]].*[msg_lint '$mpre/variant/.w\ s'].*
221 testouterr_cmd_re sh {lint -v -a} ERR $tserr
222
223 # forbid modules returned
224 # alias and virtual targets returned only once
225 set lintmsgtagrc [list {ERROR line 14: Wrong number of arguments (0) to "module-tag"}\
226 {ERROR line 17: Wrong number of arguments (1) to "module-tag"}\
227 {ERROR line 20: Bad option --foo to "module-tag"}\
228 {ERROR line 23: Bad option --before to "module-tag"}\
229 {ERROR line 26: Bad option --after to "module-tag"}]
230 set tserr .*[escre [msg_lint $mpre/tag/.modulerc {*}$lintmsgtagrc]]\n\n[msg_lint $mpre/tag/1.0]\n[msg_lint $mpre/tag/4.0]\n[msg_lint $mpre/tag/5.0]\n.*
231 testouterr_cmd_re sh {lint -v} ERR $tserr
232
233
234 # ModuleVersion rename warning
235 set lintmsglcompatversion [list {WARNING line 6: Variable "ModuleVersion" should be renamed "ModulesVersion"}\
236 {WARNING line 10: Variable "ModuleVersion" should be renamed "ModulesVersion"}\
237 {WARNING line 13: Variable "ModuleVersion" should be renamed "ModulesVersion"}]
238 set tserr [msg_lint $mp/lcompat/.version {*}$lintmsglcompatversion]
239 testouterr_cmd sh "lint $mp/lcompat/.version" OK $tserr
240
241 # command not implemented
242 set lintmsglcompat12 [list {ERROR line 14: Wrong number of arguments (0) to "extensions"}]
243 set tserr [msg_lint $mp/lcompat/1.2 {*}$lintmsglcompat12]
244 testouterr_cmd sh {lint lcompat/1.2} ERR $tserr
245
246 # command deprecated and not implemented
247 setenv_path_var MODULEPATH $modpath
248 set lintmsglogerr [list {WARNING line 30: Command "module-log" is deprecated and not implemented}]
249 set tserr [msg_lint $modpath/log/err_syslog {*}$lintmsglogerr]
250 testouterr_cmd sh {lint log/err_syslog} OK $tserr
251
252 # should not be used in modulefile
253 setenv_path_var MODULEPATH $modpath.allin
254 set lintmsgallin1 [list {WARNING line 55: Command "module aliases" should not be used in modulefile}\
255 {WARNING line 56: Command "module avail" should not be used in modulefile}\
256 {WARNING line 57: Command "module display" should not be used in modulefile}\
257 {WARNING line 58: Command "module list" should not be used in modulefile}\
258 {WARNING line 59: Command "module save" should not be used in modulefile}\
259 {WARNING line 60: Command "module restore" should not be used in modulefile}\
260 {WARNING line 61: Command "module savelist" should not be used in modulefile}\
261 {WARNING line 62: Command "module saveshow" should not be used in modulefile}\
262 {WARNING line 63: Command "module saverm" should not be used in modulefile}\
263 {WARNING line 66: Command "module test" should not be used in modulefile}]
264 set lintmsgallin3 [list {WARNING line 28: Command "module whatis" should not be used in modulefile}]
265 set lintmsgallin4 [list {WARNING line 27: Command "module purge" should not be used in modulefile}\
266 {WARNING line 28: Command "module reload" should not be used in modulefile}]
267 set tserr [msg_lint $modpath.allin/allin/1 {*}$lintmsgallin1]\n\n[msg_lint $modpath.allin/allin/3 {*}$lintmsgallin3]\n\n[msg_lint $modpath.allin/allin/4 {*}$lintmsgallin4]
268 testouterr_cmd sh {lint} OK $tserr
269
270 # --delim=value argument test
271 setenv_path_var MODULEPATH $modpath
272 set tserr [msg_lint $modpath/prepend/1.6 "$error_msgs line 24: Wrong number of arguments (3) to \"prepend-path\""]
273 testouterr_cmd sh {lint prepend/1.6} ERR $tserr
274
275 # no MODULEPATH set
276 unsetenv_path_var MODULEPATH
277 set tserr "$error_msgs: $msg_nomodpath"
278 testouterr_cmd sh {lint} ERR $tserr
279 testouterr_cmd sh {lint foo/1.0} ERR $tserr
280 setenv_path_var MODULEPATH $mp
281
282
283 # access denied
284 # cannot test access if cannot change file permission
285 if {!$is_file_perms_editable} {
286 send_user "\tskipping access tests as file permissions cannot be changed\n"
287 # cannot test access if superuser privileges are in use
288 } elseif {$tcl_platform(user) eq {root}} {
289 send_user "\tskipping access tests as tests are run by superuser\n"
290 # cannot test access if restricted file permissions have no effect
291 } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
292 send_user "\tskipping access tests as locked files or directories are still readable\n"
293 } else {
294
295 set hide_perms ugo-rx
296
297 ignore_modulecache_if_built
298
299 # access denied on modulefile
300 change_file_perms $mp/lint/1.0 $hide_perms
301 testouterr_cmd sh {lint lint/1.0} ERR [err_permdenied $mp/lint/1.0]
302 testouterr_cmd sh "lint $mp/lint/1.0" ERR [err_permdenied $mp/lint/1.0]
303 restore_file_perms $mp/lint/1.0
304
305 # access denied on modulerc
306 change_file_perms $mp/.modulerc $hide_perms
307 change_file_perms $mp/advvers2/.modulerc $hide_perms
308 set tserr [msg_lint $env(MODULERCFILE)]\n
309 if {[file exists $mp/.modulecache]} {
310 append tserr [msg_lint $mpre/.modulecache]\n
311 }
312 append tserr [msg_lint $mpre/advvers/1.0]\n[msg_lint $mpre/advvers2/1.0]\n.*
313 testouterr_cmd_re sh {lint -v} ERR $tserr
314 restore_file_perms $mp/.modulerc
315 restore_file_perms $mp/advvers2/.modulerc
316
317 end_ignore_modulecache_if_built
318
319 # access denied on modulecache if any
320 if {[file exists $mp/.modulecache]} {
321 change_file_perms $mp/.modulecache $hide_perms
322 set tserr [msg_lint $env(MODULERCFILE)]\n\n
323 append tserr [escre [msg_lint $mpre/.modulerc {*}$lintmsgmodrc]]\n\n
324 append tserr [msg_lint $mpre/advvers/1.0]\n
325 append tserr [msg_lint $mpre/advvers2/.modulerc]\n[msg_lint $mpre/advvers2/1.0]\n.*
326 testouterr_cmd_re sh {lint -v} ERR $tserr
327 restore_file_perms $mp/.modulecache
328 }
329
330 }
331
332
333 # sgr warning/error/notice test
334 if {[siteconfig_isStderrTty]} {
335 setenv_var MODULES_COLORS hi=1:se=2:er=91:wa=93:in=94
336
337 set lintmsg12sgr [list "[sgr 91]ERROR line 3[sgr 0]: Could not complete statement.
338 One close brace would complete the first line
339 One close brace would complete at end of line 6.
340 One close brace would complete the script body at line 9.
341 Assuming completeness for further processing." \
342 "[sgr 91]ERROR line 3[sgr 0]: Bad expression: missing operand at _@_
343 in expression \"\"str\" eq_@_\"" \
344 "[sgr 93]WARNING line 5[sgr 0]: Unknown command \"else\"" \
345 "[sgr 94]NOTICE line 6[sgr 0]: Close brace not aligned with line 5 \\\(1 0\\\)" \
346 "[sgr 93]WARNING line 8[sgr 0]: Unknown command \"unk\""]
347
348 testouterr_cmd_re sh {--color=always lint lint/1.2} ERR [msg_lint [sgr 1]$mpre/lint/1.2[sgr 22] {*}$lintmsg12sgr]
349 unsetenv_var MODULES_COLORS
350 } else {
351 send_user "\tskipping sgr lint test, terminal not attached to tty\n"
352 }
353
354 } else {
355 send_user "\tskipping linting tests, nagelfar linter not found'\n"
356 }
357
358 #
359 # Cleanup
360 #
361
362 reset_test_env