Skip to content

Commit 8eee715

Browse files
committed
ts: add stashlist sub-cmd tests
1 parent 1cdd5d3 commit 8eee715

File tree

2 files changed

+250
-0
lines changed

2 files changed

+250
-0
lines changed

testsuite/modules.00-init/005-init_ts.exp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ set msg_nomodloaded {No module has been loaded}
6969
set datetimere {[0-9/]{10} [0-9:]{8}}
7070
set avail_long_headerre "- Package/Alias $modlin.- Versions $modlin.- Last mod. $modlin"
7171
set list_long_headerre "- Package $modlin.- Versions $modlin.- Last mod. $modlin"
72+
set savelist_long_headerre "- Collection $modlin.- Last mod. $modlin"
7273

7374
# Common error responses
7475
set err_path "$error_msgs: Unable to locate a modulefile for "
@@ -384,6 +385,24 @@ proc msg_no_named_coll {{matching 0} {target {}}} {
384385
return $msg
385386
}
386387

388+
proc msg_stash_coll {{target {}}} {
389+
set msg {Stash collection list}
390+
if {$target ne {}} {
391+
append msg " (for target \"$target\")"
392+
}
393+
append msg :
394+
return $msg
395+
}
396+
397+
proc msg_no_stash_coll {{target {}}} {
398+
set msg {No stash collection}
399+
if {$target ne {}} {
400+
append msg " (for target \"$target\")"
401+
}
402+
append msg .
403+
return $msg
404+
}
405+
387406
proc msg_moderr {msg cmdline modfile linenum {pad {}} {procname {}} {contact {}} {custom {}} {custom2 {while executing}}} {
388407

389408
set linefile [expr {$procname ne {} || $linenum eq {} ? {} : " line $linenum"}]
Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
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/10/02
8+
# Last Mod.: %U%, %G%
9+
#
10+
# Authors: Xavier Delaruelle, [email protected]
11+
#
12+
# Description: Testuite testsequence
13+
# Command: stashlist
14+
# Modulefiles: foo, bar
15+
# Sub-Command:
16+
#
17+
# Comment: %C{
18+
# Test stashlist 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 lprops "\\s+\[0-9\/]{10} \[0-9:]{8}"
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 stashlist OK [msg_no_stash_coll]
42+
43+
create_stash_coll $stash_basic_content
44+
set last_stash [file tail [get_last_stash_coll]]
45+
set tserr "[msg_stash_coll]\n 0) $last_stash "
46+
testouterr_cmd sh stashlist OK $tserr
47+
48+
create_stash_coll $stash_basic_content
49+
set last_last_stash [file tail [get_last_stash_coll]]
50+
set tserr "[msg_stash_coll]\n 0) $last_last_stash 1) $last_stash "
51+
testouterr_cmd sh stashlist OK $tserr
52+
53+
delete_last_stash_coll
54+
delete_last_stash_coll
55+
56+
skip_if_quick_mode
57+
58+
59+
# no .module dir
60+
file delete $collhome
61+
testouterr_cmd sh stashlist OK [msg_no_stash_coll]
62+
63+
# create regular collection file (not a stash one)
64+
file mkdir $collhome
65+
set fid [open $collhome/coll w]
66+
puts "module use --append $mp
67+
module load foo/1.0"
68+
close $fid
69+
70+
# no stash collection
71+
testouterr_cmd sh stashlist OK [msg_no_stash_coll]
72+
73+
# create regular collection file (not a stash one) but with similar name
74+
set fid [open $collhome/stash w]
75+
puts "module use --append $mp
76+
module load foo/1.0"
77+
close $fid
78+
set fid [open $collhome/stash123456789 w]
79+
puts "module use --append $mp
80+
module load foo/1.0"
81+
close $fid
82+
83+
testouterr_cmd sh stashlist OK [msg_no_stash_coll]
84+
85+
file delete $collhome/stash
86+
file delete $collhome/stash123456789
87+
88+
89+
#
90+
# --terse/--long/--json switches
91+
#
92+
93+
# no collection exists
94+
testouterr_cmd sh {stashlist -t} OK [msg_no_stash_coll]
95+
testouterr_cmd sh {stashlist -l} OK [msg_no_stash_coll]
96+
testouterr_cmd sh {stashlist -j} OK "{}"
97+
98+
99+
# several collection exists
100+
101+
create_stash_coll $stash_basic_content
102+
set last_stash_file [get_last_stash_coll]
103+
set last_stash [file tail $last_stash_file]
104+
after 2
105+
create_stash_coll $stash_basic2_content
106+
set last_last_stash_file [get_last_stash_coll]
107+
set last_last_stash [file tail $last_last_stash_file]
108+
109+
set tserr "[msg_stash_coll]\n$last_last_stash\n$last_stash"
110+
testouterr_cmd sh {stashlist --terse} OK $tserr
111+
112+
set tserr "$savelist_long_headerre\n[msg_stash_coll]\n$last_last_stash$lprops\n$last_stash$lprops"
113+
testouterr_cmd_re sh {stashlist --long} OK $tserr
114+
115+
set tserr "{\"$last_last_stash\": { \"name\": \"$last_last_stash\", \"target\": \"\", \"pathname\": \"$last_last_stash_file\"},
116+
\"$last_stash\": { \"name\": \"$last_stash\", \"target\": \"\", \"pathname\": \"$last_stash_file\"}}"
117+
testouterr_cmd sh {stashlist --json} OK $tserr
118+
119+
delete_last_stash_coll
120+
delete_last_stash_coll
121+
122+
123+
#
124+
# collection target
125+
#
126+
127+
setenv_var MODULES_COLLECTION_TARGET foo
128+
create_stash_coll $stash_basic_content
129+
set last_stash_file [get_last_stash_coll]
130+
set last_stash [file rootname [file tail $last_stash_file]]
131+
132+
set tserr "[msg_stash_coll foo]\n 0) $last_stash "
133+
testouterr_cmd sh stashlist OK $tserr
134+
135+
create_stash_coll $stash_basic_content
136+
set last_last_stash_file [get_last_stash_coll]
137+
set last_last_stash [file rootname [file tail $last_last_stash_file]]
138+
139+
set tserr "[msg_stash_coll foo]\n$last_last_stash\n$last_stash"
140+
testouterr_cmd sh {stashlist -t} OK $tserr
141+
142+
set tserr "$savelist_long_headerre\n[escre [msg_stash_coll foo]]\n$last_last_stash$lprops\n$last_stash$lprops"
143+
testouterr_cmd_re sh {stashlist -l} OK $tserr
144+
145+
set tserr "{\"$last_last_stash\": { \"name\": \"$last_last_stash\", \"target\": \"foo\", \"pathname\": \"$last_last_stash_file\"},
146+
\"$last_stash\": { \"name\": \"$last_stash\", \"target\": \"foo\", \"pathname\": \"$last_stash_file\"}}"
147+
testouterr_cmd sh {stashlist -j} OK $tserr
148+
149+
# collections *.foo remaining, changing collection target
150+
setenv_var MODULES_COLLECTION_TARGET bar
151+
testouterr_cmd sh stashlist OK [msg_no_stash_coll bar]
152+
testouterr_cmd sh {stashlist -t} OK [msg_no_stash_coll bar]
153+
testouterr_cmd sh {stashlist -l} OK [msg_no_stash_coll bar]
154+
testouterr_cmd sh {stashlist -j} OK "{}"
155+
156+
# collections *.foo remaining, removing collection target
157+
unsetenv_var MODULES_COLLECTION_TARGET
158+
testouterr_cmd sh stashlist OK [msg_no_stash_coll]
159+
testouterr_cmd sh {stashlist -t} OK [msg_no_stash_coll]
160+
testouterr_cmd sh {stashlist -l} OK [msg_no_stash_coll]
161+
testouterr_cmd sh {stashlist -j} OK "{}"
162+
163+
# test collection from correct target is there
164+
setenv_var MODULES_COLLECTION_TARGET bar
165+
create_stash_coll $stash_basic2_content
166+
set last_stash_file [get_last_stash_coll]
167+
set last_stash [file rootname [file tail $last_stash_file]]
168+
169+
set tserr "[msg_stash_coll bar]\n 0) $last_stash "
170+
testouterr_cmd sh stashlist OK $tserr
171+
172+
delete_last_stash_coll
173+
delete_last_stash_coll
174+
delete_last_stash_coll
175+
unsetenv_var MODULES_COLLECTION_TARGET
176+
177+
178+
#
179+
# errors
180+
#
181+
182+
create_stash_coll $stash_basic_content
183+
set last_stash [file tail [get_last_stash_coll]]
184+
185+
# no HOME set
186+
unsetenv_var HOME
187+
set tserr "$error_msgs: HOME not defined"
188+
testouterr_cmd sh stashlist ERR $tserr
189+
setenv_var HOME $ORIG_HOME
190+
191+
# cannot test access if cannot change file permission
192+
if {!$is_file_perms_editable} {
193+
send_user "\tskipping access tests as file permissions cannot be changed\n"
194+
# cannot test access if superuser privileges are in use
195+
} elseif {$tcl_platform(user) eq "root"} {
196+
send_user "\tskipping access tests as tests are run by superuser\n"
197+
# cannot test access if restricted file permissions have no effect
198+
} elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
199+
send_user "\tskipping access tests as locked files or directories are still readable\n"
200+
} else {
201+
202+
# cannot read collection directory
203+
change_file_perms $collhome ugo-rwx
204+
set tserr "$error_msgs: Cannot access collection directory.\n"
205+
append tserr " couldn't read directory \"$collhome/\": permission denied"
206+
testouterr_cmd sh stashlist ERR $tserr
207+
restore_file_perms $collhome
208+
209+
# cannot read collection file
210+
change_file_perms $collhome/$last_stash ugo-r
211+
testouterr_cmd sh stashlist OK [msg_no_stash_coll]
212+
restore_file_perms $collhome/$last_stash
213+
214+
file delete $collhome/$last_stash
215+
}
216+
217+
218+
#
219+
# Cleanup
220+
#
221+
222+
file delete $collhome/coll
223+
catch {
224+
foreach fpath [get_all_stash_colls] {
225+
send_user "\tDeleting $fpath\n"
226+
file delete $fpath
227+
}
228+
}
229+
file delete $collhome
230+
231+
reset_test_env

0 commit comments

Comments
 (0)