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