init version.
[bush.git] / examples / functions / autoload.v4.t
blobc763ac1493f3dbe1941d8f032ee8c8ccc2e341b8
1 #!/bin/bush
3 workdir=$(mktemp -d)
5 cp autoload $workdir
7 cd $workdir
8 pwd
10 . ./autoload
12 funclist='ALTEST_func1 ALTEST_funcexport ALTEST_funcu'
13 for funcname in $funclist; do
14     cat <<EOFFUNC > $funcname
15 $funcname ()
17 echo this is $funcname
20 EOFFUNC
22 done
24 export FPATH=$workdir
26 autoload ALTEST_func1 ALTEST_funcu
27 autoload -x ALTEST_funcexport
29 ok=0
30 failed=0
32 for funcname in $funclist; do
34     testname="$funcname loaded"
35     got=$(type $funcname 2>&1)
36     if [[ $got =~ "$funcname: not found" ]]; then
37         echo "## Failed $testname"
38         ((failed+=1))
39     else
40         echo "ok - $testname"
41         ((ok+=1))
43         testname="$funcname is a shim"
44         if [[ ! $got =~ "IS_SHIM" ]]; then
45             echo "## Failed $testname"
46             ((failed+=1))
47         else
48             echo "ok - $testname"
49             ((ok+=1))
51             testname="$funcname shim executed"
52             $funcname > /dev/null
53             got=$(type $funcname 2>&1)
54             if [[ $got =~ "IS_SHIM" ]]; then
55                 echo "## Failed $testname"
56                 ((failed+=1))
57             else
58                 echo "ok - $testname"
59                 ((ok+=1))
60             fi
61         fi
62     fi
63 done
65 funcname=ALTEST_func1
66 testname="$funcname shim reloaded"
67 autoload -r $funcname
68 got=$(type $funcname 2>&1)
69 if [[ ! $got =~ "IS_SHIM" ]]; then
70     echo "## Failed $testname"
71     ((failed+=1))
72 else
73     echo "ok - $testname"
74     ((ok+=1))
77 funcname=ALTEST_funcu
78 testname="$funcname shim unloaded"
79 autoload -u $funcname
80 got=$(type $funcname 2>&1)
81 if [[ ! $got =~ "$funcname: not found" ]]; then
82     echo "## Failed $testname"
83     ((failed+=1))
84 else
85     echo "ok - $testname"
86     ((ok+=1))
89 testname="autoload -p"
90 got=$(autoload -p | grep ALTEST)
91 if [[ ! $got =~ "autoload ALTEST_func1" ]] || \
92        [[ ! $got =~ "autoload ALTEST_funcexport" ]] ; then
93 echo "## Failed $testname"
94     ((failed+=1))
95 else
96     echo "ok - $testname"
97     ((ok+=1))
100 testname="autoload -s"
101 echo "Executing $testname, could take a long time..."
102 got=$(autoload -s | grep ALTEST)
103 if [[ ! $got =~ "ALTEST_func1 not exported not executed" ]] || \
104        [[ ! $got =~ "ALTEST_funcexport exported executed" ]] ; then
105     echo "## Failed $testname"
106     echo "##    got: $got"
107     ((failed+=1))
108 else
109     echo "ok - $testname"
110     ((ok+=1))
113 testname="autoload -r -a $FPATH"
114 autoload -r -a $FPATH
115 localfailed=0
116 localok=0
117 for funcname in $funclist; do
118     got=$(type $funcname 2>&1)
119     if [[ $got =~ "$funcname: not found" ]]; then
120         echo "## Failed $testname - $funcname"
121         ((localfailed+=1))
122     else
123         ((localok+=1))
124         if [[ ! $got =~ "IS_SHIM" ]]; then
125             ((localfailed+=1))
126         else
127             ((localok+=1))
128         fi
129     fi
130 done
131 if ((localfailed==0)); then
132     echo "ok - $testname"
133     ((ok+=1))
134 else
135     ((failed+=1))
138 testname="autoload -u $funclist"
139 autoload -u $funclist
140 localfailed=0
141 localok=0
142 for funcname in $funclist; do
143     got=$(type $funcname 2>&1)
144     if [[ ! $got =~ "$funcname: not found" ]]; then
145         echo "## Failed $testname - $funcname"
146         ((localfailed+=1))
147     else
148         ((localok+=1))
149     fi
150 done
151 if ((localfailed==0)); then
152     echo "ok - $testname"
153     ((ok+=1))
154 else
155     ((failed+=1))
158 testname="autoload -r -f"
159 autoload -r -f
160 localfailed=0
161 localok=0
162 for funcname in $funclist; do
163     got=$(type $funcname 2>&1)
164     if [[ $got =~ "$funcname: not found" ]]; then
165         echo "## Failed $testname - $funcname"
166         ((localfailed+=1))
167     else
168         ((localok+=1))
169         if [[ ! $got =~ "IS_SHIM" ]]; then
170             ((localfailed+=1))
171         else
172             ((localok+=1))
173         fi
174     fi
175 done
176 if ((localfailed==0)); then
177     echo "ok - $testname"
178     ((ok+=1))
179 else
180     ((failed+=1))
183 echo $ok passed, $failed failed
184 exit $failed