about summary refs log tree commit diff
path: root/Test/V01zmodload.ztst
blob: 1bd8c1900eaccd18d2c19eb61207e1dbf78b5661 (plain) (blame)
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# Test basic module loading

%prep
# Figure out which modules it ought to be possible to load by looking at
# the config.modules file.  This differs for static vs. dynamic builds.

 mods=()
 deps="$(zmodload -Ld)"
 while read name modfile link auto load funcs
 do
   [[ $name == \#* ]] && continue
   eval "$name $modfile $link $auto $load"
   [[ $link == no ]] && continue
   mods=($mods $name)
   moddeps=
   modfile=$ZTST_srcdir/../$modfile
   eval ${${${(f)"$(<$modfile)"}[(r)moddeps=*]}:-:}
   [[ -n $moddeps ]] && zmodload -d $name $=moddeps
 done < $ZTST_testdir/../config.modules

 zmodunload() {
   local m n=$#
   (( n == 0 )) && return 0
   for m
   do
     if [[ -z ${(M)${(f)"$(zmodload -d)"}:#*:* $m( *|)} ]]
     then
       zmodload -u $m && zmodload -ud $m || return 1
       shift
     else
       set $@[2,-1] $m
     fi
   done
   if (( $# < n ))
   then
     zmodunload $*
   else
     zmodload -u $*
   fi
 }

 mkdir zmodload.tmp
 cd zmodload.tmp

%test

# This first test depends on knowing that zsh is run with +Z from the
# Makefile, and that ztst.zsh loads the parameter module.

 zmodload -L
0:List the loaded modules
>zmodload zsh/main
>zmodload zsh/parameter

# You used to need zmodload -i to avoid an error.
# That has been deemed pointless, so now an attempt
# to load a loaded module should succeed.
 zmodload zsh/main
0:Test reloading an already-loaded module

# Loop over the modules found above and attempt to load each one.  Use
# the -i flag in case dependencies cause multiple modules to be loaded,
# or in case some previous test suite loaded a module.

 for m in $mods
 do
   zmodload $m || mods[(r)$m]=()
 done
0d:Test loading of all compiled modules

 zmodload -e $mods
0d:Check that zsh believes the modules did load

# Now check for proper failure conditions by trying some operations on
# a nonexistent module.

 zmodload bogus/notamodule
1D:Check that loading a nonexistent module fails

 zmodload -u bogus/notamodule
1D:Check that unloading a nonexistent module fails

# Test adding and removing autoloads, using a nonexistent module.

 zmodload -ab bogus
 zmodload -ub bogus
0:Add/remove autoloaded builtin

 zmodload -ub bogus
1:Fail to remove unautoloaded builtin
?(eval):zmodload:1: bogus: no such builtin

 zmodload -ac bogus
 zmodload -uc bogus
0:Add/remove autoloaded condition

 zmodload -uc bogus
1:Fail to remove unautoloaded condition
?(eval):zmodload:1: bogus: no such condition

 zmodload -ap bogus
 zmodload -up bogus
0:Add/remove autoloaded parameter

 zmodload -up bogus
1:Fail to remove unautoloaded parameter
?(eval):zmodload:1: bogus: no such parameter

 zmodload -af bogus
 zmodload -uf bogus
0:Add/remove autoloaded math function

 zmodload -uf bogus
1:Fail to remove unautoloaded math function
?(eval):zmodload:1: bogus: no such math function

# If the "example" module is available, test various autoloading behavior.

 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
   zmodload -u zsh/example
   zmodload -ab zsh/example example
   builtin example
   zmodload -e zsh/example
 else print -u$ZTST_fd Warning: zsh/example not linked: not checking autoloading
 fi
0d:Autoload a module via a builtin

 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
  zmodload -u zsh/example
  builtin example
 fi
0d:Autoloads are persistent

  (zmodload -u zsh/parameter
  zmodload -aF zsh/parameter b:fail
  fail
  print "Shouldn't get here.")
1:Failed builtin autoload
?(eval):3: module `zsh/parameter' has no such feature: `b:fail': autoload cancelled
?(eval):3: autoloading module zsh/parameter failed to define builtin: fail

  (zmodload -u zsh/parameter
  zmodload -aF zsh/parameter p:fail
  print $fail
  print "Shouldn't get here.")
1:Failed parameter autoload
?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled
?(eval):3: autoloading module zsh/parameter failed to define parameter: fail

  (zmodload -u zsh/parameter
  zmodload -aF zsh/parameter c:fail
  [[ -fail foo ]]
  print "Shouldn't get here.")
2:Failed condition autoload
?(eval):3: module `zsh/parameter' has no such feature: `c:fail': autoload cancelled
?(eval):3: unknown condition: -fail

  (zmodload -u zsh/parameter
  zmodload -aF zsh/parameter f:fail
  (( fail() )) )
2:Failed math function autoload
?(eval):3: module `zsh/parameter' has no such feature: `f:fail': autoload cancelled
?(eval):3: autoloading module zsh/parameter failed to define math function: fail

  zmodload -aF zsh/parameter f:fail2
1:Immediate autoload failure on non-existent feature when module loaded
?(eval):zmodload:1: module `zsh/parameter' has no such feature: `f:fail2'

  (zmodload -u zsh/parameter
  zmodload -aF zsh/parameter p:fail
  print $(( ${#modules} > 1 )) )
0:Autoloads checked on loading but don't necessarily effect current command
>1
?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled

  zmodload -laF zsh/parameter
0:List default autoloads
>p:aliases
>p:builtins
>p:commands
>p:dirstack
>p:dis_aliases
>p:dis_builtins
>p:dis_functions
>p:dis_functions_source
>p:dis_galiases
>p:dis_patchars
>p:dis_reswords
>p:dis_saliases
>p:funcfiletrace
>p:funcsourcetrace
>p:funcstack
>p:functions
>p:functions_source
>p:functrace
>p:galiases
>p:history
>p:historywords
>p:jobdirs
>p:jobstates
>p:jobtexts
>p:modules
>p:nameddirs
>p:options
>p:parameters
>p:patchars
>p:reswords
>p:saliases
>p:userdirs
>p:usergroups

 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
   zmodload -u zsh/example
   zmodload -ac -I zsh/example ex
   [[ exam -ex ple ]]
   zmodload -e zsh/example
 else :
 fi
0d:Autoload a module via a condition

 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
   zmodload -u zsh/example
   zmodload -ap zsh/example exint
   : $exint
   zmodload -e zsh/example
 else :
 fi
0d:Autoload a module via a parameter

 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
   zmodload -u zsh/example
   zmodload -af zsh/example sum
   (( sum(1) ))
   zmodload -e zsh/example
 else :
 fi
0d:Autoload a module via a math function

# Test module aliases

 zmodload -A example=zsh/example
 zmodload -A
0:Test creating a module alias
>example -> zsh/example

 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
   zmodload -u example
   zmodload -ab example
   builtin example
   zmodload -e example
 else :
 fi
0d:Unload/autoload the module via its alias

 zmodload -R example
 zmodload -e example
1:Delete the module alias again

  zmodload >zmodload_list
  print -l ${(o)mods} >mods_list
  diff zmodload_list mods_list
0:Listing with zmodload should give all our modules.

# Don't unload the main module.
# Do unload zsh/parameter, but reload it as it is needed.

 mods[(r)zsh/main]=()
 zmodunload $mods
 zmodload zsh/parameter
0d:Unload the modules loaded by this test suite

  zmodload -aF zsh/zftp b:zftp
  zmodload -LaF | grep zftp
0:Listing feature autoloads includes unloaded modules
>zmodload -Fa zsh/zftp b:zftp

  if ! zmodload zsh/system >/dev/null 2>&1; then
    ZTST_skip="zsh/system module not available"
  else
    zmodload -lF zsh/system
    zmodload -F zsh/system -p:errnos
    print ${+errnos}
    zmodload -lF zsh/system
    zmodload -F zsh/system +p:errnos
    print ${+errnos}
    zmodload -lF zsh/system
  fi
0:Regression tests for index bug with math functions.
>+b:syserror
>+b:sysread
>+b:syswrite
>+b:sysopen
>+b:sysseek
>+b:zsystem
>+f:systell
>+p:errnos
>+p:sysparams
>0
>+b:syserror
>+b:sysread
>+b:syswrite
>+b:sysopen
>+b:sysseek
>+b:zsystem
>+f:systell
>-p:errnos
>+p:sysparams
>1
>+b:syserror
>+b:sysread
>+b:syswrite
>+b:sysopen
>+b:sysseek
>+b:zsystem
>+f:systell
>+p:errnos
>+p:sysparams

  if ! zmodload zsh/system >/dev/null 2>&1; then
    ZTST_skip="zsh/system module not available"
  else
    zmodload -F zsh/system -f:systell
    zmodload -lF zsh/system
    (print $(( systell(-1) )))
    zmodload -F zsh/system +f:systell
    zmodload -lF zsh/system
    (print $(( systell(-1) )))
  fi
1:Module Features for math functions
>+b:syserror
>+b:sysread
>+b:syswrite
>+b:sysopen
>+b:sysseek
>+b:zsystem
>-f:systell
>+p:errnos
>+p:sysparams
>+b:syserror
>+b:sysread
>+b:syswrite
>+b:sysopen
>+b:sysseek
>+b:zsystem
>+f:systell
>+p:errnos
>+p:sysparams
?(eval):6: unknown function: systell
?(eval):9: file descriptor out of range

%clean

 eval "$deps"
 unset deps name modfile link auto load funcs mods moddeps
 unfunction zmodunload