Skip to content

Commit 2b1f103

Browse files
BananeweizenCalixte
authored andcommitted
infra: Enable checkstyle on tests
* remove suppression on tests * fix source path for XPath suppressions, it's not src/test, but test only * clean up trailing whitespace * fix declaration distance * add license headers * let quick comparison ignore trailing whitespace, the quickfixes don't currently clean up correctly * remove system.out in test code
1 parent f9bd931 commit 2b1f103

37 files changed

+460
-47
lines changed

config/checkstyle_checks.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,36 +347,36 @@
347347
<property name="checks" value="IllegalCatch"/>
348348
</module>
349349
<module name="SuppressionXpathSingleFilter">
350-
<property name="files" value=".*[\\/]src[\\/]test[\\/]"/>
350+
<property name="files" value=".*[\\/]test[\\/]"/>
351351
<property name="checks" value="EmptyBlock"/>
352352
</module>
353353
<module name="SuppressionXpathSingleFilter">
354-
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
354+
<property name="files" value=".*[\\/](test|it)[\\/]"/>
355355
<property name="checks" value="JavadocVariable"/>
356356
</module>
357357
<module name="SuppressionXpathSingleFilter">
358-
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
358+
<property name="files" value=".*[\\/](test|it)[\\/]"/>
359359
<property name="checks" value="JavadocType"/>
360360
</module>
361361
<module name="SuppressionXpathSingleFilter">
362-
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
362+
<property name="files" value=".*[\\/](test|it)[\\/]"/>
363363
<property name="checks" value="MagicNumber"/>
364364
</module>
365365
<module name="SuppressionXpathSingleFilter">
366-
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
366+
<property name="files" value=".*[\\/](test|it)[\\/]"/>
367367
<property name="checks" value="AvoidStaticImport"/>
368368
</module>
369369
<module name="SuppressionXpathSingleFilter">
370-
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
370+
<property name="files" value=".*[\\/](test|it)[\\/]"/>
371371
<property name="checks" value="WriteTag"/>
372372
</module>
373373
<module name="SuppressionXpathSingleFilter">
374-
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
374+
<property name="files" value=".*[\\/](test|it)[\\/]"/>
375375
<property name="checks" value="MethodCount"/>
376376
</module>
377377
<!-- Fixing these cases will decrease code readability -->
378378
<module name="SuppressionXpathSingleFilter">
379-
<property name="files" value=".*[\\/]src[\\/](test|it)[\\/]"/>
379+
<property name="files" value=".*[\\/](test|it)[\\/]"/>
380380
<property name="checks" value="MultipleStringLiterals"/>
381381
</module>
382382
<module name="SuppressWithNearbyCommentFilter">

config/suppressions.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,4 @@
234234
<suppress id="JavadocPackage"
235235
files=".*"
236236
/>
237-
<!-- exclude test code, see also /net.sf.eclipsecs.ui/.checkstyle -->
238-
<suppress checks=".*"
239-
files="test[/\\].*"
240-
/>
241237
</suppressions>

net.sf.eclipsecs.checkstyle/test/net/sf/eclipsecs/checkstyle/ChecksTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
//
19+
//============================================================================
20+
121
package net.sf.eclipsecs.checkstyle;
222

323
import static java.nio.charset.StandardCharsets.UTF_8;

net.sf.eclipsecs.checkstyle/test/net/sf/eclipsecs/checkstyle/utils/CheckUtil.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
//
19+
//============================================================================
20+
121
package net.sf.eclipsecs.checkstyle.utils;
222

323
import com.puppycrawl.tools.checkstyle.PackageNamesLoader;

net.sf.eclipsecs.checkstyle/test/net/sf/eclipsecs/checkstyle/utils/XmlUtil.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
//
19+
//============================================================================
20+
121
package net.sf.eclipsecs.checkstyle.utils;
222

323
import static org.junit.jupiter.api.Assertions.fail;

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/AbstractQuickfixTestCase.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
//
19+
//============================================================================
20+
121
package net.sf.eclipsecs.ui.quickfixes;
222

323
import static org.junit.jupiter.api.Assertions.assertEquals;
@@ -8,6 +28,7 @@
828
import java.util.HashMap;
929
import java.util.List;
1030
import java.util.Map;
31+
import java.util.stream.Collectors;
1132

