File: 050-prepend.exp

package info (click to toggle)
modules 5.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 20,572 kB
  • sloc: exp: 46,525; sh: 5,261; tcl: 3,182; makefile: 1,355; ansic: 466; python: 251; csh: 201; perl: 47; ruby: 44
file content (247 lines) | stat: -rw-r--r-- 5,963 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	1995/12/06
#   Last Mod.:		%U%, %G%
#
#   Authors:		Jens Hamisch, Jens.Hamisch@Strawberry.COM
#
#   Description:	Testuite testsequence
#   Command:		load
#   Modulefiles:	prepend/1.0
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'prepend-path' module subcommand for all
#			allowed shell types.
#		}C%
#
##############################################################################

skip_if_quick_mode

#
#  Variables. This test forces a module load command. It will result in the
#    environment variables "_LMFILES_", "LOADEDMODULES" and "PATH" to
#    be set up
#

set module "prepend/2.0"
set modulefile "$modpath/$module"

set old_path $env(PATH)
set ts_path "/this/is/the/modules/testsuite"
set new_path "$ts_path:$old_path"

#
#  For the different shells ...
#

lappend ans [list set PATH $new_path]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]

#
#  The tests
#

test_cmd_re "ALL" "load $module" $ans

#
# Try prepending an empty string
#

set module "prepend/0.1"
set modulefile "$modpath/$module"

set old_path $env(PATH)
set ts_path ""
set new_path "$ts_path:$old_path"

#
#  For the different shells ...
#

set ans [list]
lappend ans [list set __MODULES_SHARE_PATH :1]
lappend ans [list set PATH $new_path]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]

#
#  The tests
#

test_cmd_re "ALL" "load $module" $ans

#
# Try prepending a colon ':'

set module "prepend/0.2"
set modulefile "$modpath/$module"

# different behavior than C-version: on Tcl-version adding a bare colon
# to a path produces an error since this colon cannot be distinguished
# from the colon used for path separator
set ts_err [msg_moderr "prepend-path $msg_patheqsep" "prepend-path\tPATH\t\t:" $modulefile 25]

#
#  The tests
#

testouterr_cmd "ALL" "load $module" "ERR" [msg_load $module $ts_err]


#
# Try loading when colon is set at beginning of set PATH
#

set module "prepend/2.0"
set modulefile "$modpath/$module"

set old_path ":$env(PATH)"
set ts_path "/this/is/the/modules/testsuite"
set new_path "$ts_path:$old_path"

# set PATH with prefixing colon
setenv_path_var PATH {} $env(PATH)

set ans [list]
lappend ans [list set __MODULES_SHARE_PATH :1]
lappend ans [list set PATH $new_path]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]

#
#  The tests
#

test_cmd_re "ALL" "load $module" $ans


#
# Try bad argument list: missing variable name
#

set module "prepend/0.3"
set modulefile "$modpath/$module"
set ts_err [msg_moderr "prepend-path $msg_needenvvarname" {prepend-path } $modulefile 24]
testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $ts_err]

#
# Try bad argument list: missing variable value
#

set module "prepend/0.4"
set modulefile "$modpath/$module"
set ts_err [msg_moderr "prepend-path $msg_needenvvarval PATH" {prepend-path PATH} $modulefile 24]
testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $ts_err]

#
# Try bad argument list: empty variable name
#

set module "prepend/0.5"
set modulefile "$modpath/$module"
set ts_err [msg_moderr "prepend-path $msg_validenvvarname" {prepend-path {}} $modulefile 24]
testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $ts_err]

#
# Try command switches passed after variable name
#

set module "prepend/1.10"
set modulefile "$modpath/$module"
set ans [list]
lappend ans [list set testsuite2 -d:,:http://foobar.com]
lappend ans [list set testsuite3 -Lfoo:bar]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]
lappend ans [list set testsuite --delim=,:http://foobar.com]
testouterr_cmd_re "sh" "load $module" $ans {}


#
# Try prepending empty string and check reference counter
#

set module "prepend/3.0"
set modulefile "$modpath/$module"

set ans [list]
lappend ans [list set __MODULES_SHARE_FOO ":1"]
lappend ans [list set FOO ""]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]

testouterr_cmd "sh" "load $module" $ans ""

# empty var does not always mean empty path entry set, only if a corresponding
# reference counter array entry can be found
set env(FOO) ""
testouterr_cmd "sh" "load $module" $ans ""

unset env(FOO)
set module2 "prepend/3.1"
set modulefile2 "$modpath/$module2"

set ans [list]
lappend ans [list set __MODULES_SHARE_FOO ":2"]
lappend ans [list set FOO "/path/to/dir:"]
lappend ans [list set _LMFILES_ "$modulefile:$modulefile2"]
lappend ans [list set LOADEDMODULES "$module:$module2"]

testouterr_cmd_re "sh" "load $module $module2" $ans ""

set ans [list]
lappend ans [list set __MODULES_SHARE_FOO ":2"]
lappend ans [list set FOO "/path/to/dir:"]
lappend ans [list set _LMFILES_ "$modulefile2:$modulefile"]
lappend ans [list set LOADEDMODULES "$module2:$module"]

testouterr_cmd_re "sh" "load $module2 $module" $ans ""


#
# Prepending multiple paths passed as one string
#

set module "prepend/2.3"
set modulefile "$modpath/$module"
set old_path "/path/to/dir1"

setenv_path_var FOO $old_path

set ans [list]
lappend ans [list set __MODULES_SHARE_FOO ":1"]
lappend ans [list set FOO ":/modules/testsuite2.2:/modules/testsuite2.2/2.2:$old_path"]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]

testouterr_cmd "sh" "load $module" $ans ""


#
# Prepending multiple paths passed as multiple strings
#

set module "prepend/2.4"
set modulefile "$modpath/$module"

set ans [list]
lappend ans [list set __MODULES_SHARE_FOO ":1"]
lappend ans [list set FOO ":/modules/testsuite2.2:/modules/testsuite2.2/2.2:$old_path"]
lappend ans [list set _LMFILES_ $modulefile]
lappend ans [list set LOADEDMODULES $module]

testouterr_cmd "sh" "load $module" $ans ""


#
#  Cleanup
#

reset_test_env