comparison tests/test-contrib-check-code.t @ 27367:8833daddfc3f

test: rename 'check-code' own test to 'test-contrib-check-code.t' This test (making sure the 'check-code' script run as intended) have been confused with the test making that the mercurial code base comply with our coding still by multiple generations of contributors. We are moving it out of the way so that all tests starting with 'test-check' are now doing compliance testing.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Sat, 05 Dec 2015 22:47:26 -0800
parents tests/test-check-code.t@e78447e61624
children d3990da51637
comparison
equal deleted inserted replaced
27366:7e8a883da171 27367:8833daddfc3f
1 $ cat > correct.py <<EOF
2 > def toto(arg1, arg2):
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
34 $ "$check_code" ./wrong.py ./correct.py ./quote.py ./classstyle.py
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
72 $ cat > is-op.py <<EOF
73 > # is-operator comparing number or string literal
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
85 $ "$check_code" ./is-op.py
86 ./is-op.py:3:
87 > y = x is 'foo'
88 object comparison with literal
89 ./is-op.py:4:
90 > y = x is "foo"
91 object comparison with literal
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]