]> git.cameronkatri.com Git - apple_cmds.git/blob - shell_cmds/test/tests/legacy_test.sh
Merge branch 'apple'
[apple_cmds.git] / shell_cmds / test / tests / legacy_test.sh
1 #!/bin/sh
2
3 #-
4 # Copyright (c) June 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 # SUCH DAMAGE.
27
28 #
29 # TEST.sh - check if test(1) or builtin test works
30 #
31 # $FreeBSD$
32
33 enable -n test
34
35 # force a specified test program, e.g. `env test=/bin/test sh regress.sh'
36 : ${test=test}
37
38 t ()
39 {
40 # $1 -> exit code
41 # $2 -> $test expression
42
43 count=$((count+1))
44 printf "[BEGIN] test $count\n"
45 # check for syntax errors
46 syntax="`eval $test $2 2>&1`"
47 ret=$?
48 if test -n "$syntax"; then
49 printf "not ok %s - (syntax error)\n" "$count $2"
50 printf "[FAIL] test $count\n"
51 elif [ "$ret" != "$1" ]; then
52 printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
53 printf "[FAIL] test $count\n"
54 else
55 printf "ok %s\n" "$count $2"
56 printf "[PASS] test $count\n"
57 fi
58 }
59
60 count=0
61 echo "1..130"
62 printf "[TEST] shell_cmds: test\n"
63
64 t 0 'b = b'
65 t 0 'b == b'
66 t 1 'b != b'
67 t 0 '\( b = b \)'
68 t 0 '\( b == b \)'
69 t 1 '! \( b = b \)'
70 t 1 '! \( b == b \)'
71 t 1 '! -f /etc/passwd'
72
73 t 0 '-h = -h'
74 t 0 '-o = -o'
75 t 1 '-f = h'
76 t 1 '-h = f'
77 t 1 '-o = f'
78 t 1 'f = -o'
79 t 0 '\( -h = -h \)'
80 t 1 '\( a = -h \)'
81 t 1 '\( -f = h \)'
82 t 0 '-h = -h -o a'
83 t 0 '\( -h = -h \) -o 1'
84 t 0 '-h = -h -o -h = -h'
85 t 0 '\( -h = -h \) -o \( -h = -h \)'
86 t 0 'roedelheim = roedelheim'
87 t 1 'potsdam = berlin-dahlem'
88
89 t 0 '-d /'
90 t 0 '-d / -a a != b'
91 t 1 '-z "-z"'
92 t 0 '-n -n'
93
94 t 0 '0'
95 t 0 '\( 0 \)'
96 t 0 '-E'
97 t 0 '-X -a -X'
98 t 0 '-XXX'
99 t 0 '\( -E \)'
100 t 0 'true -o X'
101 t 0 'true -o -X'
102 t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true'
103 t 1 '-h /'
104 t 0 '-r /'
105 t 1 '-w /'
106 t 0 '-x /bin/sh'
107 t 0 '-c /dev/null'
108 t 0 '-f /etc/passwd'
109 t 0 '-s /etc/passwd'
110
111 t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
112 t 0 '100 -eq 100'
113 t 0 '100 -lt 200'
114 t 1 '1000 -lt 200'
115 t 0 '1000 -gt 200'
116 t 0 '1000 -ge 200'
117 t 0 '1000 -ge 1000'
118 t 1 '2 -ne 2'
119 t 0 '0 -eq 0'
120 t 1 '-5 -eq 5'
121 t 0 '\( 0 -eq 0 \)'
122 t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa'
123
124 t 1 '"" -o ""'
125 t 1 '"" -a ""'
126 t 1 '"a" -a ""'
127 t 0 '"a" -a ! ""'
128 t 1 '""'
129 t 0 '! ""'
130
131 t 0 '!'
132 t 0 '\('
133 t 0 '\)'
134
135 t 1 '\( = \)'
136 t 0 '\( != \)'
137 t 0 '\( ! \)'
138 t 0 '\( \( \)'
139 t 0 '\( \) \)'
140 t 0 '! = !'
141 t 1 '! != !'
142 t 1 '-n = \)'
143 t 0 '! != \)'
144 t 1 '! = a'
145 t 0 '! != -n'
146 t 0 '! -c /etc/passwd'
147
148 t 1 '! = = ='
149 t 0 '! = = \)'
150 t 0 '! "" -o ""'
151 t 1 '! "x" -o ""'
152 t 1 '! "" -o "x"'
153 t 1 '! "x" -o "x"'
154 t 0 '\( -f /etc/passwd \)'
155 t 0 '\( ! "" \)'
156 t 1 '\( ! -e \)'
157
158 t 0 '0 -eq 0 -a -d /'
159 t 0 '-s = "" -o "" = ""'
160 t 0 '"" = "" -o -s = ""'
161 t 1 '-s = "" -o -s = ""'
162 t 0 '-z x -o x = "#" -o x = x'
163 t 1 '-z y -o y = "#" -o y = x'
164 t 0 '0 -ne 0 -o ! -f /'
165 t 0 '1 -ne 0 -o ! -f /etc/passwd'
166 t 1 '0 -ne 0 -o ! -f /etc/passwd'
167
168 t 0 '-n ='
169 t 1 '-z ='
170 t 1 '! ='
171 t 0 '-n -eq'
172 t 1 '-z -eq'
173 t 1 '! -eq'
174 t 0 '-n -a'
175 t 1 '-z -a'
176 t 1 '! -a'
177 t 0 '-n -o'
178 t 1 '-z -o'
179 t 1 '! -o'
180 t 1 '! -n ='
181 t 0 '! -z ='
182 t 0 '! ! ='
183 t 1 '! -n -eq'
184 t 0 '! -z -eq'
185 t 0 '! ! -eq'
186 t 1 '! -n -a'
187 t 0 '! -z -a'
188 t 0 '! ! -a'
189 t 1 '! -n -o'
190 t 0 '! -z -o'
191 t 0 '! ! -o'
192 t 0 '\( -n = \)'
193 t 1 '\( -z = \)'
194 t 1 '\( ! = \)'
195 t 0 '\( -n -eq \)'
196 t 1 '\( -z -eq \)'
197 t 1 '\( ! -eq \)'
198 t 0 '\( -n -a \)'
199 t 1 '\( -z -a \)'
200 t 1 '\( ! -a \)'
201 t 0 '\( -n -o \)'
202 t 1 '\( -z -o \)'
203 t 1 '\( ! -o \)'