Mercurial > hg
comparison tests/test-check-code.t @ 27909:3203dfe341f9 stable
merge default into stable for 3.7 code freeze
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 17 Jan 2016 21:40:21 -0600 |
parents | e78447e61624 409a20314c64 |
children | 6d72cc613fc4 |
comparison
equal
deleted
inserted
replaced
27723:bf86e3e87123 | 27909:3203dfe341f9 |
---|---|
1 $ cat > correct.py <<EOF | 1 #require test-repo |
2 > def toto(arg1, arg2): | 2 |
3 > del arg2 | |
4 > return (5 + 6, 9) | |
5 > EOF | |
6 $ cat > wrong.py <<EOF | |
7 > def toto( arg1, arg2): | |
8 > del(arg2) | |
9 > return ( 5+6, 9) | |
10 > EOF | |
11 $ cat > quote.py <<EOF | |
12 > # let's use quote in comments | |
13 > (''' ( 4x5 ) | |
14 > but """\\''' and finally''', | |
15 > """let's fool checkpatch""", '1+2', | |
16 > '"""', 42+1, """and | |
17 > ( 4-1 ) """, "( 1+1 )\" and ") | |
18 > a, '\\\\\\\\', "\\\\\\" x-2", "c-1" | |
19 > EOF | |
20 $ cat > classstyle.py <<EOF | |
21 > class newstyle_class(object): | |
22 > pass | |
23 > | |
24 > class oldstyle_class: | |
25 > pass | |
26 > | |
27 > class empty(): | |
28 > pass | |
29 > | |
30 > no_class = 1: | |
31 > pass | |
32 > EOF | |
33 $ check_code="$TESTDIR"/../contrib/check-code.py | 3 $ check_code="$TESTDIR"/../contrib/check-code.py |
34 $ "$check_code" ./wrong.py ./correct.py ./quote.py ./classstyle.py | 4 $ cd "$TESTDIR"/.. |
35 ./wrong.py:1: | |
36 > def toto( arg1, arg2): | |
37 gratuitous whitespace in () or [] | |
38 ./wrong.py:2: | |
39 > del(arg2) | |
40 Python keyword is not a function | |
41 ./wrong.py:3: | |
42 > return ( 5+6, 9) | |
43 gratuitous whitespace in () or [] | |
44 missing whitespace in expression | |
45 ./quote.py:5: | |
46 > '"""', 42+1, """and | |
47 missing whitespace in expression | |
48 ./classstyle.py:4: | |
49 > class oldstyle_class: | |
50 old-style class, use class foo(object) | |
51 ./classstyle.py:7: | |
52 > class empty(): | |
53 class foo() creates old style object, use class foo(object) | |
54 [1] | |
55 $ cat > python3-compat.py << EOF | |
56 > foo <> bar | |
57 > reduce(lambda a, b: a + b, [1, 2, 3, 4]) | |
58 > dict(key=value) | |
59 > EOF | |
60 $ "$check_code" python3-compat.py | |
61 python3-compat.py:1: | |
62 > foo <> bar | |
63 <> operator is not available in Python 3+, use != | |
64 python3-compat.py:2: | |
65 > reduce(lambda a, b: a + b, [1, 2, 3, 4]) | |
66 reduce is not available in Python 3+ | |
67 python3-compat.py:3: | |
68 > dict(key=value) | |
69 dict() is different in Py2 and 3 and is slower than {} | |
70 [1] | |
71 | 5 |
72 $ cat > is-op.py <<EOF | 6 New errors are not allowed. Warnings are strongly discouraged. |
73 > # is-operator comparing number or string literal | 7 (The writing "no-che?k-code" is for not skipping this file when checking.) |
74 > x = None | |
75 > y = x is 'foo' | |
76 > y = x is "foo" | |
77 > y = x is 5346 | |
78 > y = x is -6 | |
79 > y = x is not 'foo' | |
80 > y = x is not "foo" | |
81 > y = x is not 5346 | |
82 > y = x is not -6 | |
83 > EOF | |
84 | 8 |
85 $ "$check_code" ./is-op.py | 9 $ hg locate | sed 's-\\-/-g' | |
86 ./is-op.py:3: | 10 > xargs "$check_code" --warnings --per-file=0 || false |
87 > y = x is 'foo' | 11 Skipping hgext/zeroconf/Zeroconf.py it has no-che?k-code (glob) |
88 object comparison with literal | 12 Skipping i18n/polib.py it has no-che?k-code (glob) |
89 ./is-op.py:4: | 13 Skipping mercurial/httpclient/__init__.py it has no-che?k-code (glob) |
90 > y = x is "foo" | 14 Skipping mercurial/httpclient/_readers.py it has no-che?k-code (glob) |
91 object comparison with literal | 15 Skipping mercurial/httpclient/socketutil.py it has no-che?k-code (glob) |
92 ./is-op.py:5: | |
93 > y = x is 5346 | |
94 object comparison with literal | |
95 ./is-op.py:6: | |
96 > y = x is -6 | |
97 object comparison with literal | |
98 ./is-op.py:7: | |
99 > y = x is not 'foo' | |
100 object comparison with literal | |
101 ./is-op.py:8: | |
102 > y = x is not "foo" | |
103 object comparison with literal | |
104 ./is-op.py:9: | |
105 > y = x is not 5346 | |
106 object comparison with literal | |
107 ./is-op.py:10: | |
108 > y = x is not -6 | |
109 object comparison with literal | |
110 [1] | |
111 | |
112 $ cat > for-nolineno.py <<EOF | |
113 > except: | |
114 > EOF | |
115 $ "$check_code" for-nolineno.py --nolineno | |
116 for-nolineno.py:0: | |
117 > except: | |
118 naked except clause | |
119 [1] | |
120 | |
121 $ cat > warning.t <<EOF | |
122 > $ function warnonly { | |
123 > > } | |
124 > $ diff -N aaa | |
125 > $ function onwarn {} | |
126 > EOF | |
127 $ "$check_code" warning.t | |
128 $ "$check_code" --warn warning.t | |
129 warning.t:1: | |
130 > $ function warnonly { | |
131 warning: don't use 'function', use old style | |
132 warning.t:3: | |
133 > $ diff -N aaa | |
134 warning: don't use 'diff -N' | |
135 warning.t:4: | |
136 > $ function onwarn {} | |
137 warning: don't use 'function', use old style | |
138 [1] | |
139 $ cat > raise-format.py <<EOF | |
140 > raise SomeException, message | |
141 > # this next line is okay | |
142 > raise SomeException(arg1, arg2) | |
143 > EOF | |
144 $ "$check_code" not-existing.py raise-format.py | |
145 Skipping*not-existing.py* (glob) | |
146 raise-format.py:1: | |
147 > raise SomeException, message | |
148 don't use old-style two-argument raise, use Exception(message) | |
149 [1] | |
150 | |
151 $ cat > rst.py <<EOF | |
152 > """problematic rst text | |
153 > | |
154 > .. note:: | |
155 > wrong | |
156 > """ | |
157 > | |
158 > ''' | |
159 > | |
160 > .. note:: | |
161 > | |
162 > valid | |
163 > | |
164 > new text | |
165 > | |
166 > .. note:: | |
167 > | |
168 > also valid | |
169 > ''' | |
170 > | |
171 > """mixed | |
172 > | |
173 > .. note:: | |
174 > | |
175 > good | |
176 > | |
177 > .. note:: | |
178 > plus bad | |
179 > """ | |
180 > EOF | |
181 $ $check_code -w rst.py | |
182 rst.py:3: | |
183 > .. note:: | |
184 warning: add two newlines after '.. note::' | |
185 rst.py:26: | |
186 > .. note:: | |
187 warning: add two newlines after '.. note::' | |
188 [1] | |
189 | |
190 $ cat > ./map-inside-gettext.py <<EOF | |
191 > print _("map inside gettext %s" % v) | |
192 > | |
193 > print _("concatenating " " by " " space %s" % v) | |
194 > print _("concatenating " + " by " + " '+' %s" % v) | |
195 > | |
196 > print _("mapping operation in different line %s" | |
197 > % v) | |
198 > | |
199 > print _( | |
200 > "leading spaces inside of '(' %s" % v) | |
201 > EOF | |
202 $ "$check_code" ./map-inside-gettext.py | |
203 ./map-inside-gettext.py:1: | |
204 > print _("map inside gettext %s" % v) | |
205 don't use % inside _() | |
206 ./map-inside-gettext.py:3: | |
207 > print _("concatenating " " by " " space %s" % v) | |
208 don't use % inside _() | |
209 ./map-inside-gettext.py:4: | |
210 > print _("concatenating " + " by " + " '+' %s" % v) | |
211 don't use % inside _() | |
212 ./map-inside-gettext.py:6: | |
213 > print _("mapping operation in different line %s" | |
214 don't use % inside _() | |
215 ./map-inside-gettext.py:9: | |
216 > print _( | |
217 don't use % inside _() | |
218 [1] | |
219 | |
220 web templates | |
221 | |
222 $ mkdir -p mercurial/templates | |
223 $ cat > mercurial/templates/example.tmpl <<EOF | |
224 > {desc} | |
225 > {desc|escape} | |
226 > {desc|firstline} | |
227 > {desc|websub} | |
228 > EOF | |
229 | |
230 $ "$check_code" --warnings mercurial/templates/example.tmpl | |
231 mercurial/templates/example.tmpl:2: | |
232 > {desc|escape} | |
233 warning: follow desc keyword with either firstline or websub | |
234 [1] |