Skip to content

Commit

Permalink
Issue checkstyle#7855: Resolve Pitest Issues - IllegalImportCheck (2)
Browse files Browse the repository at this point in the history
  • Loading branch information
harsh-kukreja committed Mar 27, 2020
2 parents aed53d1 + dabbeba commit a6bc654
Show file tree
Hide file tree
Showing 49 changed files with 1,484 additions and 188 deletions.
2 changes: 0 additions & 2 deletions .ci/pitest.sh
Expand Up @@ -72,7 +72,6 @@ pitest-imports)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"CustomImportOrderCheck.java.html:<td class='covered'><pre><span class='survived'> if (bestMatch.group.equals(NON_GROUP_RULE_GROUP)) {</span></pre></td></tr>"
"IllegalImportCheck.java.html:<td class='covered'><pre><span class='survived'> if (regexp) {</span></pre></td></tr>"
"IllegalImportCheck.java.html:<td class='covered'><pre><span class='survived'> if (!result) {</span></pre></td></tr>"
"ImportControlLoader.java.html:<td class='covered'><pre><span class='survived'> else if (ALLOW_ELEMENT_NAME.equals(qName) || &#34;disallow&#34;.equals(qName)) {</span></pre></td></tr>"
"ImportOrderCheck.java.html:<td class='covered'><pre><span class='survived'> else if (matcher.start() == bestPos &#38;&#38; matcher.end() &#62; bestEnd) {</span></pre></td></tr>"
Expand All @@ -86,7 +85,6 @@ pitest-imports)
"PkgImportControl.java.html:<td class='covered'><pre><span class='survived'> if (regex || parent.regex) {</span></pre></td></tr>"
"PkgImportControl.java.html:<td class='covered'><pre><span class='survived'> if (regex) {</span></pre></td></tr>"
"PkgImportRule.java.html:<td class='covered'><pre><span class='survived'> if (isRegExp()) {</span></pre></td></tr>"
"RedundantImportCheck.java.html:<td class='covered'><pre><span class='survived'> else if (pkgName != null &#38;&#38; isFromPackage(imp.getText(), pkgName)) {</span></pre></td></tr>"
"UnusedImportsCheck.java.html:<td class='covered'><pre><span class='survived'> if (collect) {</span></pre></td></tr>"
);
checkPitestReport "${ignoredItems[@]}"
Expand Down
5 changes: 1 addition & 4 deletions .ci/travis/travis.sh
Expand Up @@ -3,10 +3,7 @@
set -e

removeFolderWithProtectedFiles() {
cd "$1"
find . -delete
cd ..
rmdir "$1"
find $1 -delete
}

case $1 in
Expand Down
14 changes: 14 additions & 0 deletions .ci/wercker.sh
Expand Up @@ -316,6 +316,20 @@ no-exception-spotbugs)
rm -rf contribution
;;

no-exception-spoon)
CS_POM_VERSION=$(mvn -e -q -Dexec.executable='echo' -Dexec.args='${project.version}' \
--non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
echo CS_version: ${CS_POM_VERSION}
checkout_from https://github.com/checkstyle/contribution.git
cd .ci-temp/contribution/checkstyle-tester
sed -i.'' 's/^guava/#guava/' projects-to-test-on.properties
sed -i.'' 's/#spoon/spoon/' projects-to-test-on.properties
groovy ./launch.groovy --listOfProjects projects-for-wercker.properties \
--config checks-nonjavadoc-error.xml --checkstyleVersion ${CS_POM_VERSION}
cd ../../
rm -rf contribution
;;

no-exception-spring-framework)
CS_POM_VERSION=$(mvn -e -q -Dexec.executable='echo' -Dexec.args='${project.version}' \
--non-recursive org.codehaus.mojo:exec-maven-plugin:1.3.1:exec)
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -204,7 +204,7 @@
<maven.pmd.plugin.version>3.13.0</maven.pmd.plugin.version>
<pmd.version>6.21.0</pmd.version>
<maven.jacoco.plugin.version>0.8.5</maven.jacoco.plugin.version>
<powermock.version>2.0.5</powermock.version>
<powermock.version>2.0.6</powermock.version>
<saxon.version>9.9.1-7</saxon.version>
<maven.checkstyle.plugin.version>3.1.1</maven.checkstyle.plugin.version>
<maven.sevntu.checkstyle.plugin.version>1.37.1</maven.sevntu.checkstyle.plugin.version>
Expand All @@ -219,7 +219,7 @@
<pitest.plugin.threads>4</pitest.plugin.threads>
<pitest.junit5.plugin.version>0.10</pitest.junit5.plugin.version>
<sonar.test.exclusions>**/test/resources/**/*,**/it/resources/**/*</sonar.test.exclusions>
<junit.version>5.6.0</junit.version>
<junit.version>5.6.1</junit.version>
</properties>

