1 # Test basic module loading
4 # Figure out which modules it ought to be possible to load by looking at
5 # the config.modules file. This differs for static vs. dynamic builds.
9 while read name modfile link auto load funcs
11 [[ $name == \#* ]] && continue
12 eval "$name $modfile $link $auto $load"
13 [[ $link == no ]] && continue
16 modfile=$ZTST_srcdir/../$modfile
17 eval ${${${(f)"$(<$modfile)"}[(r)moddeps=*]}:-:}
18 [[ -n $moddeps ]] && zmodload -d $name $=moddeps
19 done < $ZTST_testdir/../config.modules
23 (( n == 0 )) && return 0
26 if [[ -z ${(M)${(f)"$(zmodload -d)"}:#*:* $m( *|)} ]]
28 zmodload -u $m && zmodload -ud $m || return 1
47 # This first test depends on knowing that zsh is run with +Z from the
48 # Makefile, and that ztst.zsh loads the parameter module.
51 0:List the loaded modules
53 >zmodload zsh/parameter
55 # You use to need zmodload -i to avoid an error.
56 # That has been deemed pointless, so now an attempt
57 # to load a loaded module should succeed.
59 0:Test reloading an already-loaded module
61 # Loop over the modules found above and attempt to load each one. Use
62 # the -i flag in case dependencies cause multiple modules to be loaded,
63 # or in case some previous test suite loaded a module.
67 zmodload -i $m || mods[(r)$m]=()
69 0d:Test loading of all compiled modules
72 0d:Check that zsh believes the modules did load
74 # Now check for proper failure conditions by trying some operations on
75 # a nonexistent module.
77 zmodload -i bogus/notamodule
78 1D:Check that loading a nonexistent module fails
80 zmodload -u bogus/notamodule
81 1D:Check that unloading a nonexistent module fails
83 # Test adding and removing autoloads, using a nonexistent module.
87 0:Add/remove autoloaded builtin
90 1:Fail to remove unautoloaded builtin
91 ?(eval):zmodload:1: bogus: no such builtin
95 0:Add/remove autoloaded condition
98 1:Fail to remove unautoloaded condition
99 ?(eval):zmodload:1: bogus: no such condition
103 0:Add/remove autoloaded parameter
106 1:Fail to remove unautoloaded parameter
107 ?(eval):zmodload:1: bogus: no such parameter
111 0:Add/remove autoloaded math function
114 1:Fail to remove unautoloaded math function
115 ?(eval):zmodload:1: bogus: no such math function
117 # If the "example" module is available, test various autoloading behavior.
119 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
120 zmodload -u zsh/example
121 zmodload -ab zsh/example example
123 zmodload -e zsh/example
124 else print -u$ZTST_fd Warning: zsh/example not linked: not checking autoloading
126 0d:Autoload a module via a builtin
128 zmodload -u zsh/example
130 0d:Autoloads are persistent
132 (zmodload -u zsh/parameter
133 zmodload -aF zsh/parameter b:fail
135 print "Shouldn't get here.")
136 1:Failed builtin autoload
137 ?(eval):3: module `zsh/parameter' has no such feature: `b:fail': autoload cancelled
138 ?(eval):3: unknown builtin: fail
140 (zmodload -u zsh/parameter
141 zmodload -aF zsh/parameter p:fail
143 print "Shouldn't get here.")
144 1:Failed parameter autoload
145 ?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled
146 ?(eval):3: unknown parameter: fail
148 (zmodload -u zsh/parameter
149 zmodload -aF zsh/parameter c:fail
151 print "Shouldn't get here.")
152 2:Failed condition autoload
153 ?(eval):3: module `zsh/parameter' has no such feature: `c:fail': autoload cancelled
154 ?(eval):3: unknown condition: -foo
156 (zmodload -u zsh/parameter
157 zmodload -aF zsh/parameter f:fail
159 2:Failed math function autoload
160 ?(eval):3: module `zsh/parameter' has no such feature: `f:fail': autoload cancelled
161 ?(eval):3: unknown function: fail
163 zmodload -aF zsh/parameter f:fail2
164 1:Immediate autoload failure on non-existent feature when module loaded
165 ?(eval):zmodload:1: module `zsh/parameter' has no such feature: `f:fail2'
167 (zmodload -u zsh/parameter
168 zmodload -aF zsh/parameter p:fail
169 print $(( ${#modules} > 1 )) )
170 0:Autoloads checked on loading but don't necessarily effect current command
172 ?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled
174 zmodload -laF zsh/parameter
175 0:List default autoloads
205 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
206 zmodload -u zsh/example
207 zmodload -ac -I zsh/example ex
209 zmodload -e zsh/example
212 0d:Autoload a module via a condition
214 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
215 zmodload -u zsh/example
216 zmodload -ap zsh/example exint
218 zmodload -e zsh/example
221 0d:Autoload a module via a parameter
223 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
224 zmodload -u zsh/example
225 zmodload -af zsh/example sum
227 zmodload -e zsh/example
230 0d:Autoload a module via a math function
232 # Test module aliases
234 zmodload -A example=zsh/example
236 0:Test creating a module alias
237 >example -> zsh/example
239 if [[ $mods[(r)zsh/example] == zsh/example ]]; then
246 0d:Unload/autoload the module via its alias
250 1:Delete the module alias again
252 zmodload >zmodload_list
253 print -l ${(o)mods} >mods_list
254 diff zmodload_list mods_list
255 0:Listing with zmodload should give all our modules.
257 # Don't unload the main module.
258 # Do unload zsh/parameter, but reload it as it is needed.
262 zmodload zsh/parameter
263 0d:Unload the modules loaded by this test suite
265 zmodload -aF zsh/zftp b:zftp
266 zmodload -LaF | grep zftp
267 0:Listing feature autoloads includes unloaded modules
268 >zmodload -Fa zsh/zftp b:zftp
273 unset deps name modfile link auto load funcs mods moddeps
274 unfunction zmodunload