Blame


1 35dc4510 2019-02-04 stsp #!/bin/sh
2 35dc4510 2019-02-04 stsp #
3 35dc4510 2019-02-04 stsp # Copyright (c) 2019 Stefan Sperling <stsp@openbsd.org>
4 35dc4510 2019-02-04 stsp #
5 35dc4510 2019-02-04 stsp # Permission to use, copy, modify, and distribute this software for any
6 35dc4510 2019-02-04 stsp # purpose with or without fee is hereby granted, provided that the above
7 35dc4510 2019-02-04 stsp # copyright notice and this permission notice appear in all copies.
8 35dc4510 2019-02-04 stsp #
9 35dc4510 2019-02-04 stsp # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 35dc4510 2019-02-04 stsp # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 35dc4510 2019-02-04 stsp # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 35dc4510 2019-02-04 stsp # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 35dc4510 2019-02-04 stsp # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 35dc4510 2019-02-04 stsp # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 35dc4510 2019-02-04 stsp # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 35dc4510 2019-02-04 stsp
17 35dc4510 2019-02-04 stsp . ./common.sh
18 35dc4510 2019-02-04 stsp
19 35dc4510 2019-02-04 stsp function test_status_basic {
20 35dc4510 2019-02-04 stsp local testroot=`test_init status_basic`
21 35dc4510 2019-02-04 stsp
22 35dc4510 2019-02-04 stsp got checkout $testroot/repo $testroot/wt > /dev/null
23 e60e7f5b 2019-02-10 stsp ret="$?"
24 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
25 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
26 35dc4510 2019-02-04 stsp return 1
27 35dc4510 2019-02-04 stsp fi
28 35dc4510 2019-02-04 stsp
29 35dc4510 2019-02-04 stsp echo "modified alpha" > $testroot/wt/alpha
30 35dc4510 2019-02-04 stsp echo "unversioned file" > $testroot/wt/foo
31 35dc4510 2019-02-04 stsp rm $testroot/wt/epsilon/zeta
32 14e5d4dc 2019-02-05 stsp touch $testroot/wt/beta
33 35dc4510 2019-02-04 stsp
34 35dc4510 2019-02-04 stsp echo 'M alpha' > $testroot/stdout.expected
35 35dc4510 2019-02-04 stsp echo '! epsilon/zeta' >> $testroot/stdout.expected
36 35dc4510 2019-02-04 stsp echo '? foo' >> $testroot/stdout.expected
37 35dc4510 2019-02-04 stsp
38 35dc4510 2019-02-04 stsp (cd $testroot/wt && got status > $testroot/stdout)
39 35dc4510 2019-02-04 stsp
40 35dc4510 2019-02-04 stsp cmp $testroot/stdout.expected $testroot/stdout
41 e60e7f5b 2019-02-10 stsp ret="$?"
42 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
43 35dc4510 2019-02-04 stsp diff -u $testroot/stdout.expected $testroot/stdout
44 35dc4510 2019-02-04 stsp fi
45 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
46 35dc4510 2019-02-04 stsp }
47 35dc4510 2019-02-04 stsp
48 f02ba292 2019-02-05 stsp function test_status_subdir_no_mods {
49 f02ba292 2019-02-05 stsp local testroot=`test_init status_subdir_no_mods 1`
50 f02ba292 2019-02-05 stsp
51 f02ba292 2019-02-05 stsp mkdir $testroot/repo/Basic/
52 f02ba292 2019-02-05 stsp mkdir $testroot/repo/Basic/Targets/
53 f02ba292 2019-02-05 stsp touch $testroot/repo/Basic/Targets/AArch64.cpp
54 f02ba292 2019-02-05 stsp touch $testroot/repo/Basic/Targets.cpp
55 f02ba292 2019-02-05 stsp touch $testroot/repo/Basic/Targets.h
56 f02ba292 2019-02-05 stsp (cd $testroot/repo && git add .)
57 f02ba292 2019-02-05 stsp git_commit $testroot/repo -m "add subdir with files"
58 f02ba292 2019-02-05 stsp
59 f02ba292 2019-02-05 stsp got checkout $testroot/repo $testroot/wt > /dev/null
60 e60e7f5b 2019-02-10 stsp ret="$?"
61 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
62 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
63 f02ba292 2019-02-05 stsp return 1
64 f02ba292 2019-02-05 stsp fi
65 f02ba292 2019-02-05 stsp
66 f02ba292 2019-02-05 stsp touch $testroot/stdout.expected
67 f02ba292 2019-02-05 stsp
68 f02ba292 2019-02-05 stsp # This used to erroneously print:
69 f02ba292 2019-02-05 stsp #
70 f02ba292 2019-02-05 stsp # ! Basic/Targets.cpp
71 f02ba292 2019-02-05 stsp # ? Basic/Targets.cpp
72 f02ba292 2019-02-05 stsp (cd $testroot/wt && got status > $testroot/stdout)
73 f02ba292 2019-02-05 stsp
74 f02ba292 2019-02-05 stsp cmp $testroot/stdout.expected $testroot/stdout
75 e60e7f5b 2019-02-10 stsp ret="$?"
76 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
77 f02ba292 2019-02-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
78 f02ba292 2019-02-05 stsp fi
79 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
80 f02ba292 2019-02-05 stsp }
81 f02ba292 2019-02-05 stsp
82 f02ba292 2019-02-05 stsp function test_status_subdir_no_mods2 {
83 f02ba292 2019-02-05 stsp local testroot=`test_init status_subdir_no_mods2 1`
84 f02ba292 2019-02-05 stsp
85 f02ba292 2019-02-05 stsp mkdir $testroot/repo/AST
86 f02ba292 2019-02-05 stsp touch $testroot/repo/AST/APValue.cpp
87 f02ba292 2019-02-05 stsp mkdir $testroot/repo/ASTMatchers
88 f02ba292 2019-02-05 stsp touch $testroot/repo/ASTMatchers/ASTMatchFinder.cpp
89 f02ba292 2019-02-05 stsp mkdir $testroot/repo/Frontend
90 f02ba292 2019-02-05 stsp touch $testroot/repo/Frontend/ASTConsumers.cpp
91 f02ba292 2019-02-05 stsp mkdir $testroot/repo/Frontend/Rewrite
92 f02ba292 2019-02-05 stsp touch $testroot/repo/Frontend/Rewrite/CMakeLists.txt
93 f02ba292 2019-02-05 stsp mkdir $testroot/repo/FrontendTool
94 f02ba292 2019-02-05 stsp touch $testroot/repo/FrontendTool/CMakeLists.txt
95 f02ba292 2019-02-05 stsp touch $testroot/repo/FrontendTool/ExecuteCompilerInvocation.cpp
96 f02ba292 2019-02-05 stsp (cd $testroot/repo && git add .)
97 f02ba292 2019-02-05 stsp git_commit $testroot/repo -m "add subdir with files"
98 f02ba292 2019-02-05 stsp
99 f02ba292 2019-02-05 stsp got checkout $testroot/repo $testroot/wt > /dev/null
100 e60e7f5b 2019-02-10 stsp ret="$?"
101 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
102 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
103 f02ba292 2019-02-05 stsp return 1
104 f02ba292 2019-02-05 stsp fi
105 f02ba292 2019-02-05 stsp
106 f02ba292 2019-02-05 stsp touch $testroot/stdout.expected
107 f02ba292 2019-02-05 stsp
108 f02ba292 2019-02-05 stsp # This used to erroneously print:
109 f02ba292 2019-02-05 stsp #
110 f02ba292 2019-02-05 stsp # ! AST/APValue.cpp
111 f02ba292 2019-02-05 stsp # ? AST/APValue.cpp
112 f02ba292 2019-02-05 stsp # ! Frontend/ASTConsumers.cpp
113 f02ba292 2019-02-05 stsp # ! Frontend/Rewrite/CMakeLists.txt
114 f02ba292 2019-02-05 stsp # ? Frontend/ASTConsumers.cpp
115 f02ba292 2019-02-05 stsp # ? Frontend/Rewrite/CMakeLists.txt
116 f02ba292 2019-02-05 stsp (cd $testroot/wt && got status > $testroot/stdout)
117 f02ba292 2019-02-05 stsp
118 f02ba292 2019-02-05 stsp cmp $testroot/stdout.expected $testroot/stdout
119 e60e7f5b 2019-02-10 stsp ret="$?"
120 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
121 f02ba292 2019-02-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
122 f02ba292 2019-02-05 stsp fi
123 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
124 f02ba292 2019-02-05 stsp }
125 f02ba292 2019-02-05 stsp
126 0dbc2271 2019-02-05 stsp function test_status_obstructed {
127 0dbc2271 2019-02-05 stsp local testroot=`test_init status_obstructed`
128 0dbc2271 2019-02-05 stsp
129 0dbc2271 2019-02-05 stsp got checkout $testroot/repo $testroot/wt > /dev/null
130 e60e7f5b 2019-02-10 stsp ret="$?"
131 e60e7f5b 2019-02-10 stsp if [ "$ret" != "0" ]; then
132 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
133 0dbc2271 2019-02-05 stsp return 1
134 0dbc2271 2019-02-05 stsp fi
135 0dbc2271 2019-02-05 stsp
136 0dbc2271 2019-02-05 stsp rm $testroot/wt/epsilon/zeta
137 0dbc2271 2019-02-05 stsp mkdir $testroot/wt/epsilon/zeta
138 0dbc2271 2019-02-05 stsp
139 0dbc2271 2019-02-05 stsp echo '~ epsilon/zeta' > $testroot/stdout.expected
140 0dbc2271 2019-02-05 stsp
141 0dbc2271 2019-02-05 stsp (cd $testroot/wt && got status > $testroot/stdout)
142 0dbc2271 2019-02-05 stsp
143 0dbc2271 2019-02-05 stsp cmp $testroot/stdout.expected $testroot/stdout
144 e60e7f5b 2019-02-10 stsp ret="$?"
145 0dbc2271 2019-02-05 stsp if [ "$?" != "0" ]; then
146 0dbc2271 2019-02-05 stsp diff -u $testroot/stdout.expected $testroot/stdout
147 0dbc2271 2019-02-05 stsp fi
148 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
149 0dbc2271 2019-02-05 stsp }
150 0dbc2271 2019-02-05 stsp
151 02c07007 2019-02-10 stsp function test_status_shows_local_mods_after_update {
152 02c07007 2019-02-10 stsp local testroot=`test_init status_shows_local_mods_after_update 1`
153 02c07007 2019-02-10 stsp
154 02c07007 2019-02-10 stsp echo "1" > $testroot/repo/numbers
155 02c07007 2019-02-10 stsp echo "2" >> $testroot/repo/numbers
156 02c07007 2019-02-10 stsp echo "3" >> $testroot/repo/numbers
157 02c07007 2019-02-10 stsp echo "4" >> $testroot/repo/numbers
158 02c07007 2019-02-10 stsp echo "5" >> $testroot/repo/numbers
159 02c07007 2019-02-10 stsp echo "6" >> $testroot/repo/numbers
160 02c07007 2019-02-10 stsp echo "7" >> $testroot/repo/numbers
161 02c07007 2019-02-10 stsp echo "8" >> $testroot/repo/numbers
162 02c07007 2019-02-10 stsp (cd $testroot/repo && git add numbers)
163 02c07007 2019-02-10 stsp git_commit $testroot/repo -m "added numbers file"
164 02c07007 2019-02-10 stsp
165 02c07007 2019-02-10 stsp got checkout $testroot/repo $testroot/wt > /dev/null
166 02c07007 2019-02-10 stsp ret="$?"
167 02c07007 2019-02-10 stsp if [ "$ret" != "0" ]; then
168 02c07007 2019-02-10 stsp test_done "$testroot" "$ret"
169 02c07007 2019-02-10 stsp return 1
170 02c07007 2019-02-10 stsp fi
171 02c07007 2019-02-10 stsp
172 02c07007 2019-02-10 stsp sed -i 's/2/22/' $testroot/repo/numbers
173 02c07007 2019-02-10 stsp git_commit $testroot/repo -m "modified line 2"
174 02c07007 2019-02-10 stsp
175 02c07007 2019-02-10 stsp # modify line 7; both changes should merge cleanly
176 02c07007 2019-02-10 stsp sed -i 's/7/77/' $testroot/wt/numbers
177 02c07007 2019-02-10 stsp
178 02c07007 2019-02-10 stsp echo "G numbers" > $testroot/stdout.expected
179 02c07007 2019-02-10 stsp echo -n "Updated to commit " >> $testroot/stdout.expected
180 02c07007 2019-02-10 stsp git_show_head $testroot/repo >> $testroot/stdout.expected
181 02c07007 2019-02-10 stsp echo >> $testroot/stdout.expected
182 02c07007 2019-02-10 stsp
183 02c07007 2019-02-10 stsp (cd $testroot/wt && got update > $testroot/stdout)
184 02c07007 2019-02-10 stsp
185 02c07007 2019-02-10 stsp cmp $testroot/stdout.expected $testroot/stdout
186 02c07007 2019-02-10 stsp ret="$?"
187 02c07007 2019-02-10 stsp if [ "$ret" != "0" ]; then
188 02c07007 2019-02-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
189 02c07007 2019-02-10 stsp test_done "$testroot" "$ret"
190 02c07007 2019-02-10 stsp return 1
191 02c07007 2019-02-10 stsp fi
192 02c07007 2019-02-10 stsp
193 02c07007 2019-02-10 stsp echo 'M numbers' > $testroot/stdout.expected
194 02c07007 2019-02-10 stsp
195 02c07007 2019-02-10 stsp (cd $testroot/wt && got status > $testroot/stdout)
196 02c07007 2019-02-10 stsp
197 02c07007 2019-02-10 stsp cmp $testroot/stdout.expected $testroot/stdout
198 02c07007 2019-02-10 stsp ret="$?"
199 02c07007 2019-02-10 stsp if [ "$ret" != "0" ]; then
200 02c07007 2019-02-10 stsp diff -u $testroot/stdout.expected $testroot/stdout
201 02c07007 2019-02-10 stsp fi
202 e60e7f5b 2019-02-10 stsp test_done "$testroot" "$ret"
203 02c07007 2019-02-10 stsp }
204 02c07007 2019-02-10 stsp
205 35dc4510 2019-02-04 stsp run_test test_status_basic
206 f02ba292 2019-02-05 stsp run_test test_status_subdir_no_mods
207 f02ba292 2019-02-05 stsp run_test test_status_subdir_no_mods2
208 0dbc2271 2019-02-05 stsp run_test test_status_obstructed
209 02c07007 2019-02-10 stsp run_test test_status_shows_local_mods_after_update