############################################################################## # Modules Revision 3.0 # Providing a flexible user environment # # File: modules.70-maint/%M% # Revision: %I% # First Edition: 2022/10/02 # Last Mod.: %U%, %G% # # Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr # # Description: Testuite testsequence # Command: stashlist # Modulefiles: foo, bar # Sub-Command: # # Comment: %C{ # Test stashlist sub-command # }C% # ############################################################################## set mp $modpath.3 setenv_path_var MODULEPATH $mp set collhome $env(HOME)/.module set stashcollglob $collhome/stash-* set lprops "\\s+\[0-9\/]{10} \[0-9:]{8}" set stash_basic_content "module use --append $mp module load foo/1.0 module load bar/1.0\n" set stash_basic2_content "module use --append $mp module load bar/1.0\n" # # basic tests # testouterr_cmd sh stashlist OK [msg_no_stash_coll] create_stash_coll $stash_basic_content set last_stash [file tail [get_last_stash_coll]] set tserr "[msg_stash_coll]\n 0) $last_stash " testouterr_cmd sh stashlist OK $tserr create_stash_coll $stash_basic_content set last_last_stash [file tail [get_last_stash_coll]] set tserr "[msg_stash_coll]\n 0) $last_last_stash 1) $last_stash " testouterr_cmd sh stashlist OK $tserr delete_last_stash_coll delete_last_stash_coll skip_if_quick_mode # no .module dir file delete $collhome testouterr_cmd sh stashlist OK [msg_no_stash_coll] # create regular collection file (not a stash one) file mkdir $collhome set fid [open $collhome/coll w] puts "module use --append $mp module load foo/1.0" close $fid # no stash collection testouterr_cmd sh stashlist OK [msg_no_stash_coll] # create regular collection file (not a stash one) but with similar name set fid [open $collhome/stash w] puts "module use --append $mp module load foo/1.0" close $fid set fid [open $collhome/stash123456789 w] puts "module use --append $mp module load foo/1.0" close $fid testouterr_cmd sh stashlist OK [msg_no_stash_coll] file delete $collhome/stash file delete $collhome/stash123456789 # # --terse/--long/--json switches # # no collection exists testouterr_cmd sh {stashlist -t} OK [msg_no_stash_coll] testouterr_cmd sh {stashlist -l} OK [msg_no_stash_coll] testouterr_cmd sh {stashlist -j} OK "{}" # several collection exists create_stash_coll $stash_basic_content set last_stash_file [get_last_stash_coll] set last_stash [file tail $last_stash_file] after 2 create_stash_coll $stash_basic2_content set last_last_stash_file [get_last_stash_coll] set last_last_stash [file tail $last_last_stash_file] set tserr "[msg_stash_coll]\n$last_last_stash\n$last_stash" testouterr_cmd sh {stashlist --terse} OK $tserr set tserr "$savelist_long_headerre\n[msg_stash_coll]\n$last_last_stash$lprops\n$last_stash$lprops" testouterr_cmd_re sh {stashlist --long} OK $tserr set tserr "{\"$last_last_stash\": { \"name\": \"$last_last_stash\", \"target\": \"\", \"pathname\": \"$last_last_stash_file\"}, \"$last_stash\": { \"name\": \"$last_stash\", \"target\": \"\", \"pathname\": \"$last_stash_file\"}}" testouterr_cmd sh {stashlist --json} OK $tserr delete_last_stash_coll delete_last_stash_coll # # collection target # setenv_var MODULES_COLLECTION_TARGET foo create_stash_coll $stash_basic_content set last_stash_file [get_last_stash_coll] set last_stash [file rootname [file tail $last_stash_file]] set tserr "[msg_stash_coll foo]\n 0) $last_stash " testouterr_cmd sh stashlist OK $tserr create_stash_coll $stash_basic_content set last_last_stash_file [get_last_stash_coll] set last_last_stash [file rootname [file tail $last_last_stash_file]] set tserr "[msg_stash_coll foo]\n$last_last_stash\n$last_stash" testouterr_cmd sh {stashlist -t} OK $tserr set tserr "$savelist_long_headerre\n[escre [msg_stash_coll foo]]\n$last_last_stash$lprops\n$last_stash$lprops" testouterr_cmd_re sh {stashlist -l} OK $tserr set tserr "{\"$last_last_stash\": { \"name\": \"$last_last_stash\", \"target\": \"foo\", \"pathname\": \"$last_last_stash_file\"}, \"$last_stash\": { \"name\": \"$last_stash\", \"target\": \"foo\", \"pathname\": \"$last_stash_file\"}}" testouterr_cmd sh {stashlist -j} OK $tserr # collections *.foo remaining, changing collection target setenv_var MODULES_COLLECTION_TARGET bar testouterr_cmd sh stashlist OK [msg_no_stash_coll bar] testouterr_cmd sh {stashlist -t} OK [msg_no_stash_coll bar] testouterr_cmd sh {stashlist -l} OK [msg_no_stash_coll bar] testouterr_cmd sh {stashlist -j} OK "{}" # collections *.foo remaining, removing collection target unsetenv_var MODULES_COLLECTION_TARGET testouterr_cmd sh stashlist OK [msg_no_stash_coll] testouterr_cmd sh {stashlist -t} OK [msg_no_stash_coll] testouterr_cmd sh {stashlist -l} OK [msg_no_stash_coll] testouterr_cmd sh {stashlist -j} OK "{}" # test collection from correct target is there setenv_var MODULES_COLLECTION_TARGET bar create_stash_coll $stash_basic2_content set last_stash_file [get_last_stash_coll] set last_stash [file rootname [file tail $last_stash_file]] set tserr "[msg_stash_coll bar]\n 0) $last_stash " testouterr_cmd sh stashlist OK $tserr delete_last_stash_coll delete_last_stash_coll delete_last_stash_coll unsetenv_var MODULES_COLLECTION_TARGET # # errors # create_stash_coll $stash_basic_content set last_stash [file tail [get_last_stash_coll]] # no HOME set unsetenv_var HOME set tserr "$error_msgs: HOME not defined" testouterr_cmd sh stashlist ERR $tserr setenv_var HOME $ORIG_HOME # cannot test access if cannot change file permission if {!$is_file_perms_editable} { send_user "\tskipping access tests as file permissions cannot be changed\n" # cannot test access if superuser privileges are in use } elseif {$tcl_platform(user) eq "root"} { send_user "\tskipping access tests as tests are run by superuser\n" # cannot test access if restricted file permissions have no effect } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} { send_user "\tskipping access tests as locked files or directories are still readable\n" } else { # cannot read collection directory change_file_perms $collhome ugo-rwx set tserr "$error_msgs: Cannot access collection directory.\n" append tserr " couldn't read directory \"$collhome/\": permission denied" testouterr_cmd sh stashlist ERR $tserr restore_file_perms $collhome # cannot read collection file change_file_perms $collhome/$last_stash ugo-r testouterr_cmd sh stashlist OK [msg_no_stash_coll] restore_file_perms $collhome/$last_stash file delete $collhome/$last_stash } # # Cleanup # file delete $collhome/coll catch { foreach fpath [get_all_stash_colls] { send_user "\tDeleting $fpath\n" file delete $fpath } } file delete $collhome reset_test_env