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