Add regression tests for /bin/test.
[dragonfly.git] / tools / regression / bin / test / regress.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: src/tools/regression/bin/test/regress.sh,v 1.1 2010/11/08 23:15:10 jilles Exp $
32
33 # force a specified test program, e.g. `env test=/bin/test sh regress.sh'
34 : ${test=test}          
35
36 t ()
37 {
38         # $1 -> exit code
39         # $2 -> $test expression
40
41         count=$((count+1))
42         # check for syntax errors
43         syntax="`eval $test $2 2>&1`"
44         ret=$?
45         if test -n "$syntax"; then
46                 printf "not ok %s - (syntax error)\n" "$count $2"
47         elif [ "$ret" != "$1" ]; then
48                 printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
49         else
50                 printf "ok %s\n" "$count $2"
51         fi
52 }
53
54 count=0
55 echo "1..94"
56
57 t 0 'b = b' 
58 t 1 'b != b' 
59 t 0 '\( b = b \)' 
60 t 1 '! \( b = b \)' 
61 t 1 '! -f /etc/passwd'
62
63 t 0 '-h = -h'
64 t 0 '-o = -o'
65 t 1 '-f = h'
66 t 1 '-h = f'
67 t 1 '-o = f'
68 t 1 'f = -o'
69 t 0 '\( -h = -h \)'
70 t 1 '\( a = -h \)'
71 t 1 '\( -f = h \)'
72 t 0 '-h = -h -o a'
73 t 0 '\( -h = -h \) -o 1'
74 t 0 '-h = -h -o -h = -h'
75 t 0 '\( -h = -h \) -o \( -h = -h \)'
76 t 0 'roedelheim = roedelheim'
77 t 1 'potsdam = berlin-dahlem'
78
79 t 0 '-d /'
80 t 0 '-d / -a a != b'
81 t 1 '-z "-z"'
82 t 0 '-n -n'
83
84 t 0 '0'
85 t 0 '\( 0 \)'
86 t 0 '-E'
87 t 0 '-X -a -X'
88 t 0 '-XXX'
89 t 0 '\( -E \)'
90 t 0 'true -o X'
91 t 0 'true -o -X'
92 t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true'
93 t 1 '-h /'
94 t 0 '-r /'
95 t 1 '-w /'
96 t 0 '-x /bin/sh'
97 t 0 '-c /dev/null'
98 t 0 '-f /etc/passwd'
99 t 0 '-s /etc/passwd'
100
101 t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
102 t 0 '100 -eq 100'
103 t 0 '100 -lt 200'
104 t 1 '1000 -lt 200'
105 t 0 '1000 -gt 200'
106 t 0 '1000 -ge 200'
107 t 0 '1000 -ge 1000'
108 t 1 '2 -ne 2'
109 t 0 '0 -eq 0'
110 t 1 '-5 -eq 5'
111 t 0 '\( 0 -eq 0 \)'
112 t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa'
113
114 t 1 '"" -o ""'
115 t 1 '"" -a ""'
116 t 1 '"a" -a ""'
117 t 0 '"a" -a ! ""'
118 t 1 '""'
119 t 0 '! ""'
120
121 t 0 '!'
122 t 0 '\('
123 t 0 '\)'
124
125 t 1 '\( = \)'
126 t 0 '\( != \)'
127 t 0 '\( ! \)'
128 t 0 '\( \( \)'
129 t 0 '\( \) \)'
130 t 0 '! = !'
131 t 1 '! != !'
132 t 1 '-n = \)'
133 t 0 '! != \)'
134 t 1 '! = a'
135 t 0 '! != -n'
136 t 0 '! -c /etc/passwd'
137
138 t 0 '! \( = \)'
139 t 1 '! \( != \)'
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 1 '\( ! = \)'
148 t 0 '\( ! "" \)'
149 t 1 '\( ! -e \)'
150
151 t 0 '0 -eq 0 -a -d /'
152 t 0 '-s = "" -o "" = ""'
153 t 0 '"" = "" -o -s = ""'
154 t 1 '-s = "" -o -s = ""'
155 t 0 '-z x -o x = "#" -o x = x'
156 t 1 '-z y -o y = "#" -o y = x'
157 t 0 '0 -ne 0 -o ! -f /'
158 t 0 '1 -ne 0 -o ! -f /etc/passwd'
159 t 1 '0 -ne 0 -o ! -f /etc/passwd'