]> git.proxmox.com Git - mirror_ovs.git/blob - tests/checkpatch.at
checkpatch: Normalize exit code for Windows
[mirror_ovs.git] / tests / checkpatch.at
1 AT_BANNER([checkpatch])
2
3 OVS_START_SHELL_HELPERS
4 # try_checkpatch PATCH [ERRORS]
5 #
6 # Runs checkpatch under Python 2 and Python 3, if installed, on the given
7 # PATCH, expecting the specified set of ERRORS (and warnings).
8 try_checkpatch() {
9 AT_SKIP_IF([test $HAVE_PYTHON2 = no && test $HAVE_PYTHON3 = no])
10 # Take the patch to test from $1. Remove an initial four-space indent
11 # from it and, if it is just headers with no body, add a null body.
12 echo "$1" | sed 's/^ //' > test.patch
13 if grep '---' expout >/dev/null 2>&1; then :
14 else
15 printf '\n---\n' >> test.patch
16 fi
17
18 # Take expected output from $2.
19 if test -n "$2"; then
20 echo "$2" | sed 's/^ //' > expout
21 else
22 : > expout
23 fi
24
25 try_checkpatch__ "$HAVE_PYTHON2" "$PYTHON2"
26 try_checkpatch__ "$HAVE_PYTHON3" "$PYTHON3"
27 }
28 try_checkpatch__() {
29 if test $1 = no; then
30 :
31 elif test -s expout; then
32 AT_CHECK([$2 $top_srcdir/utilities/checkpatch.py -q test.patch],
33 [1], [stdout])
34 AT_CHECK([sed '/^Lines checked:/,$d' stdout], [0], [expout])
35 else
36 AT_CHECK([$2 $top_srcdir/utilities/checkpatch.py -q test.patch])
37 fi
38 }
39 OVS_END_SHELL_HELPERS
40
41 AT_SETUP([checkpatch - sign-offs])
42
43 # Sign-off for single author who is also the committer.
44 try_checkpatch \
45 "Author: A
46 Commit: A
47
48 Signed-off-by: A"
49 try_checkpatch \
50 "Author: A
51 Commit: A" \
52 "ERROR: Author A needs to sign off."
53
54 # Single author but somehow the mailing list is the author.
55 try_checkpatch \
56 "Author: Foo Bar via dev <ovs-dev@openvswitch.org>
57 Commit: A
58
59 Signed-off-by: A" \
60 "ERROR: Author should not be mailing list."
61
62 # Sign-off for single author and different committer.
63 try_checkpatch \
64 "Author: A
65 Commit: B
66
67 Signed-off-by: A
68 Signed-off-by: B"
69 try_checkpatch \
70 "Author: A
71 Commit: B" \
72 "ERROR: Author A needs to sign off.
73 ERROR: Committer B needs to sign off."
74
75 # Sign-off for multiple authors with one author also the committer.
76 try_checkpatch \
77 "Author: A
78 Commit: A
79
80 Signed-off-by: A
81 Co-authored-by: B
82 Signed-off-by: B"
83 try_checkpatch \
84 "Author: A
85 Commit: A
86
87 Co-authored-by: B
88 Signed-off-by: B" \
89 "ERROR: Author A needs to sign off."
90 try_checkpatch \
91 "Author: A
92 Commit: A
93
94 Signed-off-by: A
95 Co-authored-by: B" \
96 "ERROR: Co-author B needs to sign off."
97 try_checkpatch \
98 "Author: A
99 Commit: A
100
101 Co-authored-by: B" \
102 "ERROR: Author A needs to sign off.
103 ERROR: Co-author B needs to sign off."
104
105 # Sign-off for multiple authors and separate committer.
106 try_checkpatch \
107 "Author: A
108 Commit: C
109
110 Signed-off-by: A
111 Co-authored-by: B
112 Signed-off-by: B
113 Signed-off-by: C"
114 try_checkpatch \
115 "Author: A
116 Commit: C
117
118 Signed-off-by: A
119 Co-authored-by: B
120 Signed-off-by: B" \
121 "ERROR: Committer C needs to sign off."
122
123 # Extra sign-offs:
124 #
125 # - If we know the committer, one extra sign-off raises a warning.
126 #
127 # - If we do not know the committer, two extra sign-offs raise a warning.
128 try_checkpatch \
129 "Author: A
130 Commit: C
131
132 Signed-off-by: A
133 Co-authored-by: B
134 Signed-off-by: B
135 Signed-off-by: C
136 Signed-off-by: D" \
137 "WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: D"
138 try_checkpatch \
139 "Author: A
140
141 Signed-off-by: A
142 Co-authored-by: B
143 Signed-off-by: B
144 Signed-off-by: C"
145 try_checkpatch \
146 "Author: A
147
148 Signed-off-by: A
149 Co-authored-by: B
150 Signed-off-by: B
151 Signed-off-by: C
152 Signed-off-by: D" \
153 "WARNING: Unexpected sign-offs from developers who are not authors or co-authors or committers: C, D"
154
155 # Missing committer is OK, missing author is an error.
156 try_checkpatch \
157 "Author: A
158
159 Signed-off-by: A"
160 try_checkpatch \
161 "Commit: A
162
163 Signed-off-by: A" \
164 "ERROR: Patch lacks author."
165
166 AT_CLEANUP
167
168
169 m4_define([COMMON_PATCH_HEADER], [dnl
170 Author: A
171
172 Signed-off-by: A
173 ---
174 diff --git a/A.c b/A.c
175 index 0000000..1111111 100644
176 --- a/A.c
177 +++ b/A.c
178 @@ -1,1 +1,1 @@])
179
180
181 AT_SETUP([checkpatch - parenthesized constructs])
182 for ctr in 'if' 'while' 'switch'; do
183 try_checkpatch \
184 "COMMON_PATCH_HEADER
185 + $ctr (first_run) {
186 "
187
188 try_checkpatch \
189 "COMMON_PATCH_HEADER
190 + $ctr ( first_run) {
191 " \
192 "ERROR: Improper whitespace around control block
193 #8 FILE: A.c:1:
194 $ctr ( first_run) {
195 "
196
197 try_checkpatch \
198 "COMMON_PATCH_HEADER
199 + $ctr (first_run ) {
200 " \
201 "ERROR: Inappropriate bracing around statement
202 #8 FILE: A.c:1:
203 $ctr (first_run ) {
204 "
205
206 try_checkpatch \
207 "COMMON_PATCH_HEADER
208 + $ctr (first_run)
209 " \
210 "ERROR: Inappropriate bracing around statement
211 #8 FILE: A.c:1:
212 $ctr (first_run)
213 "
214
215 try_checkpatch \
216 "COMMON_PATCH_HEADER
217 + $ctr(first_run)
218 " \
219 "ERROR: Improper whitespace around control block
220 #8 FILE: A.c:1:
221 $ctr(first_run)
222 "
223
224 try_checkpatch \
225 "COMMON_PATCH_HEADER
226 + $ctr (first_run) { /* foo */
227 "
228
229 try_checkpatch \
230 "COMMON_PATCH_HEADER
231 + $ctr (first_run) { \\
232 "
233 done
234 AT_CLEANUP
235
236
237 AT_SETUP([checkpatch - parenthesized constructs - for])
238 try_checkpatch \
239 "COMMON_PATCH_HEADER
240 + for (init; condition; increment) {
241 "
242
243 try_checkpatch \
244 "COMMON_PATCH_HEADER
245 + for ( init; condition; increment) {
246 " \
247 "ERROR: Improper whitespace around control block
248 #8 FILE: A.c:1:
249 for ( init; condition; increment) {
250 "
251
252 try_checkpatch \
253 "COMMON_PATCH_HEADER
254 + for (init; condition; increment ) {
255 " \
256 "ERROR: Inappropriate bracing around statement
257 #8 FILE: A.c:1:
258 for (init; condition; increment ) {
259 "
260
261 try_checkpatch \
262 "COMMON_PATCH_HEADER
263 + for (init; condition; increment)
264 " \
265 "ERROR: Inappropriate bracing around statement
266 #8 FILE: A.c:1:
267 for (init; condition; increment)
268 "
269
270 try_checkpatch \
271 "COMMON_PATCH_HEADER
272 + for(init; condition; increment)
273 " \
274 "ERROR: Improper whitespace around control block
275 #8 FILE: A.c:1:
276 for(init; condition; increment)
277 "
278
279 try_checkpatch \
280 "COMMON_PATCH_HEADER
281 + for (init; condition; increment) { /* foo */
282 "
283
284 try_checkpatch \
285 "COMMON_PATCH_HEADER
286 + for (init; condition; increment) { \\
287 "
288
289 AT_CLEANUP
290
291
292 AT_SETUP([checkpatch - comments])
293 try_checkpatch \
294 "COMMON_PATCH_HEADER
295 + a = 1; /* C style comment. */
296 "
297
298 try_checkpatch \
299 "COMMON_PATCH_HEADER
300 + /* http://URL/inside/the/comment.html */
301 "
302
303 try_checkpatch \
304 "COMMON_PATCH_HEADER
305 + a = 1; // C99 style comment.
306 " \
307 "ERROR: C99 style comment
308 #8 FILE: A.c:1:
309 a = 1; // C99 style comment.
310 "
311
312 AT_CLEANUP
313
314 AT_SETUP([checkpatch - whitespace around operator])
315 try_checkpatch \
316 "COMMON_PATCH_HEADER
317 + if (--mcs->n_refs == 0) {
318 "
319
320 try_checkpatch \
321 "COMMON_PATCH_HEADER
322 + if (--mcs->n_refs==0) {
323 " \
324 "WARNING: Line lacks whitespace around operator
325 WARNING: Line lacks whitespace around operator
326 #8 FILE: A.c:1:
327 if (--mcs->n_refs==0) {
328 "
329
330 AT_CLEANUP