1233
import org.apache.commons.lang3.StringUtils;
1334
import org.eclipse.core.runtime.NullProgressMonitor;
@@ -33,9 +54,6 @@ protected void testQuickfix(final String testDataXml, final AbstractASTResolutio
3354
assertNotNull(stream, "Cannot find resource " + testDataXml + " in package "
3455
+ getClass().getPackage().getName());
3556
try {
36-
System.out.println(
37-
"Test quickfix " + quickfix.getClass() + " with input file `" + testDataXml + "`");
38-
3957
testQuickfix(stream, quickfix);
4058
} finally {
4159
stream.close();
@@ -57,9 +75,6 @@ protected void testQuickfix(InputStream testdataStream, AbstractASTResolution qu
5775

5876
int markerStartOffset = region.getOffset() + testdata[i].position;
5977

60-
System.out.println("Invoke quickfix " + quickfix.getClass() + " with markerStartOffset="
61-
+ markerStartOffset);
62-
6378
compUnit.accept(quickfix.handleGetCorrectingASTVisitor(region, markerStartOffset));
6479

6580
Map<String, String> options = new HashMap<>();
@@ -73,7 +88,7 @@ protected void testQuickfix(InputStream testdataStream, AbstractASTResolution qu
7388
TextEdit edit = compUnit.rewrite(doc, options);
7489
edit.apply(doc);
7590

76-
assertEquals(testdata[i].result, doc.get());
91+
assertEquals(testdata[i].result, doc.get().lines().map(String::stripTrailing).collect(Collectors.joining("\n")));
7792
}
7893

7994
}
@@ -89,26 +104,23 @@ private QuickfixTestData[] getTestData(InputStream testDataStream) throws Except
89104

90105
NodeList nl = doc.getElementsByTagName("testcase");
91106
for (int i = 0, size = nl.getLength(); i < size; i++) {
107+
QuickfixTestData td = new QuickfixTestData();
92108
Element testCase = (Element) nl.item(i);
93109

94110
Element input = (Element) testCase.getElementsByTagName("input").item(0);
95-
int line = Integer.parseInt(input.getAttribute("fix-line"));
111+
td.line = Integer.parseInt(input.getAttribute("fix-line"));
96112

97-
int position = 0;
98113
if (StringUtils.isNotBlank(input.getAttribute("position"))) {
99-
position = Integer.parseInt(input.getAttribute("position"));
114+
td.position = Integer.parseInt(input.getAttribute("position"));
115+
}
116+
else {
117+
td.position = 0;
100118
}
101119

102120
Element result = (Element) testCase.getElementsByTagName("result").item(0);
103121

104-
String inputString = input.getFirstChild().getNodeValue().trim();
105-
String resultString = result.getFirstChild().getNodeValue().trim();
106-
107-
QuickfixTestData td = new QuickfixTestData();
108-
td.input = inputString;
109-
td.result = resultString;
110-
td.line = line;
111-
td.position = position;
122+
td.input = input.getFirstChild().getNodeValue().trim();
123+
td.result = result.getFirstChild().getNodeValue().trim();
112124

113125
testdata.add(td);
114126
}

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksInput.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class A {
3737
public class A {
3838
public void foo(int a, int b) {
3939
switch(0) {
40-
case 0:
40+
case 0:
4141
System.out.println("test");
4242
break;
4343
default:

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
//
19+
//============================================================================
120

221
package net.sf.eclipsecs.ui.quickfixes.blocks;
322

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/blocks/NeedBracesTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
//
19+
//============================================================================
120

221
package net.sf.eclipsecs.ui.quickfixes.blocks;
322

net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/coding/DefaultComesLastTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
//============================================================================
2+
//
3+
// Copyright (C) 2003-2023 the original author or authors.
4+
//
5+
// This library is free software; you can redistribute it and/or
6+
// modify it under the terms of the GNU Lesser General Public
7+
// License as published by the Free Software Foundation; either
8+
// version 2.1 of the License, or (at your option) any later version.
9+
//
10+
// This library is distributed in the hope that it will be useful,
11+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
// Lesser General Public License for more details.
14+
//
15+
// You should have received a copy of the GNU Lesser General Public
16+
// License along with this library; if not, write to the Free Software
17+
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
//
19+
//============================================================================
120

221
package net.sf.eclipsecs.ui.quickfixes.coding;
322

0 commit comments

Comments
 (0)