Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/bin/test/tests/legacy_test.sh
39586 views
1
#!/bin/sh
2
3
#-
4
# Copyright (c) June 1996 Wolfram Schneider <[email protected]>. 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
32
# force a specified test program, e.g. `env test=/bin/test sh regress.sh'
33
: ${test=test}
34
35
t ()
36
{
37
# $1 -> exit code
38
# $2 -> $test expression
39
40
count=$((count+1))
41
# check for syntax errors
42
syntax="`eval $test $2 2>&1`"
43
ret=$?
44
if test -n "$syntax"; then
45
printf "not ok %s - (syntax error)\n" "$count $2"
46
elif [ "$ret" != "$1" ]; then
47
printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
48
else
49
printf "ok %s\n" "$count $2"
50
fi
51
}
52
53
count=0
54
echo "1..130"
55
56
t 0 'b = b'
57
t 0 'b == b'
58
t 1 'b != b'
59
t 0 '\( b = b \)'
60
t 0 '\( b == b \)'
61
t 1 '! \( b = b \)'
62
t 1 '! \( b == b \)'
63
t 1 '! -f /etc/passwd'
64
65
t 0 '-h = -h'
66
t 0 '-o = -o'
67
t 1 '-f = h'
68
t 1 '-h = f'
69
t 1 '-o = f'
70
t 1 'f = -o'
71
t 0 '\( -h = -h \)'
72
t 1 '\( a = -h \)'
73
t 1 '\( -f = h \)'
74
t 0 '-h = -h -o a'
75
t 0 '\( -h = -h \) -o 1'
76
t 0 '-h = -h -o -h = -h'
77
t 0 '\( -h = -h \) -o \( -h = -h \)'
78
t 0 'roedelheim = roedelheim'
79
t 1 'potsdam = berlin-dahlem'
80
81
t 0 '-d /'
82
t 0 '-d / -a a != b'
83
t 1 '-z "-z"'
84
t 0 '-n -n'
85
86
t 0 '0'
87
t 0 '\( 0 \)'
88
t 0 '-E'
89
t 0 '-X -a -X'
90
t 0 '-XXX'
91
t 0 '\( -E \)'
92
t 0 'true -o X'
93
t 0 'true -o -X'
94
t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true'
95
t 1 '-h /'
96
t 0 '-r /'
97
t 1 '-w /'
98
t 0 '-x /bin/sh'
99
t 0 '-c /dev/null'
100
t 0 '-f /etc/passwd'
101
t 0 '-s /etc/passwd'
102
103
t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
104
t 0 '100 -eq 100'
105
t 0 '100 -lt 200'
106
t 1 '1000 -lt 200'
107
t 0 '1000 -gt 200'
108
t 0 '1000 -ge 200'
109
t 0 '1000 -ge 1000'
110
t 1 '2 -ne 2'
111
t 0 '0 -eq 0'
112
t 1 '-5 -eq 5'
113
t 0 '\( 0 -eq 0 \)'
114
t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa'
115
116
t 1 '"" -o ""'
117
t 1 '"" -a ""'
118
t 1 '"a" -a ""'
119
t 0 '"a" -a ! ""'
120
t 1 '""'
121
t 0 '! ""'
122
123
t 0 '!'
124
t 0 '\('
125
t 0 '\)'
126
127
t 1 '\( = \)'
128
t 0 '\( != \)'
129
t 0 '\( ! \)'
130
t 0 '\( \( \)'
131
t 0 '\( \) \)'
132
t 0 '! = !'
133
t 1 '! != !'
134
t 1 '-n = \)'
135
t 0 '! != \)'
136
t 1 '! = a'
137
t 0 '! != -n'
138
t 0 '! -c /etc/passwd'
139
140
t 1 '! = = ='
141
t 0 '! = = \)'
142
t 0 '! "" -o ""'
143
t 1 '! "x" -o ""'
144
t 1 '! "" -o "x"'
145
t 1 '! "x" -o "x"'
146
t 0 '\( -f /etc/passwd \)'
147
t 0 '\( ! "" \)'
148
t 1 '\( ! -e \)'
149
150
t 0 '0 -eq 0 -a -d /'
151
t 0 '-s = "" -o "" = ""'
152
t 0 '"" = "" -o -s = ""'
153
t 1 '-s = "" -o -s = ""'
154
t 0 '-z x -o x = "#" -o x = x'
155
t 1 '-z y -o y = "#" -o y = x'
156
t 0 '0 -ne 0 -o ! -f /'
157
t 0 '1 -ne 0 -o ! -f /etc/passwd'
158
t 1 '0 -ne 0 -o ! -f /etc/passwd'
159
160
t 0 '-n ='
161
t 1 '-z ='
162
t 1 '! ='
163
t 0 '-n -eq'
164
t 1 '-z -eq'
165
t 1 '! -eq'
166
t 0 '-n -a'
167
t 1 '-z -a'
168
t 1 '! -a'
169
t 0 '-n -o'
170
t 1 '-z -o'
171
t 1 '! -o'
172
t 1 '! -n ='
173
t 0 '! -z ='
174
t 0 '! ! ='
175
t 1 '! -n -eq'
176
t 0 '! -z -eq'
177
t 0 '! ! -eq'
178
t 1 '! -n -a'
179
t 0 '! -z -a'
180
t 0 '! ! -a'
181
t 1 '! -n -o'
182
t 0 '! -z -o'
183
t 0 '! ! -o'
184
t 0 '\( -n = \)'
185
t 1 '\( -z = \)'
186
t 1 '\( ! = \)'
187
t 0 '\( -n -eq \)'
188
t 1 '\( -z -eq \)'
189
t 1 '\( ! -eq \)'
190
t 0 '\( -n -a \)'
191
t 1 '\( -z -a \)'
192
t 1 '\( ! -a \)'
193
t 0 '\( -n -o \)'
194
t 1 '\( -z -o \)'
195
t 1 '\( ! -o \)'
196
197