##// END OF EJS Templates
tests: use NO_CHECK_EOF as heredoc limit mark to omit checking code fragments...
FUJIWARA Katsunori -
r40130:ff47ba7a default
parent child Browse files
Show More
@@ -1,375 +1,375 b''
1 $ cat > correct.py <<EOF
1 $ cat > correct.py <<NO_CHECK_EOF
2 > def toto(arg1, arg2):
2 > def toto(arg1, arg2):
3 > del arg2
3 > del arg2
4 > return (5 + 6, 9)
4 > return (5 + 6, 9)
5 > EOF
5 > NO_CHECK_EOF
6 $ cat > wrong.py <<EOF
6 $ cat > wrong.py <<NO_CHECK_EOF
7 > def toto( arg1, arg2):
7 > def toto( arg1, arg2):
8 > del(arg2)
8 > del(arg2)
9 > return ( 5+6, 9)
9 > return ( 5+6, 9)
10 > EOF
10 > NO_CHECK_EOF
11 $ cat > quote.py <<EOF
11 $ cat > quote.py <<NO_CHECK_EOF
12 > # let's use quote in comments
12 > # let's use quote in comments
13 > (''' ( 4x5 )
13 > (''' ( 4x5 )
14 > but """\\''' and finally''',
14 > but """\\''' and finally''',
15 > """let's fool checkpatch""", '1+2',
15 > """let's fool checkpatch""", '1+2',
16 > '"""', 42+1, """and
16 > '"""', 42+1, """and
17 > ( 4-1 ) """, "( 1+1 )\" and ")
17 > ( 4-1 ) """, "( 1+1 )\" and ")
18 > a, '\\\\\\\\', "\\\\\\" x-2", "c-1"
18 > a, '\\\\\\\\', "\\\\\\" x-2", "c-1"
19 > EOF
19 > NO_CHECK_EOF
20 $ cat > classstyle.py <<EOF
20 $ cat > classstyle.py <<NO_CHECK_EOF
21 > class newstyle_class(object):
21 > class newstyle_class(object):
22 > pass
22 > pass
23 >
23 >
24 > class oldstyle_class:
24 > class oldstyle_class:
25 > pass
25 > pass
26 >
26 >
27 > class empty():
27 > class empty():
28 > pass
28 > pass
29 >
29 >
30 > no_class = 1:
30 > no_class = 1:
31 > pass
31 > pass
32 > EOF
32 > NO_CHECK_EOF
33 $ check_code="$TESTDIR"/../contrib/check-code.py
33 $ check_code="$TESTDIR"/../contrib/check-code.py
34 $ "$check_code" ./wrong.py ./correct.py ./quote.py ./classstyle.py
34 $ "$check_code" ./wrong.py ./correct.py ./quote.py ./classstyle.py
35 ./wrong.py:1:
35 ./wrong.py:1:
36 > def toto( arg1, arg2):
36 > def toto( arg1, arg2):
37 gratuitous whitespace in () or []
37 gratuitous whitespace in () or []
38 ./wrong.py:2:
38 ./wrong.py:2:
39 > del(arg2)
39 > del(arg2)
40 Python keyword is not a function
40 Python keyword is not a function
41 ./wrong.py:3:
41 ./wrong.py:3:
42 > return ( 5+6, 9)
42 > return ( 5+6, 9)
43 gratuitous whitespace in () or []
43 gratuitous whitespace in () or []
44 missing whitespace in expression
44 missing whitespace in expression
45 ./quote.py:5:
45 ./quote.py:5:
46 > '"""', 42+1, """and
46 > '"""', 42+1, """and
47 missing whitespace in expression
47 missing whitespace in expression
48 ./classstyle.py:4:
48 ./classstyle.py:4:
49 > class oldstyle_class:
49 > class oldstyle_class:
50 old-style class, use class foo(object)
50 old-style class, use class foo(object)
51 ./classstyle.py:7:
51 ./classstyle.py:7:
52 > class empty():
52 > class empty():
53 class foo() creates old style object, use class foo(object)
53 class foo() creates old style object, use class foo(object)
54 [1]
54 [1]
55 $ cat > python3-compat.py << EOF
55 $ cat > python3-compat.py << NO_CHECK_EOF
56 > foo <> bar
56 > foo <> bar
57 > reduce(lambda a, b: a + b, [1, 2, 3, 4])
57 > reduce(lambda a, b: a + b, [1, 2, 3, 4])
58 > dict(key=value)
58 > dict(key=value)
59 > EOF
59 > NO_CHECK_EOF
60 $ "$check_code" python3-compat.py
60 $ "$check_code" python3-compat.py
61 python3-compat.py:1:
61 python3-compat.py:1:
62 > foo <> bar
62 > foo <> bar
63 <> operator is not available in Python 3+, use !=
63 <> operator is not available in Python 3+, use !=
64 python3-compat.py:2:
64 python3-compat.py:2:
65 > reduce(lambda a, b: a + b, [1, 2, 3, 4])
65 > reduce(lambda a, b: a + b, [1, 2, 3, 4])
66 reduce is not available in Python 3+
66 reduce is not available in Python 3+
67 python3-compat.py:3:
67 python3-compat.py:3:
68 > dict(key=value)
68 > dict(key=value)
69 dict() is different in Py2 and 3 and is slower than {}
69 dict() is different in Py2 and 3 and is slower than {}
70 [1]
70 [1]
71
71
72 $ cat > foo.c <<EOF
72 $ cat > foo.c <<NO_CHECK_EOF
73 > void narf() {
73 > void narf() {
74 > strcpy(foo, bar);
74 > strcpy(foo, bar);
75 > // strcpy_s is okay, but this comment is not
75 > // strcpy_s is okay, but this comment is not
76 > strcpy_s(foo, bar);
76 > strcpy_s(foo, bar);
77 > }
77 > }
78 > EOF
78 > NO_CHECK_EOF
79 $ "$check_code" ./foo.c
79 $ "$check_code" ./foo.c
80 ./foo.c:2:
80 ./foo.c:2:
81 > strcpy(foo, bar);
81 > strcpy(foo, bar);
82 don't use strcpy, use strlcpy or memcpy
82 don't use strcpy, use strlcpy or memcpy
83 ./foo.c:3:
83 ./foo.c:3:
84 > // strcpy_s is okay, but this comment is not
84 > // strcpy_s is okay, but this comment is not
85 don't use //-style comments
85 don't use //-style comments
86 [1]
86 [1]
87
87
88 $ cat > is-op.py <<EOF
88 $ cat > is-op.py <<NO_CHECK_EOF
89 > # is-operator comparing number or string literal
89 > # is-operator comparing number or string literal
90 > x = None
90 > x = None
91 > y = x is 'foo'
91 > y = x is 'foo'
92 > y = x is "foo"
92 > y = x is "foo"
93 > y = x is 5346
93 > y = x is 5346
94 > y = x is -6
94 > y = x is -6
95 > y = x is not 'foo'
95 > y = x is not 'foo'
96 > y = x is not "foo"
96 > y = x is not "foo"
97 > y = x is not 5346
97 > y = x is not 5346
98 > y = x is not -6
98 > y = x is not -6
99 > EOF
99 > NO_CHECK_EOF
100
100
101 $ "$check_code" ./is-op.py
101 $ "$check_code" ./is-op.py
102 ./is-op.py:3:
102 ./is-op.py:3:
103 > y = x is 'foo'
103 > y = x is 'foo'
104 object comparison with literal
104 object comparison with literal
105 ./is-op.py:4:
105 ./is-op.py:4:
106 > y = x is "foo"
106 > y = x is "foo"
107 object comparison with literal
107 object comparison with literal
108 ./is-op.py:5:
108 ./is-op.py:5:
109 > y = x is 5346
109 > y = x is 5346
110 object comparison with literal
110 object comparison with literal
111 ./is-op.py:6:
111 ./is-op.py:6:
112 > y = x is -6
112 > y = x is -6
113 object comparison with literal
113 object comparison with literal
114 ./is-op.py:7:
114 ./is-op.py:7:
115 > y = x is not 'foo'
115 > y = x is not 'foo'
116 object comparison with literal
116 object comparison with literal
117 ./is-op.py:8:
117 ./is-op.py:8:
118 > y = x is not "foo"
118 > y = x is not "foo"
119 object comparison with literal
119 object comparison with literal
120 ./is-op.py:9:
120 ./is-op.py:9:
121 > y = x is not 5346
121 > y = x is not 5346
122 object comparison with literal
122 object comparison with literal
123 ./is-op.py:10:
123 ./is-op.py:10:
124 > y = x is not -6
124 > y = x is not -6
125 object comparison with literal
125 object comparison with literal
126 [1]
126 [1]
127
127
128 $ cat > for-nolineno.py <<EOF
128 $ cat > for-nolineno.py <<NO_CHECK_EOF
129 > except:
129 > except:
130 > EOF
130 > NO_CHECK_EOF
131 $ "$check_code" for-nolineno.py --nolineno
131 $ "$check_code" for-nolineno.py --nolineno
132 for-nolineno.py:0:
132 for-nolineno.py:0:
133 > except:
133 > except:
134 naked except clause
134 naked except clause
135 [1]
135 [1]
136
136
137 $ cat > warning.t <<EOF
137 $ cat > warning.t <<NO_CHECK_EOF
138 > $ function warnonly {
138 > $ function warnonly {
139 > > }
139 > > }
140 > $ diff -N aaa
140 > $ diff -N aaa
141 > $ function onwarn {}
141 > $ function onwarn {}
142 > EOF
142 > NO_CHECK_EOF
143 $ "$check_code" warning.t
143 $ "$check_code" warning.t
144 $ "$check_code" --warn warning.t
144 $ "$check_code" --warn warning.t
145 warning.t:1:
145 warning.t:1:
146 > $ function warnonly {
146 > $ function warnonly {
147 warning: don't use 'function', use old style
147 warning: don't use 'function', use old style
148 warning.t:3:
148 warning.t:3:
149 > $ diff -N aaa
149 > $ diff -N aaa
150 warning: don't use 'diff -N'
150 warning: don't use 'diff -N'
151 warning.t:4:
151 warning.t:4:
152 > $ function onwarn {}
152 > $ function onwarn {}
153 warning: don't use 'function', use old style
153 warning: don't use 'function', use old style
154 [1]
154 [1]
155 $ cat > error.t <<EOF
155 $ cat > error.t <<NO_CHECK_EOF
156 > $ [ foo == bar ]
156 > $ [ foo == bar ]
157 > EOF
157 > NO_CHECK_EOF
158 $ "$check_code" error.t
158 $ "$check_code" error.t
159 error.t:1:
159 error.t:1:
160 > $ [ foo == bar ]
160 > $ [ foo == bar ]
161 [ foo == bar ] is a bashism, use [ foo = bar ] instead
161 [ foo == bar ] is a bashism, use [ foo = bar ] instead
162 [1]
162 [1]
163 $ rm error.t
163 $ rm error.t
164 $ cat > raise-format.py <<EOF
164 $ cat > raise-format.py <<NO_CHECK_EOF
165 > raise SomeException, message
165 > raise SomeException, message
166 > # this next line is okay
166 > # this next line is okay
167 > raise SomeException(arg1, arg2)
167 > raise SomeException(arg1, arg2)
168 > EOF
168 > NO_CHECK_EOF
169 $ "$check_code" not-existing.py raise-format.py
169 $ "$check_code" not-existing.py raise-format.py
170 Skipping*not-existing.py* (glob)
170 Skipping*not-existing.py* (glob)
171 raise-format.py:1:
171 raise-format.py:1:
172 > raise SomeException, message
172 > raise SomeException, message
173 don't use old-style two-argument raise, use Exception(message)
173 don't use old-style two-argument raise, use Exception(message)
174 [1]
174 [1]
175
175
176 $ cat <<EOF > tab.t
176 $ cat <<NO_CHECK_EOF > tab.t
177 > indent
177 > indent
178 > > heredoc
178 > > heredoc
179 > EOF
179 > NO_CHECK_EOF
180 $ "$check_code" tab.t
180 $ "$check_code" tab.t
181 tab.t:1:
181 tab.t:1:
182 > indent
182 > indent
183 don't use tabs to indent
183 don't use tabs to indent
184 [1]
184 [1]
185 $ rm tab.t
185 $ rm tab.t
186
186
187 $ cat > rst.py <<EOF
187 $ cat > rst.py <<NO_CHECK_EOF
188 > """problematic rst text
188 > """problematic rst text
189 >
189 >
190 > .. note::
190 > .. note::
191 > wrong
191 > wrong
192 > """
192 > """
193 >
193 >
194 > '''
194 > '''
195 >
195 >
196 > .. note::
196 > .. note::
197 >
197 >
198 > valid
198 > valid
199 >
199 >
200 > new text
200 > new text
201 >
201 >
202 > .. note::
202 > .. note::
203 >
203 >
204 > also valid
204 > also valid
205 > '''
205 > '''
206 >
206 >
207 > """mixed
207 > """mixed
208 >
208 >
209 > .. note::
209 > .. note::
210 >
210 >
211 > good
211 > good
212 >
212 >
213 > .. note::
213 > .. note::
214 > plus bad
214 > plus bad
215 > """
215 > """
216 > EOF
216 > NO_CHECK_EOF
217 $ $check_code -w rst.py
217 $ $check_code -w rst.py
218 rst.py:3:
218 rst.py:3:
219 > .. note::
219 > .. note::
220 warning: add two newlines after '.. note::'
220 warning: add two newlines after '.. note::'
221 rst.py:26:
221 rst.py:26:
222 > .. note::
222 > .. note::
223 warning: add two newlines after '.. note::'
223 warning: add two newlines after '.. note::'
224 [1]
224 [1]
225
225
226 $ cat > ./map-inside-gettext.py <<EOF
226 $ cat > ./map-inside-gettext.py <<NO_CHECK_EOF
227 > print(_("map inside gettext %s" % v))
227 > print(_("map inside gettext %s" % v))
228 >
228 >
229 > print(_("concatenating " " by " " space %s" % v))
229 > print(_("concatenating " " by " " space %s" % v))
230 > print(_("concatenating " + " by " + " '+' %s" % v))
230 > print(_("concatenating " + " by " + " '+' %s" % v))
231 >
231 >
232 > print(_("mapping operation in different line %s"
232 > print(_("mapping operation in different line %s"
233 > % v))
233 > % v))
234 >
234 >
235 > print(_(
235 > print(_(
236 > "leading spaces inside of '(' %s" % v))
236 > "leading spaces inside of '(' %s" % v))
237 > EOF
237 > NO_CHECK_EOF
238 $ "$check_code" ./map-inside-gettext.py
238 $ "$check_code" ./map-inside-gettext.py
239 ./map-inside-gettext.py:1:
239 ./map-inside-gettext.py:1:
240 > print(_("map inside gettext %s" % v))
240 > print(_("map inside gettext %s" % v))
241 don't use % inside _()
241 don't use % inside _()
242 ./map-inside-gettext.py:3:
242 ./map-inside-gettext.py:3:
243 > print(_("concatenating " " by " " space %s" % v))
243 > print(_("concatenating " " by " " space %s" % v))
244 don't use % inside _()
244 don't use % inside _()
245 ./map-inside-gettext.py:4:
245 ./map-inside-gettext.py:4:
246 > print(_("concatenating " + " by " + " '+' %s" % v))
246 > print(_("concatenating " + " by " + " '+' %s" % v))
247 don't use % inside _()
247 don't use % inside _()
248 ./map-inside-gettext.py:6:
248 ./map-inside-gettext.py:6:
249 > print(_("mapping operation in different line %s"
249 > print(_("mapping operation in different line %s"
250 don't use % inside _()
250 don't use % inside _()
251 ./map-inside-gettext.py:9:
251 ./map-inside-gettext.py:9:
252 > print(_(
252 > print(_(
253 don't use % inside _()
253 don't use % inside _()
254 [1]
254 [1]
255
255
256 web templates
256 web templates
257
257
258 $ mkdir -p mercurial/templates
258 $ mkdir -p mercurial/templates
259 $ cat > mercurial/templates/example.tmpl <<EOF
259 $ cat > mercurial/templates/example.tmpl <<NO_CHECK_EOF
260 > {desc}
260 > {desc}
261 > {desc|escape}
261 > {desc|escape}
262 > {desc|firstline}
262 > {desc|firstline}
263 > {desc|websub}
263 > {desc|websub}
264 > EOF
264 > NO_CHECK_EOF
265
265
266 $ "$check_code" --warnings mercurial/templates/example.tmpl
266 $ "$check_code" --warnings mercurial/templates/example.tmpl
267 mercurial/templates/example.tmpl:2:
267 mercurial/templates/example.tmpl:2:
268 > {desc|escape}
268 > {desc|escape}
269 warning: follow desc keyword with either firstline or websub
269 warning: follow desc keyword with either firstline or websub
270 [1]
270 [1]
271
271
272 'string join across lines with no space' detection
272 'string join across lines with no space' detection
273
273
274 $ cat > stringjoin.py <<EOF
274 $ cat > stringjoin.py <<NO_CHECK_EOF
275 > foo = (' foo'
275 > foo = (' foo'
276 > 'bar foo.'
276 > 'bar foo.'
277 > 'bar foo:'
277 > 'bar foo:'
278 > 'bar foo@'
278 > 'bar foo@'
279 > 'bar foo%'
279 > 'bar foo%'
280 > 'bar foo*'
280 > 'bar foo*'
281 > 'bar foo+'
281 > 'bar foo+'
282 > 'bar foo-'
282 > 'bar foo-'
283 > 'bar')
283 > 'bar')
284 > EOF
284 > NO_CHECK_EOF
285
285
286 'missing _() in ui message' detection
286 'missing _() in ui message' detection
287
287
288 $ cat > uigettext.py <<EOF
288 $ cat > uigettext.py <<NO_CHECK_EOF
289 > ui.status("% 10s %05d % -3.2f %*s %%"
289 > ui.status("% 10s %05d % -3.2f %*s %%"
290 > # this use '\\\\' instead of '\\', because the latter in
290 > # this use '\\\\' instead of '\\', because the latter in
291 > # heredoc on shell becomes just '\'
291 > # heredoc on shell becomes just '\'
292 > '\\\\ \n \t \0'
292 > '\\\\ \n \t \0'
293 > """12345
293 > """12345
294 > """
294 > """
295 > '''.:*+-=
295 > '''.:*+-=
296 > ''' "%-6d \n 123456 .:*+-= foobar")
296 > ''' "%-6d \n 123456 .:*+-= foobar")
297 > EOF
297 > NO_CHECK_EOF
298
298
299 superfluous pass
299 superfluous pass
300
300
301 $ cat > superfluous_pass.py <<EOF
301 $ cat > superfluous_pass.py <<NO_CHECK_EOF
302 > # correct examples
302 > # correct examples
303 > if foo:
303 > if foo:
304 > pass
304 > pass
305 > else:
305 > else:
306 > # comment-only line means still need pass
306 > # comment-only line means still need pass
307 > pass
307 > pass
308 > def nothing():
308 > def nothing():
309 > pass
309 > pass
310 > class empty(object):
310 > class empty(object):
311 > pass
311 > pass
312 > if whatever:
312 > if whatever:
313 > passvalue(value)
313 > passvalue(value)
314 > # bad examples
314 > # bad examples
315 > if foo:
315 > if foo:
316 > "foo"
316 > "foo"
317 > pass
317 > pass
318 > else: # trailing comment doesn't fool checker
318 > else: # trailing comment doesn't fool checker
319 > wat()
319 > wat()
320 > pass
320 > pass
321 > def nothing():
321 > def nothing():
322 > "docstring means no pass"
322 > "docstring means no pass"
323 > pass
323 > pass
324 > class empty(object):
324 > class empty(object):
325 > """multiline
325 > """multiline
326 > docstring also
326 > docstring also
327 > means no pass"""
327 > means no pass"""
328 > pass
328 > pass
329 > EOF
329 > NO_CHECK_EOF
330
330
331 (Checking multiple invalid files at once examines whether caching
331 (Checking multiple invalid files at once examines whether caching
332 translation table for repquote() works as expected or not. All files
332 translation table for repquote() works as expected or not. All files
333 should break rules depending on result of repquote(), in this case)
333 should break rules depending on result of repquote(), in this case)
334
334
335 $ "$check_code" stringjoin.py uigettext.py superfluous_pass.py
335 $ "$check_code" stringjoin.py uigettext.py superfluous_pass.py
336 stringjoin.py:1:
336 stringjoin.py:1:
337 > foo = (' foo'
337 > foo = (' foo'
338 string join across lines with no space
338 string join across lines with no space
339 stringjoin.py:2:
339 stringjoin.py:2:
340 > 'bar foo.'
340 > 'bar foo.'
341 string join across lines with no space
341 string join across lines with no space
342 stringjoin.py:3:
342 stringjoin.py:3:
343 > 'bar foo:'
343 > 'bar foo:'
344 string join across lines with no space
344 string join across lines with no space
345 stringjoin.py:4:
345 stringjoin.py:4:
346 > 'bar foo@'
346 > 'bar foo@'
347 string join across lines with no space
347 string join across lines with no space
348 stringjoin.py:5:
348 stringjoin.py:5:
349 > 'bar foo%'
349 > 'bar foo%'
350 string join across lines with no space
350 string join across lines with no space
351 stringjoin.py:6:
351 stringjoin.py:6:
352 > 'bar foo*'
352 > 'bar foo*'
353 string join across lines with no space
353 string join across lines with no space
354 stringjoin.py:7:
354 stringjoin.py:7:
355 > 'bar foo+'
355 > 'bar foo+'
356 string join across lines with no space
356 string join across lines with no space
357 stringjoin.py:8:
357 stringjoin.py:8:
358 > 'bar foo-'
358 > 'bar foo-'
359 string join across lines with no space
359 string join across lines with no space
360 uigettext.py:1:
360 uigettext.py:1:
361 > ui.status("% 10s %05d % -3.2f %*s %%"
361 > ui.status("% 10s %05d % -3.2f %*s %%"
362 missing _() in ui message (use () to hide false-positives)
362 missing _() in ui message (use () to hide false-positives)
363 superfluous_pass.py:14:
363 superfluous_pass.py:14:
364 > if foo:
364 > if foo:
365 omit superfluous pass
365 omit superfluous pass
366 superfluous_pass.py:17:
366 superfluous_pass.py:17:
367 > else: # trailing comment doesn't fool checker
367 > else: # trailing comment doesn't fool checker
368 omit superfluous pass
368 omit superfluous pass
369 superfluous_pass.py:20:
369 superfluous_pass.py:20:
370 > def nothing():
370 > def nothing():
371 omit superfluous pass
371 omit superfluous pass
372 superfluous_pass.py:23:
372 superfluous_pass.py:23:
373 > class empty(object):
373 > class empty(object):
374 omit superfluous pass
374 omit superfluous pass
375 [1]
375 [1]
General Comments 0
You need to be logged in to leave comments. Login now