]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - tools/regression/environ/envtest.t
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / tools / regression / environ / envtest.t
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Sean C. Farley <scf@FreeBSD.org>
4 # All rights reserved.
5
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
9 # 1. Redistributions of source code must retain the above copyright
10 #    notice, this list of conditions and the following disclaimer,
11 #    without modification, immediately at the beginning of the file.
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 ``AS IS'' AND ANY EXPRESS OR
17 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #
27 # $FreeBSD$
28
29
30 # Initialization.
31 testndx=0
32
33
34 # Testing function.
35 run_test()
36 {
37         lasttest="${@}"
38         result=`./envctl -t "${@}"`
39
40         if [ ${?} -ne 0 ]
41         then
42                 echo "Test program failed" >&2
43                 exit 1
44         fi
45
46         return
47 }
48
49
50 # Perform test on results.
51 check_result()
52 {
53         testndx=$((testndx + 1))
54
55         echo "${result}" | sed 's/[ \t]*$//' | grep -q "^${@}$"
56         if [ ${?} -eq 0 ]
57         then
58                 echo "ok ${testndx}"
59         else
60                 echo "not ok ${testndx} - '${lasttest}'"
61         fi
62
63         return
64 }
65
66
67 #
68 # Regression tests
69 #
70
71 # Setup environment for tests.
72 readonly BAR="bar"
73 readonly NEWBAR="newbar"
74 export FOO=${BAR}
75
76
77 # Gets from environ.
78 run_test -g FOO
79 check_result "${FOO}"
80
81 run_test -c -g FOO
82 check_result ""
83
84 run_test -g FOOBAR
85 check_result ""
86
87 run_test -c -g FOOBAR
88 check_result ""
89
90 run_test -G
91 check_result ""
92
93
94 # Sets.
95 run_test -s FOO ${NEWBAR} 0 -g FOO
96 check_result "0 0 ${BAR}"
97
98 run_test -s FOO ${NEWBAR} 1 -g FOO
99 check_result "0 0 ${NEWBAR}"
100
101 run_test -c -s FOO ${NEWBAR} 0 -g FOO
102 check_result "0 0 ${NEWBAR}"
103
104 run_test -c -s FOO ${NEWBAR} 1 -g FOO
105 check_result "0 0 ${NEWBAR}"
106
107 run_test -s "FOO=" ${NEWBAR} 1 -g FOO
108 check_result "-1 22 ${BAR}"
109
110 run_test -s "=FOO" ${NEWBAR} 1
111 check_result "-1 22"
112
113 run_test -s "=" ${NEWBAR} 1
114 check_result "-1 22"
115
116 run_test -s "" ${NEWBAR} 1
117 check_result "-1 22"
118
119 run_test -S ${NEWBAR} 1
120 check_result "-1 22"
121
122 run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -g FOO
123 check_result "0 0 0 0 ${BAR}"
124
125 run_test -c -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -g FOO
126 check_result "0 0 0 0 ${BAR}"
127
128 run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -s FOO ${NEWBAR} 1 -g FOO
129 check_result "0 0 0 0 0 0 ${NEWBAR}"
130
131 run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1\
132         -g FOO
133 check_result "0 0 0 0 0 0 0 0 ${BAR}"
134
135 run_test -c -s FOO ${BAR} 1 -g FOO -c -s FOO ${NEWBAR} 1 -g FOO
136 check_result "0 0 ${BAR} 0 0 ${NEWBAR}"
137
138
139 # Unsets.
140 run_test -u FOO -g FOO
141 check_result "0 0"
142
143 run_test -c -u FOO -g FOO
144 check_result "0 0"
145
146 run_test -U
147 check_result "-1 22"
148
149 run_test -u ""
150 check_result "-1 22"
151
152 run_test -u "=${BAR}"
153 check_result "-1 22"
154
155 run_test -c -s FOO ${NEWBAR} 1 -g FOO -u FOO -g FOO
156 check_result "0 0 ${NEWBAR} 0 0"
157
158 run_test -c -u FOO -s FOO ${BAR} 1 -g FOO -u FOO -g FOO -c -u FOO\
159         -s FOO ${NEWBAR} 1 -g FOO
160 check_result "0 0 0 0 ${BAR} 0 0  0 0 0 0 ${NEWBAR}"
161
162
163 # Puts.
164 run_test -p FOO=${NEWBAR} -g FOO
165 check_result "0 0 ${NEWBAR}"
166
167 run_test -c -p FOO=${NEWBAR} -g FOO
168 check_result "0 0 ${NEWBAR}"
169
170 run_test -p FOO -g FOO
171 check_result "-1 22 ${BAR}"
172
173 run_test -p FOO=${BAR} -p FOO=${NEWBAR} -g FOO
174 check_result "0 0 0 0 ${NEWBAR}"
175
176 run_test -p FOO=${BAR} -s FOO ${NEWBAR} 1 -g FOO
177 check_result "0 0 0 0 ${NEWBAR}"
178
179 run_test -s FOO ${NEWBAR} 1 -p FOO=${BAR} -g FOO
180 check_result "0 0 0 0 ${BAR}"
181
182 run_test -p FOO=${BAR} -u FOO
183 check_result "0 0 0 0"
184
185 run_test -p FOO=${BAR} -s FOO ${NEWBAR} 1 -u FOO
186 check_result "0 0 0 0 0 0"
187
188 run_test -s FOO ${NEWBAR} 1 -p FOO=${BAR} -u FOO
189 check_result "0 0 0 0 0 0"
190
191 run_test -s FOO ${NEWBAR} 1 -p FOO=${BAR} -c -g FOO -p FOO=${NEWBAR} -g FOO
192 check_result "0 0 0 0  0 0 ${NEWBAR}"
193
194 run_test -c -p FOO=${BAR} -g FOO -c -p FOO=${NEWBAR} -g FOO
195 check_result "0 0 ${BAR} 0 0 ${NEWBAR}"
196
197
198 # environ replacements.
199 run_test -r -g FOO -s FOO ${BAR} 1 -g FOO -u FOO -g FOO
200 check_result "${BAR} 0 0 ${BAR} 0 0"
201
202 run_test -r -g FOO -u FOO -g FOO -s FOO ${BAR} 1 -g FOO
203 check_result "${BAR} 0 0  0 0 ${BAR}"