3 # Copyright (c) 2010 Hudson River Trading LLC
4 # Written by: John H. Baldwin <jhb@FreeBSD.org>
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
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.
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
30 # Various regression tests to test the -I flag to the 'update' command.
37 echo "Usage: ignore.sh [-s script] [-w workdir]"
41 # Allow the user to specify an alternate work directory or script.
43 while getopts "s:w:" option; do
62 CONFLICTS=$WORKDIR/conflicts
67 # These tests deal with ignoring certain patterns of files. We run the
68 # test multiple times ignoring different patterns.
73 rm -rf $OLD $NEW $TEST $CONFLICTS
74 mkdir -p $OLD $NEW $TEST
76 for i in $OLD $NEW $TEST; do
80 # tree: Test three different cases (add, modify, remove) that all
81 # match the tree/* glob.
82 echo "foo" > $NEW/tree/add
83 for i in $OLD $TEST; do
84 echo "old" > $i/tree/modify
86 echo "new" > $NEW/tree/modify
87 for i in $OLD $TEST; do
88 echo "old" > $i/tree/remove
91 # rmdir: Remove a whole tree.
92 for i in $OLD $TEST; do
94 echo "foo" > $i/rmdir/file
98 # $1 - relative path to file that should be missing from TEST
101 if [ -e $TEST/$1 -o -L $TEST/$1 ]; then
102 echo "File $1 should be missing"
107 # $1 - relative path to file that should be present in TEST
110 if ! [ -e $TEST/$1 -o -L $TEST/$1 ]; then
111 echo "File $1 should be present"
116 # $1 - relative path to file that should be a directory in TEST
119 if ! [ -d $TEST/$1 ]; then
120 echo "File $1 should be a directory"
125 # $1 - relative path to regular file that should be present in TEST
126 # $2 - optional string that should match file contents
127 # $3 - optional MD5 of the flie contents, overrides $2 if present
132 if ! [ -f $TEST/$1 ]; then
133 echo "File $1 should be a regular file"
135 elif [ $# -eq 2 ]; then
136 contents=`cat $TEST/$1`
137 if [ "$contents" != "$2" ]; then
138 echo "File $1 has wrong contents"
141 elif [ $# -eq 3 ]; then
142 sum=`md5 -q $TEST/$1`
143 if [ "$sum" != "$3" ]; then
144 echo "File $1 has wrong contents"
150 # $1 - relative path to a regular file that should have a conflict
151 # $2 - optional MD5 of the conflict file contents
156 if ! [ -f $CONFLICTS/$1 ]; then
157 echo "File $1 missing conflict"
159 elif [ $# -gt 1 ]; then
160 sum=`md5 -q $CONFLICTS/$1`
161 if [ "$sum" != "$2" ]; then
162 echo "Conflict $1 has wrong contents"
168 # $1 - relative path to a regular file that should not have a conflict
171 if [ -f $CONFLICTS/$1 ]; then
172 echo "File $1 should not have a conflict"
177 if [ `id -u` -ne 0 ]; then
182 if [ -r /etc/etcupdate.conf ]; then
183 echo "WARNING: /etc/etcupdate.conf settings may break some tests."
186 # First run the test ignoring no patterns.
190 $COMMAND -r -d $WORKDIR -D $TEST > $WORKDIR/test.out
192 cat > $WORKDIR/correct.out <<EOF
200 echo "Differences for regular:"
201 diff -u -L "correct" $WORKDIR/correct.out -L "test" $WORKDIR/test.out \
205 file /tree/modify "new"
210 # Now test with -I '/tree/*'. This should preserve the /tree files.
214 $COMMAND -r -I '/tree/*' -d $WORKDIR -D $TEST > $WORKDIR/test1.out
216 cat > $WORKDIR/correct1.out <<EOF
221 echo "Differences for -I '/tree/*':"
222 diff -u -L "correct" $WORKDIR/correct1.out -L "test" $WORKDIR/test1.out \
225 file /tree/remove "old"
226 file /tree/modify "old"
231 # Now test with two patterns. This should preserve everything.
235 $COMMAND -r -I '/tree/*' -I '/rmdir*' -d $WORKDIR -D $TEST > \
238 cat > $WORKDIR/correct2.out <<EOF
241 echo "Differences for -I '/tree/*' -I '/rmdir*':"
243 diff -u -L "correct" $WORKDIR/correct2.out -L "test" $WORKDIR/test2.out \
246 file /tree/remove "old"
247 file /tree/modify "old"
249 file /rmdir/file "foo"
251 # Now test with a pattern that should cause a warning on /rmdir by
252 # only ignoring the files under that directory. Note that this also
253 # tests putting two patterns into a single -I argument.
257 $COMMAND -r -I '/tree/* /rmdir/*' -d $WORKDIR -D $TEST > \
260 cat > $WORKDIR/correct3.out <<EOF
262 Non-empty directory remains: /rmdir
265 echo "Differences for -I '/tree/* /rmdir/*':"
267 diff -u -L "correct" $WORKDIR/correct3.out -L "test" $WORKDIR/test3.out \
270 file /tree/remove "old"
271 file /tree/modify "old"
273 file /rmdir/file "foo"