Debian Codegraph @

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