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)
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 test_done "$testroot" "$ret"
64 }
66 function test_add_multiple {
67 local testroot=`test_init multiple_add`
69 got checkout $testroot/repo $testroot/wt > /dev/null
70 ret="$?"
71 if [ "$ret" != "0" ]; then
72 test_done "$testroot" "$ret"
73 return 1
74 fi
76 echo "new file" > $testroot/wt/foo
77 echo "new file" > $testroot/wt/bar
78 echo "new file" > $testroot/wt/baz
79 (cd $testroot/wt && got add foo bar baz > $testroot/stdout)
80 ret="$?"
81 if [ "$ret" != "0" ]; then
82 echo "got add failed unexpectedly" >&2
83 test_done "$testroot" 1
84 return 1
85 fi
87 echo "A foo" > $testroot/stdout.expected
88 echo "A bar" >> $testroot/stdout.expected
89 echo "A baz" >> $testroot/stdout.expected
91 cmp -s $testroot/stdout.expected $testroot/stdout
92 ret="$?"
93 if [ "$ret" != "0" ]; then
94 diff -u $testroot/stdout.expected $testroot/stdout
95 fi
96 test_done "$testroot" "$ret"
97 }
99 function test_add_file_in_new_subdir {
100 local testroot=`test_init add_file_in_new_subdir`
102 got checkout $testroot/repo $testroot/wt > /dev/null
103 ret="$?"
104 if [ "$ret" != "0" ]; then
105 test_done "$testroot" "$ret"
106 return 1
107 fi
109 mkdir -p $testroot/wt/new
110 echo "new file" > $testroot/wt/new/foo
112 echo 'A new/foo' > $testroot/stdout.expected
113 (cd $testroot/wt && got add new/foo > $testroot/stdout)
115 cmp -s $testroot/stdout.expected $testroot/stdout
116 ret="$?"
117 if [ "$ret" != "0" ]; then
118 diff -u $testroot/stdout.expected $testroot/stdout
119 fi
120 test_done "$testroot" "$ret"
123 function test_add_deleted {
124 local testroot=`test_init add_deleted`
126 got checkout $testroot/repo $testroot/wt > /dev/null
127 ret="$?"
128 if [ "$ret" != "0" ]; then
129 test_done "$testroot" "$ret"
130 return 1
131 fi
133 (cd $testroot/wt && got rm beta > /dev/null)
135 echo -n > $testroot/stdout.expected
136 (cd $testroot/wt && got add beta > $testroot/stdout 2> $testroot/stderr)
137 ret="$?"
138 if [ "$ret" == "0" ]; then
139 echo "got add command succeeded unexpectedly" >&2
140 diff -u $testroot/stdout.expected $testroot/stdout
141 test_done "$testroot" "1"
142 return 1
143 fi
145 echo "got: beta: file has unexpected status" > $testroot/stderr.expected
146 cmp -s $testroot/stderr.expected $testroot/stderr
147 ret="$?"
148 if [ "$ret" != "0" ]; then
149 diff -u $testroot/stderr.expected $testroot/stderr
150 fi
151 test_done "$testroot" "$ret"
154 function test_add_directory {
155 local testroot=`test_init add_directory`
157 got checkout $testroot/repo $testroot/wt > /dev/null
158 ret="$?"
159 if [ "$ret" != "0" ]; then
160 test_done "$testroot" "$ret"
161 return 1
162 fi
164 (cd $testroot/wt && got add . > $testroot/stdout 2> $testroot/stderr)
165 ret="$?"
166 echo "got: adding directories requires -R option" \
167 > $testroot/stderr.expected
168 cmp -s $testroot/stderr.expected $testroot/stderr
169 ret="$?"
170 if [ "$ret" != "0" ]; then
171 diff -u $testroot/stderr.expected $testroot/stderr
172 test_done "$testroot" "$ret"
173 return 1
174 fi
176 (cd $testroot/wt && got add -I . > $testroot/stdout 2> $testroot/stderr)
177 ret="$?"
178 echo "got: disregarding ignores requires -R option" \
179 > $testroot/stderr.expected
180 cmp -s $testroot/stderr.expected $testroot/stderr
181 ret="$?"
182 if [ "$ret" != "0" ]; then
183 diff -u $testroot/stderr.expected $testroot/stderr
184 test_done "$testroot" "$ret"
185 return 1
186 fi
188 echo -n > $testroot/stdout.expected
189 cmp -s $testroot/stdout.expected $testroot/stdout
190 ret="$?"
191 if [ "$ret" != "0" ]; then
192 diff -u $testroot/stdout.expected $testroot/stdout
193 test_done "$testroot" "$ret"
194 return 1
195 fi
197 mkdir -p $testroot/wt/tree1
198 mkdir -p $testroot/wt/tree2
199 echo "tree1/**" > $testroot/wt/.gitignore
200 echo "tree2/**" >> $testroot/wt/.gitignore
201 echo -n > $testroot/wt/tree1/foo
202 echo -n > $testroot/wt/tree2/foo
203 echo -n > $testroot/wt/epsilon/zeta1
204 echo -n > $testroot/wt/epsilon/zeta2
206 (cd $testroot/wt && got add -R . > $testroot/stdout)
208 echo 'A .gitignore' > $testroot/stdout.expected
209 echo 'A epsilon/zeta1' >> $testroot/stdout.expected
210 echo 'A epsilon/zeta2' >> $testroot/stdout.expected
212 cmp -s $testroot/stdout.expected $testroot/stdout
213 ret="$?"
214 if [ "$ret" != "0" ]; then
215 diff -u $testroot/stdout.expected $testroot/stdout
216 test_done "$testroot" "$ret"
217 return 1
218 fi
220 (cd $testroot/wt && got add -RI tree1 > $testroot/stdout)
222 echo 'A tree1/foo' > $testroot/stdout.expected
224 cmp -s $testroot/stdout.expected $testroot/stdout
225 ret="$?"
226 if [ "$ret" != "0" ]; then
227 diff -u $testroot/stdout.expected $testroot/stdout
228 test_done "$testroot" "$ret"
229 return 1
230 fi
232 (cd $testroot/wt && got add tree2/foo > $testroot/stdout)
234 echo 'A tree2/foo' > $testroot/stdout.expected
236 cmp -s $testroot/stdout.expected $testroot/stdout
237 ret="$?"
238 if [ "$ret" != "0" ]; then
239 diff -u $testroot/stdout.expected $testroot/stdout
240 test_done "$testroot" "$ret"
241 return 1
242 fi
243 test_done "$testroot" "$ret"
246 run_test test_add_basic
247 run_test test_double_add
248 run_test test_add_multiple
249 run_test test_add_file_in_new_subdir
250 run_test test_add_deleted
251 run_test test_add_directory