1# Test basic module loading 2 3%prep 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. 6 7 mods=() 8 deps="$(zmodload -Ld)" 9 while read name modfile link auto load funcs 10 do 11 [[ $name == \#* ]] && continue 12 eval "$name $modfile $link $auto $load" 13 [[ $link == no ]] && continue 14 mods=($mods $name) 15 moddeps= 16 modfile=$ZTST_srcdir/../$modfile 17 eval ${${${(f)"$(<$modfile)"}[(r)moddeps=*]}:-:} 18 [[ -n $moddeps ]] && zmodload -d $name $=moddeps 19 done < $ZTST_testdir/../config.modules 20 21 zmodunload() { 22 local m n=$# 23 (( n == 0 )) && return 0 24 for m 25 do 26 if [[ -z ${(M)${(f)"$(zmodload -d)"}:#*:* $m( *|)} ]] 27 then 28 zmodload -u $m && zmodload -ud $m || return 1 29 shift 30 else 31 set $@[2,-1] $m 32 fi 33 done 34 if (( $# < n )) 35 then 36 zmodunload $* 37 else 38 zmodload -u $* 39 fi 40 } 41 42 mkdir zmodload.tmp 43 cd zmodload.tmp 44 45%test 46 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. 49 50 zmodload -L 510:List the loaded modules 52>zmodload zsh/main 53>zmodload zsh/parameter 54 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. 58 zmodload zsh/main 590:Test reloading an already-loaded module 60 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. 64 65 for m in $mods 66 do 67 zmodload -i $m || mods[(r)$m]=() 68 done 690d:Test loading of all compiled modules 70 71 zmodload -e $mods 720d:Check that zsh believes the modules did load 73 74# Now check for proper failure conditions by trying some operations on 75# a nonexistent module. 76 77 zmodload -i bogus/notamodule 781D:Check that loading a nonexistent module fails 79 80 zmodload -u bogus/notamodule 811D:Check that unloading a nonexistent module fails 82 83# Test adding and removing autoloads, using a nonexistent module. 84 85 zmodload -ab bogus 86 zmodload -ub bogus 870:Add/remove autoloaded builtin 88 89 zmodload -ub bogus 901:Fail to remove unautoloaded builtin 91?(eval):zmodload:1: bogus: no such builtin 92 93 zmodload -ac bogus 94 zmodload -uc bogus 950:Add/remove autoloaded condition 96 97 zmodload -uc bogus 981:Fail to remove unautoloaded condition 99?(eval):zmodload:1: bogus: no such condition 100 101 zmodload -ap bogus 102 zmodload -up bogus 1030:Add/remove autoloaded parameter 104 105 zmodload -up bogus 1061:Fail to remove unautoloaded parameter 107?(eval):zmodload:1: bogus: no such parameter 108 109 zmodload -af bogus 110 zmodload -uf bogus 1110:Add/remove autoloaded math function 112 113 zmodload -uf bogus 1141:Fail to remove unautoloaded math function 115?(eval):zmodload:1: bogus: no such math function 116 117# If the "example" module is available, test various autoloading behavior. 118 119 if [[ $mods[(r)zsh/example] == zsh/example ]]; then 120 zmodload -u zsh/example 121 zmodload -ab zsh/example example 122 builtin example 123 zmodload -e zsh/example 124 else print -u$ZTST_fd Warning: zsh/example not linked: not checking autoloading 125 fi 1260d:Autoload a module via a builtin 127 128 if [[ $mods[(r)zsh/example] == zsh/example ]]; then 129 zmodload -u zsh/example 130 builtin example 131 fi 1320d:Autoloads are persistent 133 134 (zmodload -u zsh/parameter 135 zmodload -aF zsh/parameter b:fail 136 fail 137 print "Shouldn't get here.") 1381:Failed builtin autoload 139?(eval):3: module `zsh/parameter' has no such feature: `b:fail': autoload cancelled 140?(eval):3: autoloading module zsh/parameter failed to define builtin: fail 141 142 (zmodload -u zsh/parameter 143 zmodload -aF zsh/parameter p:fail 144 print $fail 145 print "Shouldn't get here.") 1461:Failed parameter autoload 147?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled 148?(eval):3: autoloading module zsh/parameter failed to define parameter: fail 149 150 (zmodload -u zsh/parameter 151 zmodload -aF zsh/parameter c:fail 152 [[ -fail foo ]] 153 print "Shouldn't get here.") 1542:Failed condition autoload 155?(eval):3: module `zsh/parameter' has no such feature: `c:fail': autoload cancelled 156?(eval):3: unknown condition: -fail 157 158 (zmodload -u zsh/parameter 159 zmodload -aF zsh/parameter f:fail 160 (( fail() )) ) 1612:Failed math function autoload 162?(eval):3: module `zsh/parameter' has no such feature: `f:fail': autoload cancelled 163?(eval):3: autoloading module zsh/parameter failed to define math function: fail 164 165 zmodload -aF zsh/parameter f:fail2 1661:Immediate autoload failure on non-existent feature when module loaded 167?(eval):zmodload:1: module `zsh/parameter' has no such feature: `f:fail2' 168 169 (zmodload -u zsh/parameter 170 zmodload -aF zsh/parameter p:fail 171 print $(( ${#modules} > 1 )) ) 1720:Autoloads checked on loading but don't necessarily effect current command 173>1 174?(eval):3: module `zsh/parameter' has no such feature: `p:fail': autoload cancelled 175 176 zmodload -laF zsh/parameter 1770:List default autoloads 178>p:aliases 179>p:builtins 180>p:commands 181>p:dirstack 182>p:dis_aliases 183>p:dis_builtins 184>p:dis_functions 185>p:dis_galiases 186>p:dis_patchars 187>p:dis_reswords 188>p:dis_saliases 189>p:funcfiletrace 190>p:funcsourcetrace 191>p:funcstack 192>p:functions 193>p:functrace 194>p:galiases 195>p:history 196>p:historywords 197>p:jobdirs 198>p:jobstates 199>p:jobtexts 200>p:modules 201>p:nameddirs 202>p:options 203>p:parameters 204>p:patchars 205>p:reswords 206>p:saliases 207>p:userdirs 208 209 if [[ $mods[(r)zsh/example] == zsh/example ]]; then 210 zmodload -u zsh/example 211 zmodload -ac -I zsh/example ex 212 [[ exam -ex ple ]] 213 zmodload -e zsh/example 214 else : 215 fi 2160d:Autoload a module via a condition 217 218 if [[ $mods[(r)zsh/example] == zsh/example ]]; then 219 zmodload -u zsh/example 220 zmodload -ap zsh/example exint 221 : $exint 222 zmodload -e zsh/example 223 else : 224 fi 2250d:Autoload a module via a parameter 226 227 if [[ $mods[(r)zsh/example] == zsh/example ]]; then 228 zmodload -u zsh/example 229 zmodload -af zsh/example sum 230 (( sum(1) )) 231 zmodload -e zsh/example 232 else : 233 fi 2340d:Autoload a module via a math function 235 236# Test module aliases 237 238 zmodload -A example=zsh/example 239 zmodload -A 2400:Test creating a module alias 241>example -> zsh/example 242 243 if [[ $mods[(r)zsh/example] == zsh/example ]]; then 244 zmodload -u example 245 zmodload -ab example 246 builtin example 247 zmodload -e example 248 else : 249 fi 2500d:Unload/autoload the module via its alias 251 252 zmodload -R example 253 zmodload -e example 2541:Delete the module alias again 255 256 zmodload >zmodload_list 257 print -l ${(o)mods} >mods_list 258 diff zmodload_list mods_list 2590:Listing with zmodload should give all our modules. 260 261# Don't unload the main module. 262# Do unload zsh/parameter, but reload it as it is needed. 263 264 mods[(r)zsh/main]=() 265 zmodunload $mods 266 zmodload zsh/parameter 2670d:Unload the modules loaded by this test suite 268 269 zmodload -aF zsh/zftp b:zftp 270 zmodload -LaF | grep zftp 2710:Listing feature autoloads includes unloaded modules 272>zmodload -Fa zsh/zftp b:zftp 273 274%clean 275 276 eval "$deps" 277 unset deps name modfile link auto load funcs mods moddeps 278 unfunction zmodunload 279