Debian Codegraph @

testsuite/modules.70-maint/451-stashpop.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/09/22
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: Xavier Delaruelle, [email protected]
11 #
12 # Description: Testuite testsequence
13 # Command: stashpop
14 # Modulefiles: foo, bar
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Test stashpop sub-command
19 # }C%
20 #
21 ##############################################################################
22
23 set mp $modpath.3
24 setenv_path_var MODULEPATH $mp
25
26 set collhome $env(HOME)/.module
27 set stashcollglob $collhome/stash-*
28
29 set stash_basic_content "module use --append $mp
30 module load foo/1.0
31 module load bar/1.0\n"
32 set stash_basic2_content "module use --append $mp
33 module load bar/1.0\n"
34
35
36 #
37 # basic tests
38 #
39
40 testouterr_cmd sh stashpop ERR [err_stash_index 0]
41 testouterr_cmd sh {stashpop 1} ERR [err_stash_index 1]
42
43 create_stash_coll $stash_basic_content
44 set ans [list]
45 lappend ans [list set _LMFILES_ $mp/foo/1.0:$mp/bar/1.0]
46 lappend ans [list set LOADEDMODULES foo/1.0:bar/1.0]
47 set tserr [msg_load {foo/1.0}]\n[msg_load {bar/1.0}]
48 testouterr_cmd sh stashpop $ans $tserr
49 testouterr_cmd sh stashpop ERR [err_stash_index 0]
50
51 create_stash_coll $stash_basic_content
52 set last_stash [file tail [get_last_stash_coll]]
53 testouterr_cmd sh "stashpop $last_stash" $ans $tserr
54 testouterr_cmd sh "stashpop $last_stash" ERR [err_coll_notfound $last_stash]
55
56 skip_if_quick_mode
57
58
59 #
60 # stash argument tests
61 #
62
63 # no .module dir
64 file delete $collhome
65 testouterr_cmd sh stashpop ERR [err_stash_index 0]
66
67 # create regular collection file (not a stash one)
68 file mkdir $collhome
69 set fid [open $collhome/coll w]
70 puts "module use --append $mp
71 module load foo/1.0"
72 close $fid
73
74 # no stash collection
75 testouterr_cmd sh stashpop ERR [err_stash_index 0]
76
77 # empty argument
78 testouterr_cmd sh "stashpop " ERR [err_stash_name {}]
79
80 # negative index
81 testouterr_cmd sh {stashpop -1} ERR [err_invopt -1]
82
83 # large number
84 if {[cmpversion $tclsh_version 8.6] == 1} {
85 testouterr_cmd sh {stashpop 123456789012345} ERR [err_stash_index 123456789012345]
86 } else {
87 testouterr_cmd sh {stashpop 123456789012345} ERR [err_stash_name 123456789012345]
88 }
89
90 # index padded with space (no collection file)
91 testouterr_cmd sh {stashpop \ 0\ } ERR [err_stash_index { 0 }]
92
93 # index padded with space (collection file exists)
94 create_stash_coll $stash_basic_content
95 testouterr_cmd sh {stashpop \ 0\ } $ans $tserr
96
97 # create regular collection file (not a stash one) but with similar name
98 set fid [open $collhome/stash w]
99 puts "module use --append $mp
100 module load foo/1.0"
101 close $fid
102 set fid [open $collhome/stash123456789 w]
103 puts "module use --append $mp
104 module load foo/1.0"
105 close $fid
106
107 # collection name that looks like stash collection
108 testouterr_cmd sh {stashpop stash} ERR [err_stash_name stash]
109 testouterr_cmd sh {stashpop stash123456789} ERR [err_stash_name stash123456789]
110
111 # same tests but with files that do not exist
112 file delete $collhome/stash
113 file delete $collhome/stash123456789
114 testouterr_cmd sh {stashpop stash} ERR [err_stash_name stash]
115 testouterr_cmd sh {stashpop stash123456789} ERR [err_stash_name stash123456789]
116
117 # different collection name (that does not exist)
118 testouterr_cmd sh {stashpop other} ERR [err_stash_name other]
119 # different collection name (that does exist)
120 testouterr_cmd sh {stashpop coll} ERR [err_stash_name coll]
121
122
123 #
124 # autoload tests
125 #
126
127 setenv_loaded_module [list foo/1.0 reset/1] [list $mp/foo/1.0 $mp/reset/1]
128 setenv_var __MODULES_LMPREREQ reset/1&foo/1.0
129 setenv_var __MODULES_LMTAG foo/1.0&auto-loaded
130
131 # autoload done with 'module load' in no-auto mode
132 setenv_var TESTSUITE_RESET load1
133 set ans [list]
134 lappend ans [list unset __MODULES_LMPREREQ]
135 lappend ans [list set _LMFILES_ $mp/bar/1.0]
136 lappend ans [list set LOADEDMODULES bar/1.0]
137 lappend ans [list unset __MODULES_LMTAG]
138 # auto-loaded foo/1.0 is not auto-unloaded by reset/1, as performed
139 # during a restore or purge sub-command
140 set tserr unload-1\n[msg_unload {reset/1}]\n[msg_unload {foo/1.0 <aL>}]\n[msg_load bar/1.0]
141 create_stash_coll $stash_basic2_content
142 testouterr_cmd sh {stashpop --auto} $ans $tserr
143 create_stash_coll $stash_basic2_content
144 testouterr_cmd sh {stashpop --no-auto} $ans $tserr
145
146 # autoload done with 'module switch' in no-auto mode
147 setenv_var TESTSUITE_RESET switch1
148 create_stash_coll $stash_basic2_content
149 testouterr_cmd sh {stashpop --auto} $ans $tserr
150 create_stash_coll $stash_basic2_content
151 testouterr_cmd sh {stashpop --no-auto} $ans $tserr
152
153 unsetenv_var TESTSUITE_RESET
154 unsetenv_var __MODULES_LMPREREQ
155 unsetenv_var __MODULES_LMTAG
156 unsetenv_loaded_module
157
158
159 #
160 # stash order
161 #
162
163 create_stash_coll $stash_basic_content
164 after 2
165 create_stash_coll $stash_basic2_content
166
167 set ans [list]
168 lappend ans [list set _LMFILES_ $mp/foo/1.0:$mp/bar/1.0]
169 lappend ans [list set LOADEDMODULES foo/1.0:bar/1.0]
170 set tserr [msg_load {foo/1.0}]\n[msg_load {bar/1.0}]
171
172 testouterr_cmd sh {stashpop 1} $ans $tserr
173
174 create_stash_coll $stash_basic_content
175 testouterr_cmd sh {stashpop 0} $ans $tserr
176
177 delete_last_stash_coll
178
179
180 #
181 # no difference with current environment
182 #
183
184 create_stash_coll $stash_basic_content
185 setenv_loaded_module [list foo/1.0 bar/1.0] [list $mp/foo/1.0 $mp/bar/1.0]
186
187 # restore does not change environment, but stash collection is removed
188 testouterr_cmd sh stashpop OK {}
189 testouterr_cmd sh stashpop ERR [err_stash_index 0]
190
191 unsetenv_loaded_module
192
193
194 #
195 # collection target
196 #
197
198 setenv_var MODULES_COLLECTION_TARGET foo
199 set ans [list]
200 lappend ans [list set _LMFILES_ $mp/foo/1.0:$mp/bar/1.0]
201 lappend ans [list set LOADEDMODULES foo/1.0:bar/1.0]
202 set tserr [msg_load {foo/1.0}]\n[msg_load {bar/1.0}]
203 create_stash_coll $stash_basic_content
204
205 testouterr_cmd sh stashpop $ans $tserr
206 testouterr_cmd sh stashpop ERR [err_stash_index 0]
207
208 create_stash_coll $stash_basic_content
209 after 2
210 create_stash_coll $stash_basic_content
211
212 testouterr_cmd sh {stashpop 1} $ans $tserr
213 testouterr_cmd sh {stashpop 1} ERR [err_stash_index 1]
214
215 # collection 0.foo remaining, changing collection target
216 setenv_var MODULES_COLLECTION_TARGET bar
217 testouterr_cmd sh stashpop ERR [err_stash_index 0]
218
219 # collection 0.foo remaining, removing collection target
220 unsetenv_var MODULES_COLLECTION_TARGET
221 testouterr_cmd sh stashpop ERR [err_stash_index 0]
222
223 setenv_var MODULES_COLLECTION_TARGET foo
224 create_stash_coll $stash_basic_content
225
226 # collection 0.foo and 1.foo exist, chanfing collection target
227 setenv_var MODULES_COLLECTION_TARGET bar
228 testouterr_cmd sh {stashpop 1} ERR [err_stash_index 1]
229
230 # collection 0.foo and 1.foo exist, removing collection target
231 unsetenv_var MODULES_COLLECTION_TARGET
232 testouterr_cmd sh {stashpop 1} ERR [err_stash_index 1]
233
234 setenv_var MODULES_COLLECTION_TARGET bar
235 create_stash_coll $stash_basic2_content
236 setenv_var MODULES_COLLECTION_TARGET foo
237 create_stash_coll $stash_basic_content
238
239 # test collection from correct target is popped
240 setenv_var MODULES_COLLECTION_TARGET bar
241 set ans [list]
242 lappend ans [list set _LMFILES_ $mp/bar/1.0]
243 lappend ans [list set LOADEDMODULES bar/1.0]
244 set tserr [msg_load bar/1.0]
245 testouterr_cmd sh stashpop $ans $tserr
246
247 create_stash_coll $stash_basic2_content
248 after 2
249 create_stash_coll $stash_basic_content
250 set last_stash_current_target_with_ext [file tail [get_last_stash_coll]]
251 set last_stash_current_target [file rootname $last_stash_current_target_with_ext]
252 setenv_var MODULES_COLLECTION_TARGET foo
253 create_stash_coll $stash_basic_content
254 set last_stash_foreign_target_with_ext [file tail [get_last_stash_coll]]
255 set last_stash_foreign_target [file rootname $last_stash_foreign_target_with_ext]
256
257 setenv_var MODULES_COLLECTION_TARGET bar
258 testouterr_cmd sh {stashpop 1} $ans $tserr
259 testouterr_cmd sh {stashpop 1} ERR [err_stash_index 1]
260
261 # specifying valid stash collection name from current target
262 set ans [list]
263 lappend ans [list set _LMFILES_ $mp/foo/1.0:$mp/bar/1.0]
264 lappend ans [list set LOADEDMODULES foo/1.0:bar/1.0]
265 set tserr [msg_load {foo/1.0}]\n[msg_load {bar/1.0}]
266 testouterr_cmd sh "stashpop $last_stash_current_target_with_ext" ERR [err_coll_notfound $last_stash_current_target_with_ext bar]
267 testouterr_cmd sh "stashpop $last_stash_current_target" $ans $tserr
268
269 create_stash_coll $stash_basic2_content
270 after 2
271 create_stash_coll $stash_basic_content
272
273 # specifying valid stash collection name from foreign target
274 testouterr_cmd sh "stashpop $last_stash_foreign_target_with_ext" ERR [err_coll_notfound $last_stash_foreign_target_with_ext bar]
275 testouterr_cmd sh "stashpop $last_stash_foreign_target" ERR [err_coll_notfound $last_stash_foreign_target bar]
276
277 delete_last_stash_coll
278 delete_last_stash_coll
279 delete_last_stash_coll
280 delete_last_stash_coll
281 delete_last_stash_coll
282 delete_last_stash_coll
283 unsetenv_var MODULES_COLLECTION_TARGET
284
285
286 #
287 # errors
288 #
289
290 create_stash_coll $stash_basic_content
291 set last_stash [file tail [get_last_stash_coll]]
292
293 # no HOME set
294 unsetenv_var HOME
295 set tserr "$error_msgs: HOME not defined"
296 testouterr_cmd sh stashpop ERR $tserr
297 setenv_var HOME $ORIG_HOME
298
299 # cannot test access if cannot change file permission
300 if {!$is_file_perms_editable} {
301 send_user "\tskipping access tests as file permissions cannot be changed\n"
302 # cannot test access if superuser privileges are in use
303 } elseif {$tcl_platform(user) eq "root"} {
304 send_user "\tskipping access tests as tests are run by superuser\n"
305 # cannot test access if restricted file permissions have no effect
306 } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
307 send_user "\tskipping access tests as locked files or directories are still readable\n"
308 } else {
309
310 # cannot read collection directory
311 change_file_perms $collhome ugo-rwx
312 set tserr "$error_msgs: Cannot access collection directory.\n"
313 append tserr " couldn't read directory \"$collhome/\": permission denied"
314 testouterr_cmd sh stashpop ERR $tserr
315 restore_file_perms $collhome
316
317 # cannot read collection file
318 change_file_perms $collhome/$last_stash ugo-r
319 testouterr_cmd sh stashpop ERR [err_stash_index 0]
320 testouterr_cmd sh "stashpop $last_stash" ERR [err_permdenied $collhome/$last_stash]
321 restore_file_perms $collhome/$last_stash
322
323 # cannot delete collection file
324 change_file_perms $collhome ugo-w
325 change_file_perms $collhome/$last_stash ugo-w
326 set tserr [msg_load foo/1.0]\n[msg_load bar/1.0]\n
327 append tserr "$error_msgs: Collection $last_stash cannot be removed.\n"
328 append tserr " error deleting \"$collhome/$last_stash\": permission denied"
329 testouterr_cmd sh stashpop ERR $tserr
330 restore_file_perms $collhome/$last_stash
331 restore_file_perms $collhome
332
333 file delete $collhome/$last_stash
334 }
335
336
337 #
338 # Cleanup
339 #
340
341 file delete $collhome/coll
342 catch {
343 foreach fpath [get_all_stash_colls] {
344 send_user "\tDeleting $fpath\n"
345 file delete $fpath
346 }
347 }
348 file delete $collhome
349
350 reset_test_env