<dependencies>
Expand Down
Expand Up @@ -38,44 +38,44 @@ public void testNeedBraces() throws Exception {
final String messageKey = "needBraces";

final String[] expected = {
"29: " + getCheckMessage(clazz, messageKey, "do"),
"41: " + getCheckMessage(clazz, messageKey, "while"),
"42: " + getCheckMessage(clazz, messageKey, "while"),
"44: " + getCheckMessage(clazz, messageKey, "while"),
"45: " + getCheckMessage(clazz, messageKey, "if"),
"58: " + getCheckMessage(clazz, messageKey, "for"),
"59: " + getCheckMessage(clazz, messageKey, "for"),
"61: " + getCheckMessage(clazz, messageKey, "for"),
"63: " + getCheckMessage(clazz, messageKey, "if"),
"82: " + getCheckMessage(clazz, messageKey, "if"),
"83: " + getCheckMessage(clazz, messageKey, "if"),
"85: " + getCheckMessage(clazz, messageKey, "if"),
"87: " + getCheckMessage(clazz, messageKey, "else"),
"89: " + getCheckMessage(clazz, messageKey, "if"),
"97: " + getCheckMessage(clazz, messageKey, "else"),
"99: " + getCheckMessage(clazz, messageKey, "if"),
"100: " + getCheckMessage(clazz, messageKey, "if"),
"126: " + getCheckMessage(clazz, messageKey, "while"),
"129: " + getCheckMessage(clazz, messageKey, "do"),
"135: " + getCheckMessage(clazz, messageKey, "if"),
"138: " + getCheckMessage(clazz, messageKey, "if"),
"139: " + getCheckMessage(clazz, messageKey, "else"),
"144: " + getCheckMessage(clazz, messageKey, "for"),
"147: " + getCheckMessage(clazz, messageKey, "for"),
"157: " + getCheckMessage(clazz, messageKey, "while"),
"160: " + getCheckMessage(clazz, messageKey, "do"),
"166: " + getCheckMessage(clazz, messageKey, "if"),
"169: " + getCheckMessage(clazz, messageKey, "if"),
"170: " + getCheckMessage(clazz, messageKey, "else"),
"175: " + getCheckMessage(clazz, messageKey, "for"),
"178: " + getCheckMessage(clazz, messageKey, "for"),
"189: " + getCheckMessage(clazz, messageKey, "while"),
"192: " + getCheckMessage(clazz, messageKey, "do"),
"198: " + getCheckMessage(clazz, messageKey, "if"),
"201: " + getCheckMessage(clazz, messageKey, "if"),
"202: " + getCheckMessage(clazz, messageKey, "else"),
"207: " + getCheckMessage(clazz, messageKey, "for"),
"210: " + getCheckMessage(clazz, messageKey, "for"),
"29:9: " + getCheckMessage(clazz, messageKey, "do"),
"41:9: " + getCheckMessage(clazz, messageKey, "while"),
"42:9: " + getCheckMessage(clazz, messageKey, "while"),
"44:9: " + getCheckMessage(clazz, messageKey, "while"),
"45:13: " + getCheckMessage(clazz, messageKey, "if"),
"58:9: " + getCheckMessage(clazz, messageKey, "for"),
"59:9: " + getCheckMessage(clazz, messageKey, "for"),
"61:9: " + getCheckMessage(clazz, messageKey, "for"),
"63:13: " + getCheckMessage(clazz, messageKey, "if"),
"82:9: " + getCheckMessage(clazz, messageKey, "if"),
"83:9: " + getCheckMessage(clazz, messageKey, "if"),
"85:9: " + getCheckMessage(clazz, messageKey, "if"),
"87:9: " + getCheckMessage(clazz, messageKey, "else"),
"89:9: " + getCheckMessage(clazz, messageKey, "if"),
"97:9: " + getCheckMessage(clazz, messageKey, "else"),
"99:9: " + getCheckMessage(clazz, messageKey, "if"),
"100:13: " + getCheckMessage(clazz, messageKey, "if"),
"126:9: " + getCheckMessage(clazz, messageKey, "while"),
"129:9: " + getCheckMessage(clazz, messageKey, "do"),
"135:9: " + getCheckMessage(clazz, messageKey, "if"),
"138:9: " + getCheckMessage(clazz, messageKey, "if"),
"139:9: " + getCheckMessage(clazz, messageKey, "else"),
"144:9: " + getCheckMessage(clazz, messageKey, "for"),
"147:9: " + getCheckMessage(clazz, messageKey, "for"),
"157:13: " + getCheckMessage(clazz, messageKey, "while"),
"160:13: " + getCheckMessage(clazz, messageKey, "do"),
"166:13: " + getCheckMessage(clazz, messageKey, "if"),
"169:13: " + getCheckMessage(clazz, messageKey, "if"),
"170:13: " + getCheckMessage(clazz, messageKey, "else"),
"175:13: " + getCheckMessage(clazz, messageKey, "for"),
"178:13: " + getCheckMessage(clazz, messageKey, "for"),
"189:13: " + getCheckMessage(clazz, messageKey, "while"),
"192:13: " + getCheckMessage(clazz, messageKey, "do"),
"198:13: " + getCheckMessage(clazz, messageKey, "if"),
"201:13: " + getCheckMessage(clazz, messageKey, "if"),
"202:13: " + getCheckMessage(clazz, messageKey, "else"),
"207:13: " + getCheckMessage(clazz, messageKey, "for"),
"210:13: " + getCheckMessage(clazz, messageKey, "for"),
};

final Configuration checkConfig = getModuleConfig("NeedBraces");
Expand Down
@@ -0,0 +1,85 @@
////////////////////////////////////////////////////////////////////////////////
// checkstyle: Checks Java source code for adherence to a set of rules.
// Copyright (C) 2001-2020 the original author or authors.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
////////////////////////////////////////////////////////////////////////////////

package org.checkstyle.suppressionxpathfilter;

import java.io.File;
import java.util.Collections;
import java.util.List;

import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.checks.coding.IllegalCatchCheck;

public class XpathRegressionIllegalCatchTest extends AbstractXpathTestSupport {

private final String checkName = IllegalCatchCheck.class.getSimpleName();

@Override
protected String getCheckName() {
return checkName;
}

@Test
public void testOne() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionIllegalCatchOne.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(IllegalCatchCheck.class);

final String[] expectedViolation = {
"6:11: " + getCheckMessage(IllegalCatchCheck.class,
IllegalCatchCheck.MSG_KEY, "RuntimeException"),
};

final List<String> expectedXpathQueries = Collections.singletonList(
"/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionIllegalCatchOne']]/OBJBLOCK"
+ "/METHOD_DEF[./IDENT[@text='fun']]/SLIST"
+ "/LITERAL_TRY/LITERAL_CATCH"
);

runVerifications(moduleConfig, fileToProcess, expectedViolation,
expectedXpathQueries);
}

@Test
public void testTwo() throws Exception {
final File fileToProcess =
new File(getPath("SuppressionXpathRegressionIllegalCatchTwo.java"));

final DefaultConfiguration moduleConfig =
createModuleConfig(IllegalCatchCheck.class);

final String[] expectedViolation = {
"16:11: " + getCheckMessage(IllegalCatchCheck.class,
IllegalCatchCheck.MSG_KEY, "java.lang.RuntimeException"),
};

final List<String> expectedXpathQueries = Collections.singletonList(
"/CLASS_DEF[./IDENT[@text='SuppressionXpathRegressionIllegalCatchTwo']]/OBJBLOCK"
+ "/METHOD_DEF[./IDENT[@text='methodTwo']]/SLIST"
+ "/LITERAL_TRY/LITERAL_CATCH"
);

runVerifications(moduleConfig, fileToProcess, expectedViolation,
expectedXpathQueries);
}
}

0 comments on commit a6bc654

Please sign in to comment.