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
34 echo 'M alpha' > $testroot/stdout.expected
35 echo '! epsilon/zeta' >> $testroot/stdout.expected
36 echo '? foo' >> $testroot/stdout.expected
38 (cd $testroot/wt && got status > $testroot/stdout)
40 cmp $testroot/stdout.expected $testroot/stdout
41 ret="$?"
42 if [ "$ret" != "0" ]; then
43 diff -u $testroot/stdout.expected $testroot/stdout
44 fi
45 test_done "$testroot" "$ret"
46 }
48 function test_status_subdir_no_mods {
49 local testroot=`test_init status_subdir_no_mods 1`
51 mkdir $testroot/repo/Basic/
52 mkdir $testroot/repo/Basic/Targets/
53 touch $testroot/repo/Basic/Targets/AArch64.cpp
54 touch $testroot/repo/Basic/Targets.cpp
55 touch $testroot/repo/Basic/Targets.h
56 (cd $testroot/repo && git add .)
57 git_commit $testroot/repo -m "add subdir with files"
59 got checkout $testroot/repo $testroot/wt > /dev/null
60 ret="$?"
61 if [ "$ret" != "0" ]; then
62 test_done "$testroot" "$ret"
63 return 1
64 fi
66 touch $testroot/stdout.expected
68 # This used to erroneously print:
69 #
70 # ! Basic/Targets.cpp
71 # ? Basic/Targets.cpp
72 (cd $testroot/wt && got status > $testroot/stdout)
74 cmp $testroot/stdout.expected $testroot/stdout
75 ret="$?"
76 if [ "$ret" != "0" ]; then
77 diff -u $testroot/stdout.expected $testroot/stdout
78 fi
79 test_done "$testroot" "$ret"
80 }
82 function test_status_subdir_no_mods2 {
83 local testroot=`test_init status_subdir_no_mods2 1`
85 mkdir $testroot/repo/AST
86 touch $testroot/repo/AST/APValue.cpp
87 mkdir $testroot/repo/ASTMatchers
88 touch $testroot/repo/ASTMatchers/ASTMatchFinder.cpp
89 mkdir $testroot/repo/Frontend
90 touch $testroot/repo/Frontend/ASTConsumers.cpp
91 mkdir $testroot/repo/Frontend/Rewrite
92 touch $testroot/repo/Frontend/Rewrite/CMakeLists.txt
93 mkdir $testroot/repo/FrontendTool
94 touch $testroot/repo/FrontendTool/CMakeLists.txt
95 touch $testroot/repo/FrontendTool/ExecuteCompilerInvocation.cpp
96 (cd $testroot/repo && git add .)
97 git_commit $testroot/repo -m "add subdir with files"
99 got checkout $testroot/repo $testroot/wt > /dev/null
100 ret="$?"
101 if [ "$ret" != "0" ]; then
102 test_done "$testroot" "$ret"
103 return 1
104 fi
106 touch $testroot/stdout.expected
108 # This used to erroneously print:
110 # ! AST/APValue.cpp
111 # ? AST/APValue.cpp
112 # ! Frontend/ASTConsumers.cpp
113 # ! Frontend/Rewrite/CMakeLists.txt
114 # ? Frontend/ASTConsumers.cpp
115 # ? Frontend/Rewrite/CMakeLists.txt
116 (cd $testroot/wt && got status > $testroot/stdout)
118 cmp $testroot/stdout.expected $testroot/stdout
119 ret="$?"
120 if [ "$ret" != "0" ]; then
121 diff -u $testroot/stdout.expected $testroot/stdout
122 fi
123 test_done "$testroot" "$ret"
126 function test_status_obstructed {
127 local testroot=`test_init status_obstructed`
129 got checkout $testroot/repo $testroot/wt > /dev/null
130 ret="$?"
131 if [ "$ret" != "0" ]; then
132 test_done "$testroot" "$ret"
133 return 1
134 fi
136 rm $testroot/wt/epsilon/zeta
137 mkdir $testroot/wt/epsilon/zeta
139 echo '~ epsilon/zeta' > $testroot/stdout.expected
141 (cd $testroot/wt && got status > $testroot/stdout)
143 cmp $testroot/stdout.expected $testroot/stdout
144 ret="$?"
145 if [ "$?" != "0" ]; then
146 diff -u $testroot/stdout.expected $testroot/stdout
147 fi
148 test_done "$testroot" "$ret"
151 function test_status_shows_local_mods_after_update {
152 local testroot=`test_init status_shows_local_mods_after_update 1`
154 echo "1" > $testroot/repo/numbers
155 echo "2" >> $testroot/repo/numbers
156 echo "3" >> $testroot/repo/numbers
157 echo "4" >> $testroot/repo/numbers
158 echo "5" >> $testroot/repo/numbers
159 echo "6" >> $testroot/repo/numbers
160 echo "7" >> $testroot/repo/numbers
161 echo "8" >> $testroot/repo/numbers
162 (cd $testroot/repo && git add numbers)
163 git_commit $testroot/repo -m "added numbers file"
165 got checkout $testroot/repo $testroot/wt > /dev/null
166 ret="$?"
167 if [ "$ret" != "0" ]; then
168 test_done "$testroot" "$ret"
169 return 1
170 fi
172 sed -i 's/2/22/' $testroot/repo/numbers
173 git_commit $testroot/repo -m "modified line 2"
175 # modify line 7; both changes should merge cleanly
176 sed -i 's/7/77/' $testroot/wt/numbers
178 echo "G numbers" > $testroot/stdout.expected
179 echo -n "Updated to commit " >> $testroot/stdout.expected
180 git_show_head $testroot/repo >> $testroot/stdout.expected
181 echo >> $testroot/stdout.expected
183 (cd $testroot/wt && got update > $testroot/stdout)
185 cmp $testroot/stdout.expected $testroot/stdout
186 ret="$?"
187 if [ "$ret" != "0" ]; then
188 diff -u $testroot/stdout.expected $testroot/stdout
189 test_done "$testroot" "$ret"
190 return 1
191 fi
193 echo 'M numbers' > $testroot/stdout.expected
195 (cd $testroot/wt && got status > $testroot/stdout)
197 cmp $testroot/stdout.expected $testroot/stdout
198 ret="$?"
199 if [ "$ret" != "0" ]; then
200 diff -u $testroot/stdout.expected $testroot/stdout
201 fi
202 test_done "$testroot" "$ret"
205 function test_status_unversioned_subdirs {
206 local testroot=`test_init status_unversioned_subdirs 1`
208 mkdir $testroot/repo/cdfs/
209 touch $testroot/repo/cdfs/Makefile
210 mkdir $testroot/repo/common/
211 touch $testroot/repo/common/Makefile
212 mkdir $testroot/repo/iso/
213 touch $testroot/repo/iso/Makefile
214 mkdir $testroot/repo/ramdisk/
215 touch $testroot/repo/ramdisk/Makefile
216 touch $testroot/repo/ramdisk/list.local
217 mkdir $testroot/repo/ramdisk_cd/
218 touch $testroot/repo/ramdisk_cd/Makefile
219 touch $testroot/repo/ramdisk_cd/list.local
220 (cd $testroot/repo && git add .)
221 git_commit $testroot/repo -m "first commit"
223 got checkout $testroot/repo $testroot/wt > /dev/null
224 ret="$?"
225 if [ "$ret" != "0" ]; then
226 test_done "$testroot" "$ret"
227 return 1
228 fi
230 mkdir $testroot/wt/cdfs/obj
231 mkdir $testroot/wt/ramdisk/obj
232 mkdir $testroot/wt/ramdisk_cd/obj
233 mkdir $testroot/wt/iso/obj
235 echo -n > $testroot/stdout.expected
237 # This used to erroneously print:
239 # ! ramdisk_cd/Makefile
240 # ! ramdisk_cd/list.local
241 # ? ramdisk_cd/Makefile
242 # ? ramdisk_cd/list.local
243 (cd $testroot/wt && got status > $testroot/stdout)
245 cmp $testroot/stdout.expected $testroot/stdout
246 ret="$?"
247 if [ "$ret" != "0" ]; then
248 diff -u $testroot/stdout.expected $testroot/stdout
249 fi
250 test_done "$testroot" "$ret"
253 # 'got status' ignores symlinks at present; this might change eventually
254 function test_status_ignores_symlink {
255 local testroot=`test_init status_ignores_symlink 1`
257 mkdir $testroot/repo/ramdisk/
258 touch $testroot/repo/ramdisk/Makefile
259 (cd $testroot/repo && git add .)
260 git_commit $testroot/repo -m "first commit"
262 got checkout $testroot/repo $testroot/wt > /dev/null
263 ret="$?"
264 if [ "$ret" != "0" ]; then
265 test_done "$testroot" "$ret"
266 return 1
267 fi
269 ln -s /usr/obj/distrib/i386/ramdisk $testroot/wt/ramdisk/obj
271 echo -n > $testroot/stdout.expected
273 (cd $testroot/wt && got status > $testroot/stdout)
275 cmp $testroot/stdout.expected $testroot/stdout
276 ret="$?"
277 if [ "$ret" != "0" ]; then
278 diff -u $testroot/stdout.expected $testroot/stdout
279 fi
280 test_done "$testroot" "$ret"
283 function test_status_shows_no_mods_after_complete_merge {
284 local testroot=`test_init status_shows_no_mods_after_complete_merge 1`
286 # make this file larger than the usual blob buffer size of 8192
287 echo -n > $testroot/repo/numbers
288 for i in `jot 16384`; do
289 echo "$i" >> $testroot/repo/numbers
290 done
292 (cd $testroot/repo && git add numbers)
293 git_commit $testroot/repo -m "added numbers file"
295 got checkout $testroot/repo $testroot/wt > /dev/null
296 ret="$?"
297 if [ "$ret" != "0" ]; then
298 test_done "$testroot" "$ret"
299 return 1
300 fi
302 sed -i 's/2/22/' $testroot/repo/numbers
303 git_commit $testroot/repo -m "modified line 2"
305 sleep 1
306 # modify line 2 again; no local changes are left after merge
307 sed -i 's/2/22/' $testroot/wt/numbers
309 echo "G numbers" > $testroot/stdout.expected
310 echo -n "Updated to commit " >> $testroot/stdout.expected
311 git_show_head $testroot/repo >> $testroot/stdout.expected
312 echo >> $testroot/stdout.expected
314 (cd $testroot/wt && got update > $testroot/stdout)
316 cmp $testroot/stdout.expected $testroot/stdout
317 ret="$?"
318 if [ "$ret" != "0" ]; then
319 diff -u $testroot/stdout.expected $testroot/stdout
320 test_done "$testroot" "$ret"
321 return 1
322 fi
324 echo -n > $testroot/stdout.expected
326 (cd $testroot/wt && got status > $testroot/stdout)
328 cmp $testroot/stdout.expected $testroot/stdout
329 ret="$?"
330 if [ "$ret" != "0" ]; then
331 diff -u $testroot/stdout.expected $testroot/stdout
332 fi
333 test_done "$testroot" "$ret"
336 run_test test_status_basic
337 run_test test_status_subdir_no_mods
338 run_test test_status_subdir_no_mods2
339 run_test test_status_obstructed
340 run_test test_status_shows_local_mods_after_update
341 run_test test_status_unversioned_subdirs
342 run_test test_status_ignores_symlink
343 run_test test_status_shows_no_mods_after_complete_merge