Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 . ./common.sh
19 function test_add_basic {
20 local testroot=`test_init add_basic`
22 got checkout $testroot/repo $testroot/wt > /dev/null
23 ret="$?"
24 if [ "$ret" != "0" ]; then
25 test_done "$testroot" "$ret"
26 return 1
27 fi
29 echo "new file" > $testroot/wt/foo
31 echo 'A foo' > $testroot/stdout.expected
32 (cd $testroot/wt && got add foo > $testroot/stdout)
34 cmp -s $testroot/stdout.expected $testroot/stdout
35 ret="$?"
36 if [ "$ret" != "0" ]; then
37 diff -u $testroot/stdout.expected $testroot/stdout
38 fi
39 test_done "$testroot" "$ret"
40 }
42 function test_double_add {
43 local testroot=`test_init double_add`
45 got checkout $testroot/repo $testroot/wt > /dev/null
46 ret="$?"
47 if [ "$ret" != "0" ]; then
48 test_done "$testroot" "$ret"
49 return 1
50 fi
52 echo "new file" > $testroot/wt/foo
53 (cd $testroot/wt && got add foo > /dev/null)
55 (cd $testroot/wt && got add foo > $testroot/stdout)
56 ret="$?"
57 if [ "$ret" != "0" ]; then
58 echo "got add failed unexpectedly" >&2
59 test_done "$testroot" 1
60 return 1
61 fi
63 echo -n > $testroot/stdout.expected
64 cmp -s $testroot/stdout.expected $testroot/stdout
65 ret="$?"
66 if [ "$ret" != "0" ]; then
67 diff -u $testroot/stdout.expected $testroot/stdout
68 fi
69 test_done "$testroot" "$ret"
70 }
72 function test_add_multiple {
73 local testroot=`test_init multiple_add`
75 got checkout $testroot/repo $testroot/wt > /dev/null
76 ret="$?"
77 if [ "$ret" != "0" ]; then
78 test_done "$testroot" "$ret"
79 return 1
80 fi
82 echo "new file" > $testroot/wt/foo
83 echo "new file" > $testroot/wt/bar
84 echo "new file" > $testroot/wt/baz
85 (cd $testroot/wt && got add foo bar baz > $testroot/stdout)
86 ret="$?"
87 if [ "$ret" != "0" ]; then
88 echo "got add failed unexpectedly" >&2
89 test_done "$testroot" 1
90 return 1
91 fi
93 echo "A foo" > $testroot/stdout.expected
94 echo "A bar" >> $testroot/stdout.expected
95 echo "A baz" >> $testroot/stdout.expected
97 cmp -s $testroot/stdout.expected $testroot/stdout
98 ret="$?"
99 if [ "$ret" != "0" ]; then
100 diff -u $testroot/stdout.expected $testroot/stdout
101 fi
102 test_done "$testroot" "$ret"
105 function test_add_file_in_new_subdir {
106 local testroot=`test_init add_file_in_new_subdir`
108 got checkout $testroot/repo $testroot/wt > /dev/null
109 ret="$?"
110 if [ "$ret" != "0" ]; then
111 test_done "$testroot" "$ret"
112 return 1
113 fi
115 mkdir -p $testroot/wt/new
116 echo "new file" > $testroot/wt/new/foo
118 echo 'A new/foo' > $testroot/stdout.expected
119 (cd $testroot/wt && got add new/foo > $testroot/stdout)
121 cmp -s $testroot/stdout.expected $testroot/stdout
122 ret="$?"
123 if [ "$ret" != "0" ]; then
124 diff -u $testroot/stdout.expected $testroot/stdout
125 fi
126 test_done "$testroot" "$ret"
129 function test_add_deleted {
130 local testroot=`test_init add_deleted`
132 got checkout $testroot/repo $testroot/wt > /dev/null
133 ret="$?"
134 if [ "$ret" != "0" ]; then
135 test_done "$testroot" "$ret"
136 return 1
137 fi
139 (cd $testroot/wt && got rm beta > /dev/null)
141 echo -n > $testroot/stdout.expected
142 (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
143 ret="$?"
144 if [ "$ret" == "0" ]; then
145 echo "got add command succeeded unexpectedly" >&2
146 diff -u $testroot/stdout.expected $testroot/stdout
147 test_done "$testroot" "1"
148 return 1
149 fi
151 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
152 cmp -s $testroot/stderr.expected $testroot/stderr
153 ret="$?"
154 if [ "$ret" != "0" ]; then
155 diff -u $testroot/stderr.expected $testroot/stderr
156 fi
157 test_done "$testroot" "$ret"
160 function test_add_directory {
161 local testroot=`test_init add_directory`
163 got checkout $testroot/repo $testroot/wt > /dev/null
164 ret="$?"
165 if [ "$ret" != "0" ]; then
166 test_done "$testroot" "$ret"
167 return 1
168 fi
170 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
171 ret="$?"
172 echo "got: adding directories requires -R option" \
173 > $testroot/stderr.expected
174 cmp -s $testroot/stderr.expected $testroot/stderr
175 ret="$?"
176 if [ "$ret" != "0" ]; then
177 diff -u $testroot/stderr.expected $testroot/stderr
178 test_done "$testroot" "$ret"
179 return 1
180 fi
182 (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
183 ret="$?"
184 echo "got: disregarding ignores requires -R option" \
185 > $testroot/stderr.expected
186 cmp -s $testroot/stderr.expected $testroot/stderr
187 ret="$?"
188 if [ "$ret" != "0" ]; then
189 diff -u $testroot/stderr.expected $testroot/stderr
190 test_done "$testroot" "$ret"
191 return 1
192 fi
194 echo -n > $testroot/stdout.expected
195 cmp -s $testroot/stdout.expected $testroot/stdout
196 ret="$?"
197 if [ "$ret" != "0" ]; then
198 diff -u $testroot/stdout.expected $testroot/stdout
199 test_done "$testroot" "$ret"
200 return 1
201 fi
203 mkdir -p $testroot/wt/tree1
204 mkdir -p $testroot/wt/tree2
205 echo "tree1/**" > $testroot/wt/.gitignore
206 echo "tree2/**" >> $testroot/wt/.gitignore
207 echo -n > $testroot/wt/tree1/foo
208 echo -n > $testroot/wt/tree2/foo
209 echo -n > $testroot/wt/epsilon/zeta1
210 echo -n > $testroot/wt/epsilon/zeta2
212 (cd $testroot/wt && got add -R . > $testroot/stdout)
214 echo 'A .gitignore' > $testroot/stdout.expected
215 echo 'A epsilon/zeta1' >> $testroot/stdout.expected
216 echo 'A epsilon/zeta2' >> $testroot/stdout.expected
218 cmp -s $testroot/stdout.expected $testroot/stdout
219 ret="$?"
220 if [ "$ret" != "0" ]; then
221 diff -u $testroot/stdout.expected $testroot/stdout
222 test_done "$testroot" "$ret"
223 return 1
224 fi
226 (cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
228 echo 'A tree1/foo' > $testroot/stdout.expected
230 cmp -s $testroot/stdout.expected $testroot/stdout
231 ret="$?"
232 if [ "$ret" != "0" ]; then
233 diff -u $testroot/stdout.expected $testroot/stdout
234 test_done "$testroot" "$ret"
235 return 1
236 fi
238 (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
240 echo 'A tree2/foo' > $testroot/stdout.expected
242 cmp -s $testroot/stdout.expected $testroot/stdout
243 ret="$?"
244 if [ "$ret" != "0" ]; then
245 diff -u $testroot/stdout.expected $testroot/stdout
246 test_done "$testroot" "$ret"
247 return 1
248 fi
249 test_done "$testroot" "$ret"
252 run_test test_add_basic
253 run_test test_double_add
254 run_test test_add_multiple
255 run_test test_add_file_in_new_subdir
256 run_test test_add_deleted
257 run_test test_add_directory