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_status_basic {
20 local testroot=`test_init status_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 "modified alpha" > $testroot/wt/alpha
30 echo "unversioned file" > $testroot/wt/foo
31 rm $testroot/wt/epsilon/zeta
32 touch $testroot/wt/beta
33 echo "new file" > $testroot/wt/new
34 (cd $testroot/wt && got add new >/dev/null)
36 echo 'M alpha' > $testroot/stdout.expected
37 echo '! epsilon/zeta' >> $testroot/stdout.expected
38 echo '? foo' >> $testroot/stdout.expected
39 echo 'A new' >> $testroot/stdout.expected
41 (cd $testroot/wt && got status > $testroot/stdout)
43 cmp $testroot/stdout.expected $testroot/stdout
44 ret="$?"
45 if [ "$ret" != "0" ]; then
46 diff -u $testroot/stdout.expected $testroot/stdout
47 fi
48 test_done "$testroot" "$ret"
49 }
51 function test_status_subdir_no_mods {
52 local testroot=`test_init status_subdir_no_mods 1`
54 mkdir $testroot/repo/Basic/
55 mkdir $testroot/repo/Basic/Targets/
56 touch $testroot/repo/Basic/Targets/AArch64.cpp
57 touch $testroot/repo/Basic/Targets.cpp
58 touch $testroot/repo/Basic/Targets.h
59 (cd $testroot/repo && git add .)
60 git_commit $testroot/repo -m "add subdir with files"
62 got checkout $testroot/repo $testroot/wt > /dev/null
63 ret="$?"
64 if [ "$ret" != "0" ]; then
65 test_done "$testroot" "$ret"
66 return 1
67 fi
69 touch $testroot/stdout.expected
71 # This used to erroneously print:
72 #
73 # ! Basic/Targets.cpp
74 # ? Basic/Targets.cpp
75 (cd $testroot/wt && got status > $testroot/stdout)
77 cmp $testroot/stdout.expected $testroot/stdout
78 ret="$?"
79 if [ "$ret" != "0" ]; then
80 diff -u $testroot/stdout.expected $testroot/stdout
81 fi
82 test_done "$testroot" "$ret"
83 }
85 function test_status_subdir_no_mods2 {
86 local testroot=`test_init status_subdir_no_mods2 1`
88 mkdir $testroot/repo/AST
89 touch $testroot/repo/AST/APValue.cpp
90 mkdir $testroot/repo/ASTMatchers
91 touch $testroot/repo/ASTMatchers/ASTMatchFinder.cpp
92 mkdir $testroot/repo/Frontend
93 touch $testroot/repo/Frontend/ASTConsumers.cpp
94 mkdir $testroot/repo/Frontend/Rewrite
95 touch $testroot/repo/Frontend/Rewrite/CMakeLists.txt
96 mkdir $testroot/repo/FrontendTool
97 touch $testroot/repo/FrontendTool/CMakeLists.txt
98 touch $testroot/repo/FrontendTool/ExecuteCompilerInvocation.cpp
99 (cd $testroot/repo && git add .)
100 git_commit $testroot/repo -m "add subdir with files"
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 touch $testroot/stdout.expected
111 # This used to erroneously print:
113 # ! AST/APValue.cpp
114 # ? AST/APValue.cpp
115 # ! Frontend/ASTConsumers.cpp
116 # ! Frontend/Rewrite/CMakeLists.txt
117 # ? Frontend/ASTConsumers.cpp
118 # ? Frontend/Rewrite/CMakeLists.txt
119 (cd $testroot/wt && got status > $testroot/stdout)
121 cmp $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_status_obstructed {
130 local testroot=`test_init status_obstructed`
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 rm $testroot/wt/epsilon/zeta
140 mkdir $testroot/wt/epsilon/zeta
142 echo '~ epsilon/zeta' > $testroot/stdout.expected
144 (cd $testroot/wt && got status > $testroot/stdout)
146 cmp $testroot/stdout.expected $testroot/stdout
147 ret="$?"
148 if [ "$?" != "0" ]; then
149 diff -u $testroot/stdout.expected $testroot/stdout
150 fi
151 test_done "$testroot" "$ret"
154 function test_status_shows_local_mods_after_update {
155 local testroot=`test_init status_shows_local_mods_after_update 1`
157 echo "1" > $testroot/repo/numbers
158 echo "2" >> $testroot/repo/numbers
159 echo "3" >> $testroot/repo/numbers
160 echo "4" >> $testroot/repo/numbers
161 echo "5" >> $testroot/repo/numbers
162 echo "6" >> $testroot/repo/numbers
163 echo "7" >> $testroot/repo/numbers
164 echo "8" >> $testroot/repo/numbers
165 (cd $testroot/repo && git add numbers)
166 git_commit $testroot/repo -m "added numbers file"
168 got checkout $testroot/repo $testroot/wt > /dev/null
169 ret="$?"
170 if [ "$ret" != "0" ]; then
171 test_done "$testroot" "$ret"
172 return 1
173 fi
175 sed -i 's/2/22/' $testroot/repo/numbers
176 git_commit $testroot/repo -m "modified line 2"
178 # modify line 7; both changes should merge cleanly
179 sed -i 's/7/77/' $testroot/wt/numbers
181 echo "G numbers" > $testroot/stdout.expected
182 echo -n "Updated to commit " >> $testroot/stdout.expected
183 git_show_head $testroot/repo >> $testroot/stdout.expected
184 echo >> $testroot/stdout.expected
186 (cd $testroot/wt && got update > $testroot/stdout)
188 cmp $testroot/stdout.expected $testroot/stdout
189 ret="$?"
190 if [ "$ret" != "0" ]; then
191 diff -u $testroot/stdout.expected $testroot/stdout
192 test_done "$testroot" "$ret"
193 return 1
194 fi
196 echo 'M numbers' > $testroot/stdout.expected
198 (cd $testroot/wt && got status > $testroot/stdout)
200 cmp $testroot/stdout.expected $testroot/stdout
201 ret="$?"
202 if [ "$ret" != "0" ]; then
203 diff -u $testroot/stdout.expected $testroot/stdout
204 fi
205 test_done "$testroot" "$ret"
208 function test_status_unversioned_subdirs {
209 local testroot=`test_init status_unversioned_subdirs 1`
211 mkdir $testroot/repo/cdfs/
212 touch $testroot/repo/cdfs/Makefile
213 mkdir $testroot/repo/common/
214 touch $testroot/repo/common/Makefile
215 mkdir $testroot/repo/iso/
216 touch $testroot/repo/iso/Makefile
217 mkdir $testroot/repo/ramdisk/
218 touch $testroot/repo/ramdisk/Makefile
219 touch $testroot/repo/ramdisk/list.local
220 mkdir $testroot/repo/ramdisk_cd/
221 touch $testroot/repo/ramdisk_cd/Makefile
222 touch $testroot/repo/ramdisk_cd/list.local
223 (cd $testroot/repo && git add .)
224 git_commit $testroot/repo -m "first commit"
226 got checkout $testroot/repo $testroot/wt > /dev/null
227 ret="$?"
228 if [ "$ret" != "0" ]; then
229 test_done "$testroot" "$ret"
230 return 1
231 fi
233 mkdir $testroot/wt/cdfs/obj
234 mkdir $testroot/wt/ramdisk/obj
235 mkdir $testroot/wt/ramdisk_cd/obj
236 mkdir $testroot/wt/iso/obj
238 echo -n > $testroot/stdout.expected
240 # This used to erroneously print:
242 # ! ramdisk_cd/Makefile
243 # ! ramdisk_cd/list.local
244 # ? ramdisk_cd/Makefile
245 # ? ramdisk_cd/list.local
246 (cd $testroot/wt && got status > $testroot/stdout)
248 cmp $testroot/stdout.expected $testroot/stdout
249 ret="$?"
250 if [ "$ret" != "0" ]; then
251 diff -u $testroot/stdout.expected $testroot/stdout
252 fi
253 test_done "$testroot" "$ret"
256 # 'got status' ignores symlinks at present; this might change eventually
257 function test_status_ignores_symlink {
258 local testroot=`test_init status_ignores_symlink 1`
260 mkdir $testroot/repo/ramdisk/
261 touch $testroot/repo/ramdisk/Makefile
262 (cd $testroot/repo && git add .)
263 git_commit $testroot/repo -m "first commit"
265 got checkout $testroot/repo $testroot/wt > /dev/null
266 ret="$?"
267 if [ "$ret" != "0" ]; then
268 test_done "$testroot" "$ret"
269 return 1
270 fi
272 ln -s /usr/obj/distrib/i386/ramdisk $testroot/wt/ramdisk/obj
274 echo -n > $testroot/stdout.expected
276 (cd $testroot/wt && got status > $testroot/stdout)
278 cmp $testroot/stdout.expected $testroot/stdout
279 ret="$?"
280 if [ "$ret" != "0" ]; then
281 diff -u $testroot/stdout.expected $testroot/stdout
282 fi
283 test_done "$testroot" "$ret"
286 function test_status_shows_no_mods_after_complete_merge {
287 local testroot=`test_init status_shows_no_mods_after_complete_merge 1`
289 # make this file larger than the usual blob buffer size of 8192
290 echo -n > $testroot/repo/numbers
291 for i in `jot 16384`; do
292 echo "$i" >> $testroot/repo/numbers
293 done
295 (cd $testroot/repo && git add numbers)
296 git_commit $testroot/repo -m "added numbers file"
298 got checkout $testroot/repo $testroot/wt > /dev/null
299 ret="$?"
300 if [ "$ret" != "0" ]; then
301 test_done "$testroot" "$ret"
302 return 1
303 fi
305 sed -i 's/2/22/' $testroot/repo/numbers
306 git_commit $testroot/repo -m "modified line 2"
308 sleep 1
309 # modify line 2 again; no local changes are left after merge
310 sed -i 's/2/22/' $testroot/wt/numbers
312 echo "G numbers" > $testroot/stdout.expected
313 echo -n "Updated to commit " >> $testroot/stdout.expected
314 git_show_head $testroot/repo >> $testroot/stdout.expected
315 echo >> $testroot/stdout.expected
317 (cd $testroot/wt && got update > $testroot/stdout)
319 cmp $testroot/stdout.expected $testroot/stdout
320 ret="$?"
321 if [ "$ret" != "0" ]; then
322 diff -u $testroot/stdout.expected $testroot/stdout
323 test_done "$testroot" "$ret"
324 return 1
325 fi
327 echo -n > $testroot/stdout.expected
329 (cd $testroot/wt && got status > $testroot/stdout)
331 cmp $testroot/stdout.expected $testroot/stdout
332 ret="$?"
333 if [ "$ret" != "0" ]; then
334 diff -u $testroot/stdout.expected $testroot/stdout
335 fi
336 test_done "$testroot" "$ret"
339 run_test test_status_basic
340 run_test test_status_subdir_no_mods
341 run_test test_status_subdir_no_mods2
342 run_test test_status_obstructed
343 run_test test_status_shows_local_mods_after_update
344 run_test test_status_unversioned_subdirs
345 run_test test_status_ignores_symlink
346 run_test test_status_shows_no_mods_after_complete_merge