3 # Copyright (c) 2007 Sean C. Farley <scf@FreeBSD.org>
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
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.
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.
38 result=`./envctl -t "${@}"`
42 echo "Test program failed" >&2
50 # Perform test on results.
53 testndx=$((testndx + 1))
55 echo "${result}" | sed 's/[ \t]*$//' | grep -q "^${@}$"
60 echo "not ok ${testndx} - '${lasttest}'"
71 # Setup environment for tests.
73 readonly NEWBAR="newbar"
95 run_test -s FOO ${NEWBAR} 0 -g FOO
96 check_result "0 0 ${BAR}"
98 run_test -s FOO ${NEWBAR} 1 -g FOO
99 check_result "0 0 ${NEWBAR}"
101 run_test -c -s FOO ${NEWBAR} 0 -g FOO
102 check_result "0 0 ${NEWBAR}"
104 run_test -c -s FOO ${NEWBAR} 1 -g FOO
105 check_result "0 0 ${NEWBAR}"
107 run_test -s "FOO=" ${NEWBAR} 1 -g FOO
108 check_result "-1 22 ${BAR}"
110 run_test -s "=FOO" ${NEWBAR} 1
113 run_test -s "=" ${NEWBAR} 1
116 run_test -s "" ${NEWBAR} 1
119 run_test -S ${NEWBAR} 1
122 run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -g FOO
123 check_result "0 0 0 0 ${BAR}"
125 run_test -c -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -g FOO
126 check_result "0 0 0 0 ${BAR}"
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}"
131 run_test -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1 -s FOO ${NEWBAR} 1 -s FOO ${BAR} 1\
133 check_result "0 0 0 0 0 0 0 0 ${BAR}"
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}"
140 run_test -u FOO -g FOO
143 run_test -c -u FOO -g FOO
152 run_test -u "=${BAR}"
155 run_test -c -s FOO ${NEWBAR} 1 -g FOO -u FOO -g FOO
156 check_result "0 0 ${NEWBAR} 0 0"
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}"
164 run_test -p FOO=${NEWBAR} -g FOO
165 check_result "0 0 ${NEWBAR}"
167 run_test -c -p FOO=${NEWBAR} -g FOO
168 check_result "0 0 ${NEWBAR}"
170 run_test -p FOO -g FOO
171 check_result "-1 22 ${BAR}"
173 run_test -p FOO=${BAR} -p FOO=${NEWBAR} -g FOO
174 check_result "0 0 0 0 ${NEWBAR}"
176 run_test -p FOO=${BAR} -s FOO ${NEWBAR} 1 -g FOO
177 check_result "0 0 0 0 ${NEWBAR}"
179 run_test -s FOO ${NEWBAR} 1 -p FOO=${BAR} -g FOO
180 check_result "0 0 0 0 ${BAR}"
182 run_test -p FOO=${BAR} -u FOO
183 check_result "0 0 0 0"
185 run_test -p FOO=${BAR} -s FOO ${NEWBAR} 1 -u FOO
186 check_result "0 0 0 0 0 0"
188 run_test -s FOO ${NEWBAR} 1 -p FOO=${BAR} -u FOO
189 check_result "0 0 0 0 0 0"
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}"
194 run_test -c -p FOO=${BAR} -g FOO -c -p FOO=${NEWBAR} -g FOO
195 check_result "0 0 ${BAR} 0 0 ${NEWBAR}"
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"
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}"