Debian Codegraph @

testsuite/modules.70-maint/454-stashclear.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: stashclear
14 # Modulefiles: foo, bar
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Test stashclear 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 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob {}
41
42 create_stash_coll $stash_basic_content
43 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob {}
44
45 create_stash_coll $stash_basic_content
46 create_stash_coll $stash_basic_content
47 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob {}
48
49 skip_if_quick_mode
50
51
52 #
53 # collection target
54 #
55
56 setenv_var MODULES_COLLECTION_TARGET foo
57 create_stash_coll $stash_basic_content
58
59 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob {}
60
61 create_stash_coll $stash_basic_content
62 set last_stash_file [get_last_stash_coll]
63
64 # collection 0.foo remaining, changing collection target
65 setenv_var MODULES_COLLECTION_TARGET bar
66 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob $last_stash_file
67
68 # collection 0.foo remaining, removing collection target
69 unsetenv_var MODULES_COLLECTION_TARGET
70 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob $last_stash_file
71
72 setenv_var MODULES_COLLECTION_TARGET bar
73 create_stash_coll $stash_basic2_content
74 setenv_var MODULES_COLLECTION_TARGET foo
75 create_stash_coll $stash_basic_content
76 set foo_stash_file_list [list $last_stash_file [get_last_stash_coll]]
77
78 # test collection from correct target is popped
79 setenv_var MODULES_COLLECTION_TARGET bar
80 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob $foo_stash_file_list
81
82 delete_last_stash_coll
83 delete_last_stash_coll
84 unsetenv_var MODULES_COLLECTION_TARGET
85
86
87 #
88 # errors
89 #
90
91 create_stash_coll $stash_basic_content
92 set previous_stash_file [get_last_stash_coll]
93 set previous_stash [file tail $previous_stash_file]
94 lappend stash_coll_list $previous_stash_file
95 after 2
96 create_stash_coll $stash_basic_content
97 lappend stash_coll_list [get_last_stash_coll]
98 after 2
99 create_stash_coll $stash_basic_content
100 set last_stash_file [get_last_stash_coll]
101 set last_stash [file tail $last_stash_file]
102 lappend stash_coll_list $last_stash_file
103 set stash_coll_list [lsort $stash_coll_list]
104
105 # no HOME set
106 unsetenv_var HOME
107 set tserr "$error_msgs: HOME not defined"
108 testouterr_cmd sh stashclear ERR $tserr
109 setenv_var HOME $ORIG_HOME
110
111 # cannot test access if cannot change file permission
112 if {!$is_file_perms_editable} {
113 send_user "\tskipping access tests as file permissions cannot be changed\n"
114 # cannot test access if superuser privileges are in use
115 } elseif {$tcl_platform(user) eq "root"} {
116 send_user "\tskipping access tests as tests are run by superuser\n"
117 # cannot test access if restricted file permissions have no effect
118 } elseif {$is_locked_dir_file_readable && $is_locked_file_readable} {
119 send_user "\tskipping access tests as locked files or directories are still readable\n"
120 } else {
121
122 # cannot read collection directory
123 change_file_perms $collhome ugo-rwx
124 set tserr "$error_msgs: Cannot access collection directory.\n"
125 append tserr " couldn't read directory \"$collhome/\": permission denied"
126 testouterr_cmd sh stashclear ERR $tserr
127 restore_file_perms $collhome
128
129 # cannot delete collection file
130 change_file_perms $collhome ugo-w
131 change_file_perms $previous_stash_file ugo-w
132 set tserr "$error_msgs: Collection $last_stash cannot be removed.\n"
133 append tserr " error deleting \"$last_stash_file\": permission denied"
134 testouterrgloblist_cmd sh stashclear ERR $tserr $stashcollglob $stash_coll_list
135 restore_file_perms $previous_stash_file
136 restore_file_perms $collhome
137
138 # cannot read collection file
139 change_file_perms $last_stash_file ugo-r
140 # collection that cannot be read is not returned in valid list, so no attempt
141 # to delete this file
142 testouterrgloblist_cmd sh stashclear OK {} $stashcollglob $last_stash_file
143
144 delete_last_stash_coll
145 }
146
147
148 #
149 # Cleanup
150 #
151
152 file delete $collhome/coll
153 catch {
154 foreach fpath [get_all_stash_colls] {
155 send_user "\tDeleting $fpath\n"
156 file delete $fpath
157 }
158 }
159 file delete $collhome
160
161 reset_test_env