587
|
1 |
<?xml version="1.0" encoding="UTF-8"?>
|
|
2 |
<!--
|
|
3 |
============================================================================
|
|
4 |
Name : test_antlint.ant.xml
|
|
5 |
Part of : Helium AntLib
|
|
6 |
|
|
7 |
Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
8 |
All rights reserved.
|
|
9 |
This component and the accompanying materials are made available
|
|
10 |
under the terms of the License "Eclipse Public License v1.0"
|
|
11 |
which accompanies this distribution, and is available
|
|
12 |
at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
13 |
|
|
14 |
Initial Contributors:
|
|
15 |
Nokia Corporation - initial contribution.
|
|
16 |
|
|
17 |
Contributors:
|
|
18 |
|
|
19 |
Description:
|
|
20 |
|
|
21 |
============================================================================
|
|
22 |
-->
|
|
23 |
<project name="test-antlint" xmlns:au="antlib:org.apache.ant.antunit" xmlns:hlm="http://www.nokia.com/helium">
|
|
24 |
<description>Helium Antlib AntLint unittests.</description>
|
|
25 |
|
|
26 |
<dirname property="antlint.test.dir" file="${ant.file.test-antlint}/.."/>
|
|
27 |
|
|
28 |
<import file="${antlint.test.dir}/data/sample.ant.xml" />
|
|
29 |
|
588
|
30 |
<taskdef resource="com/nokia/helium/antlint/ant/antlib.xml" uri="http://www.nokia.com/helium"/>
|
|
31 |
|
587
|
32 |
<property name="data.model.parsed" location="${antlint.test.dir}/data/datamodel.out"/>
|
|
33 |
|
|
34 |
<!-- is called prior to the test -->
|
|
35 |
<target name="setUp">
|
588
|
36 |
<delete dir="${antlint.test.dir}/data/output" failonerror="false" />
|
|
37 |
<mkdir dir="${antlint.test.dir}/data/output" />
|
587
|
38 |
</target>
|
|
39 |
|
|
40 |
<!-- is called after the test, even if that caused an error -->
|
|
41 |
<target name="tearDown">
|
588
|
42 |
<delete dir="${antlint.test.dir}/data/output" failonerror="false" />
|
587
|
43 |
</target>
|
|
44 |
|
588
|
45 |
<target name="test-check-tab-character">
|
|
46 |
<hlm:antlint>
|
|
47 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
48 |
<include name="build.xml"/>
|
|
49 |
</fileset>
|
|
50 |
<hlm:checkTabCharacter severity="warning" enabled="true"/>
|
|
51 |
</hlm:antlint>
|
|
52 |
<au:assertLogContains text="WARNING: 25: Tabs should not be used!" level="info"/>
|
|
53 |
<au:assertLogContains text="WARNING: 29: Tabs should not be used!" level="info"/>
|
|
54 |
</target>
|
587
|
55 |
|
588
|
56 |
<target name="test-check-property-name">
|
|
57 |
<hlm:antlint>
|
|
58 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
59 |
<include name="sample.ant.xml"/>
|
|
60 |
</fileset>
|
|
61 |
<hlm:checkPropertyName severity="warning" enabled="true" regexp="([a-z0-9[\\d\\_\\.\\@\\{\\}\\$]]*)" />
|
|
62 |
</hlm:antlint>
|
|
63 |
<au:assertLogContains text="WARNING: INVALID Property Name: check-property-name" level="info"/>
|
|
64 |
</target>
|
|
65 |
|
|
66 |
<target name="test-check-target-name">
|
|
67 |
<hlm:antlint>
|
|
68 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
69 |
<include name="sample.ant.xml"/>
|
|
70 |
</fileset>
|
|
71 |
<hlm:checkTargetName severity="warning" enabled="true" regexp="([a-z0-9[\\d\\-]]*)" />
|
|
72 |
</hlm:antlint>
|
|
73 |
<au:assertLogContains text="WARNING: INVALID Target Name: Check_target.Name" level="info"/>
|
|
74 |
</target>
|
|
75 |
|
|
76 |
<target name="test-check-indentation">
|
|
77 |
<hlm:antlint>
|
|
78 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
79 |
<include name="sample.ant.xml"/>
|
|
80 |
</fileset>
|
|
81 |
<hlm:checkIndentation severity="warning" enabled="true"/>
|
|
82 |
</hlm:antlint>
|
|
83 |
<au:assertLogContains text="WARNING: 248: Bad indentation" level="info"/>
|
|
84 |
</target>
|
|
85 |
|
|
86 |
<target name="test-check-presetdef-macrodef-name">
|
|
87 |
<hlm:antlint>
|
|
88 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
89 |
<include name="sample.antlib.xml"/>
|
|
90 |
<include name="sample.ant.xml"/>
|
|
91 |
</fileset>
|
|
92 |
<hlm:checkPresetDefMacroDefName enabled="true" severity="warning" regexp="([a-z0-9][a-zA-Z0-9]*)"/>
|
|
93 |
</hlm:antlint>
|
|
94 |
<au:assertLogContains text="WARNING: INVALID PRESETDEF/MACRODEF Name: check_PresetDef.Name" level="info"/>
|
|
95 |
<au:assertLogContains text="WARNING: INVALID PRESETDEF/MACRODEF Name: foo_Macro" level="info"/>
|
|
96 |
</target>
|
|
97 |
|
|
98 |
<target name="test-check-project-name">
|
|
99 |
<hlm:antlint>
|
|
100 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
101 |
<include name="sample.ant.xml"/>
|
|
102 |
<include name="invalid.build.xml"/>
|
|
103 |
</fileset>
|
|
104 |
<hlm:checkProjectName enabled="true" severity="warning" regexp="([a-z0-9[\\d\\.\\_\\-]]*)"/>
|
|
105 |
</hlm:antlint>
|
|
106 |
<au:assertLogContains text="WARNING: INVALID Project Name: Sample" level="info"/>
|
|
107 |
<au:assertLogContains text="WARNING: Project name not specified!" level="info"/>
|
|
108 |
</target>
|
|
109 |
|
|
110 |
<target name="test-check-description">
|
|
111 |
<hlm:antlint>
|
|
112 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
113 |
<include name="build.xml"/>
|
|
114 |
</fileset>
|
|
115 |
<hlm:checkDescription enabled="true" severity="warning"/>
|
|
116 |
</hlm:antlint>
|
|
117 |
<au:assertLogContains text="WARNING: Description not specified!" level="info"/>
|
587
|
118 |
</target>
|
|
119 |
|
588
|
120 |
<target name="test-check-runtarget">
|
|
121 |
<hlm:antlint>
|
|
122 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
123 |
<include name="sample.ant.xml"/>
|
|
124 |
</fileset>
|
|
125 |
<hlm:checkRunTarget enabled="true" severity="warning"/>
|
|
126 |
</hlm:antlint>
|
|
127 |
<au:assertLogContains text="runtarget> calls the target smile that has dependencies!" level="info"/>
|
|
128 |
</target>
|
|
129 |
|
|
130 |
<target name="test-check-antcall">
|
|
131 |
<hlm:antlint>
|
|
132 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
133 |
<include name="sample.ant.xml"/>
|
|
134 |
</fileset>
|
|
135 |
<hlm:checkAntCall enabled="true" severity="warning"/>
|
|
136 |
</hlm:antlint>
|
|
137 |
<au:assertLogContains text="antcall> is used with no param elements and calls the target hello that has no dependencies!" level="info"/>
|
|
138 |
</target>
|
|
139 |
|
|
140 |
<target name="test-check-script-size">
|
|
141 |
<hlm:antlint>
|
|
142 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
143 |
<include name="sample.ant.xml"/>
|
|
144 |
</fileset>
|
|
145 |
<hlm:checkScriptSize enabled="true" severity="warning"/>
|
|
146 |
</hlm:antlint>
|
|
147 |
<au:assertLogContains text="WARNING: Target check-script-size has a script with 1098 characters, code should be inside a python file" level="info"/>
|
|
148 |
</target>
|
|
149 |
|
|
150 |
<target name="test-check-use-of-if-in-targets">
|
|
151 |
<hlm:antlint>
|
|
152 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
153 |
<include name="sample.ant.xml"/>
|
|
154 |
</fileset>
|
|
155 |
<hlm:checkUseOfIfInTargets enabled="true" severity="warning"/>
|
|
156 |
</hlm:antlint>
|
|
157 |
<au:assertLogContains text="WARNING: Target check-use-of-if-in-targets poor use of if statement, use " level="info"/>
|
|
158 |
<au:assertLogContains text="WARNING: Target check-use-of-if-else-in-targets poor use of if-else-property statement, use condition task" level="info"/>
|
|
159 |
<au:assertLogContains text="WARNING: Target check-use-of-if-then-in-targets poor use of if-then-property statement, use condition task" level="info"/>
|
|
160 |
<au:assertLogContains text="WARNING: Target check-prop-in-scriptcondition poor use of if-else-property statement, use condition task" level="info"/>
|
|
161 |
<au:assertLogContains text="WARNING: Target check-scriptcondition poor use of if-else-property statement, use condition task" level="info"/>
|
|
162 |
</target>
|
|
163 |
|
|
164 |
<target name="test-check-jython-script">
|
|
165 |
<hlm:antlint>
|
|
166 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
167 |
<include name="sample.ant.xml"/>
|
|
168 |
<include name="sample.antlib.xml"/>
|
|
169 |
</fileset>
|
|
170 |
<hlm:checkJythonScript enabled="true" severity="warning" outputDir="${antlint.test.dir}/data/output"/>
|
|
171 |
</hlm:antlint>
|
|
172 |
<au:assertLogContains text="found in target_check-jython-script" level="info"/>
|
|
173 |
<au:assertLogContains text="found in check-script" level="info"/>
|
|
174 |
</target>
|
|
175 |
|
|
176 |
<target name="test-check-use-of-equals-task">
|
|
177 |
<hlm:antlint>
|
|
178 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
179 |
<include name="sample.ant.xml"/>
|
|
180 |
</fileset>
|
|
181 |
<hlm:checkUseOfEqualsTask severity="warning" enabled="true"/>
|
|
182 |
</hlm:antlint>
|
|
183 |
<au:assertLogContains text="WARNING: test.boolean1 uses 'equals' should use 'istrue' task" level="info"/>
|
|
184 |
<au:assertLogContains text="WARNING: test.boolean2 uses 'equals' should use 'istrue' task" level="info"/>
|
|
185 |
</target>
|
|
186 |
|
|
187 |
<target name="test-check-script-condition">
|
|
188 |
<hlm:antlint>
|
|
189 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
190 |
<include name="sample.ant.xml"/>
|
|
191 |
<include name="sample.antlib.xml"/>
|
|
192 |
</fileset>
|
|
193 |
<hlm:checkScriptCondition enabled="true" severity="warning" outputDir="${antlint.test.dir}/data/output"/>
|
|
194 |
</hlm:antlint>
|
|
195 |
<au:assertLogContains text="found in scriptcondition_check-scriptcondition" level="info"/>
|
|
196 |
</target>
|
|
197 |
|
|
198 |
<target name="test-check-python-tasks">
|
587
|
199 |
<hlm:antlint>
|
|
200 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
201 |
<include name="*.xml"/>
|
|
202 |
<include name="*.ant.xml"/>
|
588
|
203 |
<include name="build.xml"/>
|
|
204 |
<include name="*.antlib.xml"/>
|
|
205 |
</fileset>
|
|
206 |
<hlm:checkPythonTasks severity="warning" enabled="true" outputDir="${antlint.test.dir}/data/output"/>
|
|
207 |
</hlm:antlint>
|
|
208 |
<au:assertFileExists file="${antlint.test.dir}/data/output/python/target0_check-prop-in-pythontask.py"/>
|
|
209 |
<au:assertFileExists file="${antlint.test.dir}/data/output/python/target0_check-script-size.py"/>
|
|
210 |
</target>
|
|
211 |
|
|
212 |
<target name="test-check-scriptdef-name-attributes">
|
|
213 |
<hlm:antlint>
|
|
214 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
215 |
<include name="sample.antlib.xml"/>
|
|
216 |
</fileset>
|
|
217 |
<hlm:checkScriptDefNameAttributes severity="warning" enabled="true" />
|
|
218 |
</hlm:antlint>
|
|
219 |
<au:assertLogContains text="WARNING: Scriptdef check-scriptdef-attributes does not have attribute target" level="info"/>
|
|
220 |
</target>
|
|
221 |
|
|
222 |
|
|
223 |
<target name="test-check-scriptdef-style">
|
|
224 |
<hlm:antlint>
|
|
225 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
226 |
<include name="sample.antlib.xml"/>
|
|
227 |
</fileset>
|
|
228 |
<hlm:checkScriptDefStyle severity="warning" enabled="true" />
|
|
229 |
</hlm:antlint>
|
|
230 |
<au:assertLogContains text="WARNING: Scriptdef check-scriptdef-style doesn't reference attributes directly, poor style" level="info"/>
|
|
231 |
</target>
|
|
232 |
|
|
233 |
<target name="test-check-scriptdef">
|
|
234 |
<hlm:antlint>
|
|
235 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
236 |
<include name="sample.antlib.xml"/>
|
|
237 |
</fileset>
|
|
238 |
<hlm:checkScriptDef severity="warning" enabled="true" outputDir="${antlint.test.dir}/data/output"/>
|
|
239 |
</hlm:antlint>
|
|
240 |
<au:assertLogContains text="WARNING: Scriptdef check-scriptdef does not use attr2" level="info"/>
|
|
241 |
<au:assertLogContains text="WARNING: Scriptdef check-scriptdef-beanshell does not use attr2" level="info"/>
|
|
242 |
</target>
|
|
243 |
|
|
244 |
<target name="test-check-duplicate-names">
|
|
245 |
<hlm:antlint>
|
|
246 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
247 |
<include name="*.xml"/>
|
|
248 |
<include name="*.ant.xml"/>
|
|
249 |
<include name="build.xml"/>
|
587
|
250 |
<include name="*.antlib.xml"/>
|
|
251 |
</fileset>
|
588
|
252 |
<hlm:checkDuplicateNames enabled="true" severity="warning"/>
|
587
|
253 |
</hlm:antlint>
|
|
254 |
</target>
|
588
|
255 |
|
|
256 |
<target name="test-check-filename">
|
|
257 |
<hlm:antlint>
|
|
258 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
259 |
<include name="invalid.build.xml"/>
|
|
260 |
</fileset>
|
|
261 |
<hlm:checkFileName severity="warning" enabled="true" regexp="^build.xml$|ant.xml$|antlib.xml$" />
|
|
262 |
</hlm:antlint>
|
|
263 |
<au:assertLogContains text="WARNING: INVALID File Name:" level="info"/>
|
|
264 |
</target>
|
|
265 |
|
|
266 |
<target name="test-antlint-failonerror-false">
|
|
267 |
<hlm:antlint failonerror="false">
|
|
268 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
269 |
<include name="*.xml"/>
|
|
270 |
<include name="*.ant.xml"/>
|
|
271 |
<include name="build.xml"/>
|
|
272 |
<include name="*.antlib.xml"/>
|
|
273 |
</fileset>
|
|
274 |
<hlm:checkTabCharacter severity="error" enabled="true"/>
|
|
275 |
<hlm:checkProjectName enabled="true" severity="error" regexp="([a-z0-9[\\d\\.\\_\\-]]*)"/>
|
|
276 |
<hlm:checkScriptDefNameAttributes severity="error" enabled="true" />
|
|
277 |
</hlm:antlint>
|
|
278 |
<au:assertLogContains text="ERROR: Scriptdef check-scriptdef-attributes does not have attribute target" level="info"/>
|
|
279 |
<au:assertLogContains text="ERROR: Project name not specified!" level="info"/>
|
|
280 |
</target>
|
|
281 |
|
|
282 |
<target name="test-antlint-failonerror-true">
|
|
283 |
<au:expectfailure>
|
|
284 |
<hlm:antlint>
|
|
285 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
286 |
<include name="*.xml"/>
|
|
287 |
<include name="*.ant.xml"/>
|
|
288 |
<include name="build.xml"/>
|
|
289 |
<include name="*.antlib.xml"/>
|
|
290 |
</fileset>
|
|
291 |
<hlm:checkTabCharacter severity="error" enabled="true"/>
|
|
292 |
<hlm:checkProjectName enabled="true" severity="error" regexp="([a-z0-9[\\d\\.\\_\\-]]*)"/>
|
|
293 |
<hlm:checkScriptDefNameAttributes severity="error" enabled="true" />
|
|
294 |
</hlm:antlint>
|
|
295 |
</au:expectfailure>
|
|
296 |
<au:assertLogContains text="ERROR: Scriptdef check-scriptdef-attributes does not have attribute target" level="info"/>
|
|
297 |
<au:assertLogContains text="ERROR: Project name not specified!" level="info"/>
|
|
298 |
</target>
|
|
299 |
|
|
300 |
<target name="test-antlint-console-and-xml-reporting">
|
|
301 |
<au:expectfailure>
|
|
302 |
<hlm:antlint>
|
|
303 |
<fileset id="antlint.files" dir="${antlint.test.dir}/data">
|
|
304 |
<include name="*.xml"/>
|
|
305 |
<include name="*.ant.xml"/>
|
|
306 |
<include name="build.xml"/>
|
|
307 |
<include name="*.antlib.xml"/>
|
|
308 |
</fileset>
|
|
309 |
<hlm:checkTabCharacter severity="error" enabled="true"/>
|
|
310 |
<hlm:checkProjectName enabled="true" severity="error" regexp="([a-z0-9[\\d\\.\\_\\-]]*)"/>
|
|
311 |
<hlm:checkScriptDefNameAttributes severity="error" enabled="true" />
|
|
312 |
|
|
313 |
<!-- reporters -->
|
|
314 |
<hlm:antlintCheckstyleReporter file="${antlint.test.dir}/data/output/report.xml" />
|
|
315 |
<hlm:antlintConsoleReporter />
|
|
316 |
</hlm:antlint>
|
|
317 |
</au:expectfailure>
|
|
318 |
<au:assertLogContains text="ERROR: Scriptdef check-scriptdef-attributes does not have attribute target" level="info"/>
|
|
319 |
<au:assertLogContains text="ERROR: Project name not specified!" level="info"/>
|
|
320 |
<au:assertFileExists file="${antlint.test.dir}/data/output/report.xml" />
|
|
321 |
<loadfile property="report.xml" srcfile="${antlint.test.dir}/data/output/report.xml" />
|
|
322 |
<echo>${report.xml}</echo>
|
|
323 |
<au:assertTrue>
|
|
324 |
<and>
|
|
325 |
<contains string="${report.xml}" substring="<error" />
|
|
326 |
<contains string="${report.xml}" substring="Scriptdef check-scriptdef-attributes does not have attribute target" />
|
|
327 |
<contains string="${report.xml}" substring="Project name not specified!" />
|
|
328 |
</and>
|
|
329 |
</au:assertTrue>
|
|
330 |
</target>
|
|
331 |
|
628
|
332 |
<target name="test-check-try-catch-block-with-empty-catch-block">
|
|
333 |
<au:expectfailure>
|
|
334 |
<hlm:antlint>
|
|
335 |
<fileset file="${antlint.test.dir}/data/sample.ant.xml"/>
|
|
336 |
<hlm:checkTryCatchBlock severity="error" />
|
|
337 |
</hlm:antlint>
|
|
338 |
</au:expectfailure>
|
|
339 |
<au:assertLogContains text="trycatch> block found without " level="info"/>
|
|
340 |
</target>
|
|
341 |
|
|
342 |
<target name="test-check-try-catch-block-with-multiple-catch-block">
|
|
343 |
<au:expectfailure>
|
|
344 |
<hlm:antlint>
|
|
345 |
<fileset file="${antlint.test.dir}/data/sample.ant.xml"/>
|
|
346 |
<hlm:checkTryCatchBlock severity="error" />
|
|
347 |
</hlm:antlint>
|
|
348 |
</au:expectfailure>
|
|
349 |
<au:assertLogContains text="trycatch> block found with 2 " level="info"/>
|
|
350 |
</target>
|
587
|
351 |
</project>
|