Skip to content

Commit

Permalink
Issue #13345: enable example test for SeverityMatchFilterExamplesTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Kexin2000 committed Apr 11, 2024
1 parent ffbeac5 commit f9f877a
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 18 deletions.
Expand Up @@ -629,12 +629,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
Expand Up @@ -368,6 +368,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
Expand Up @@ -19,24 +19,26 @@

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() {
return "com/puppycrawl/tools/checkstyle/filters/severitymatchfilter";
}

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

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

verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
}
}
@@ -0,0 +1,24 @@
/*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
}
// xdoc section -- end

This file was deleted.

17 changes: 17 additions & 0 deletions src/xdocs/filters/severitymatchfilter.xml
Expand Up @@ -55,12 +55,29 @@
</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;
&lt;/module&gt;
&lt;/module&gt;
</source>
<p id="Example1-code">
Code Example:
</p>
<source>
public class Example1 {

public void method1(int V1){} // ok, ParameterNameCheck's severity is info

public void Method2(){} // violation
}
</source>
</subsection>
<subsection name="Example of Usage" id="Example_of_Usage">
<ul>
Expand Down
10 changes: 9 additions & 1 deletion src/xdocs/filters/severitymatchfilter.xml.template
Expand Up @@ -36,9 +36,17 @@
</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>
<p id="Example1-code">
Code Example:
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/filters/severitymatchfilter/Example1.java"/>
<param name="type" value="code"/>
</macro>
</subsection>
<subsection name="Example of Usage" id="Example_of_Usage">
<ul>
Expand Down

0 comments on commit f9f877a

Please sign in to comment.