Skip to content

Commit

Permalink
Issue #13345: Enabled SeverityMatch example tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SteLeo1602 authored and romani committed Jun 17, 2024
1 parent 94d72b8 commit 8408c30
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,21 @@ private static String getMessageBundle(String className) {
final String messageBundle;
final String messages = "messages";
final int endIndex = className.lastIndexOf('.');
final Map<String, String> messageBundleMappings = new HashMap<>();
messageBundleMappings.put("SeverityMatchFilterExamplesTest",
"com.puppycrawl.tools.checkstyle.checks.naming.messages");

if (endIndex < 0) {
messageBundle = messages;
}
else {
final String packageName = className.substring(0, endIndex);
messageBundle = packageName + "." + messages;
if ("com.puppycrawl.tools.checkstyle.filters".equals(packageName)) {
messageBundle = messageBundleMappings.get(className.substring(endIndex + 1));
}
else {
messageBundle = packageName + "." + messages;
}
}
return messageBundle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,10 @@ private static String getFullyQualifiedClassName(String filePath, String moduleN
"com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck");
moduleMappings.put("LineLength",
"com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck");
moduleMappings.put("ParameterName",
"com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck");
moduleMappings.put("MethodName",
"com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck");

String fullyQualifiedClassName;
if (moduleMappings.containsKey(moduleName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package com.puppycrawl.tools.checkstyle.filters;

import org.junit.jupiter.api.Disabled;
import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;

import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;

@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
public class SeverityMatchFilterExamplesTest extends AbstractExamplesModuleTestSupport {
@Override
protected String getPackageLocation() {
Expand All @@ -33,10 +33,12 @@ protected String getPackageLocation() {

@Test
public void testExample1() throws Exception {
final String[] expected = {
final String pattern = "^[a-z][a-zA-Z0-9]*$";

final String[] expected = {
"21:15: " + getCheckMessage(MSG_INVALID_PATTERN, "Method2", pattern),
};

verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*xml
<module name="Checker">
<module name="TreeWalker">
<module name="ParameterName">
<property name="severity" value="info"/>
</module>
<module name="MethodName"/>
</module>
<module name="SeverityMatchFilter">
<property name="severity" value="info"/>
<property name="acceptOnMatch" value="false"/>
</module>
</module>
*/
package com.puppycrawl.tools.checkstyle.filters.severitymatchfilter;

// xdoc section -- start
public class Example1 {
public void method1(int V1){} // ok, ParameterNameCheck's severity is info

public void Method2(){} // violation, 'must match pattern'
}
// xdoc section -- end

This file was deleted.

6 changes: 6 additions & 0 deletions src/xdocs/filters/severitymatchfilter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@
</p>
<source>
&lt;module name=&quot;Checker&quot;&gt;
&lt;module name=&quot;TreeWalker&quot;&gt;
&lt;module name=&quot;ParameterName&quot;&gt;
&lt;property name=&quot;severity&quot; value=&quot;info&quot;/&gt;
&lt;/module&gt;
&lt;module name=&quot;MethodName&quot;/&gt;
&lt;/module&gt;
&lt;module name=&quot;SeverityMatchFilter&quot;&gt;
&lt;property name=&quot;severity&quot; value=&quot;info&quot;/&gt;
&lt;property name=&quot;acceptOnMatch&quot; value=&quot;false&quot;/&gt;
Expand Down
2 changes: 1 addition & 1 deletion src/xdocs/filters/severitymatchfilter.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/filters/severitymatchfilter/Example1.txt"/>
value="resources/com/puppycrawl/tools/checkstyle/filters/severitymatchfilter/Example1.java"/>
<param name="type" value="config"/>
</macro>
</subsection>
Expand Down

0 comments on commit 8408c30

Please sign in to comment.