Navigation Menu

Skip to content

Commit

Permalink
Issue #6635: increase mutation coverage for api profile to 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
rnveach committed Apr 5, 2019
1 parent 2be5521 commit c2ba4af
Show file tree
Hide file tree
Showing 20 changed files with 973 additions and 39 deletions.
1 change: 1 addition & 0 deletions .ci/jsoref-spellchecker/whitelist.words
Expand Up @@ -8,6 +8,7 @@ abcun
abego
abstractcheck
abstractclassname
abstractfileset
abstractjavadoc
abstracttypeaware
ABx
Expand Down
14 changes: 1 addition & 13 deletions .ci/pitest.sh
Expand Up @@ -34,6 +34,7 @@ case $1 in
pitest-annotation|pitest-design \
|pitest-metrics|pitest-modifier|pitest-naming \
|pitest-sizes|pitest-whitespace \
|pitest-api \
|pitest-packagenamesloader \
|pitest-common-2|pitest-misc|pitest-xpath)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
Expand Down Expand Up @@ -92,19 +93,6 @@ pitest-filters)
checkPitestReport "${ignoredItems[@]}"
;;

pitest-api)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
"DetailAST.java.html:<td class='covered'><pre><span class='survived'> if (nextSibling != null) {</span></pre></td></tr>"
"DetailAST.java.html:<td class='covered'><pre><span class='survived'> if (TokenUtil.isCommentType(node.getType())) {</span></pre></td></tr>"
"FileContents.java.html:<td class='covered'><pre><span class='survived'> if (firstLine.contains(&#34;/**&#34;) &#38;&#38; !firstLine.contains(&#34;/**/&#34;)) {</span></pre></td></tr>"
"FileContents.java.html:<td class='covered'><pre><span class='survived'> if (hasIntersection) {</span></pre></td></tr>"
"FileText.java.html:<td class='covered'><pre><span class='survived'> if (lineBreaks == null) {</span></pre></td></tr>"
"FileText.java.html:<td class='covered'><pre><span class='survived'> if (lineNo &#60; lineBreakPositions.length) {</span></pre></td></tr>"
);
checkPitestReport "${ignoredItems[@]}"
;;

pitest-main)
mvn -e -P$1 clean test org.pitest:pitest-maven:mutationCoverage;
declare -a ignoredItems=(
Expand Down
3 changes: 2 additions & 1 deletion config/suppressions.xml
Expand Up @@ -79,7 +79,8 @@
files="(Checker|Main|CheckstyleAntTask|JavadocDetailNodeParser)\.java"/>
<suppress checks="ClassDataAbstractionCoupling"
files="(CheckerTest|AbstractModuleTestSupport|CheckstyleAntTaskTest|
|TranslationCheckTest|LocalizedMessageTest)\.java"/>
|TranslationCheckTest|LocalizedMessageTest|AbstractFileSetCheckTest|
|AbstractCheckTest|AutomaticBeanTest)\.java"/>
<suppress checks="ClassDataAbstractionCoupling" files="PropertyCacheFileTest\.java"/>
<suppress checks="ClassDataAbstractionCoupling"
files="XpathFileGeneratorAuditListenerTest\.java"/>
Expand Down
18 changes: 2 additions & 16 deletions pom.xml
Expand Up @@ -2863,26 +2863,12 @@
</targetClasses>
<targetTests>
<param>com.puppycrawl.tools.checkstyle.api.*</param>
<param>com.puppycrawl.tools.checkstyle.TreeWalkerTest</param>
<param>com.puppycrawl.tools.checkstyle.grammar.comments.CommentsTest</param>
<param>com.puppycrawl.tools.checkstyle.filefilters.*</param>
<param>com.puppycrawl.tools.checkstyle.filters.*</param>
<param>com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocMethodCheckTest</param>
<param>com.puppycrawl.tools.checkstyle.checks.imports.ImportControlCheckTest</param>
<param>com.puppycrawl.tools.checkstyle.checks.javadoc.WriteTagCheckTest</param>
<param>com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheckTest</param>
<param>
com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheckTest
</param>
<param>com.puppycrawl.tools.checkstyle.ConfigurationLoaderTest</param>
<param>com.puppycrawl.tools.checkstyle.CheckerTest</param>
<param>com.puppycrawl.tools.checkstyle.checks.TranslationCheckTest</param>
</targetTests>
<excludedTestClasses>
<param>*.Input*</param>
</excludedTestClasses>
<coverageThreshold>99</coverageThreshold>
<mutationThreshold>99</mutationThreshold>
<coverageThreshold>100</coverageThreshold>
<mutationThreshold>100</mutationThreshold>
<timeoutFactor>${pitest.plugin.timeout.factor}</timeoutFactor>
<timeoutConstant>${pitest.plugin.timeout.constant}</timeoutConstant>
<threads>${pitest.plugin.threads}</threads>
Expand Down
Expand Up @@ -202,12 +202,7 @@ private void setParent(DetailAST parent) {
do {
instance.clearBranchTokenTypes();
instance.parent = parent;
final DetailAST nextSibling = instance.getNextSibling();
if (nextSibling != null) {
nextSibling.previousSibling = instance;
}

instance = nextSibling;
instance = instance.getNextSibling();
} while (instance != null);
}

Expand Down
Expand Up @@ -21,16 +21,22 @@

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;

import java.io.File;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.SortedSet;

import org.junit.Test;

import com.puppycrawl.tools.checkstyle.AbstractPathTestSupport;
import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.utils.CommonUtil;

public class AbstractCheckTest extends AbstractPathTestSupport {
Expand Down Expand Up @@ -86,6 +92,53 @@ public int[] getRequiredTokens() {
CommonUtil.EMPTY_INT_ARRAY, check.getAcceptableTokens());
}

@Test
public void testCommentNodes() {
final AbstractCheck check = new AbstractCheck() {
@Override
public int[] getDefaultTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public int[] getAcceptableTokens() {
return getDefaultTokens();
}

@Override
public int[] getRequiredTokens() {
return getDefaultTokens();
}
};

assertFalse("unexpected result", check.isCommentNodesRequired());
}

@Test
public void testTokenNames() {
final AbstractCheck check = new AbstractCheck() {
@Override
public int[] getDefaultTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public int[] getAcceptableTokens() {
return getDefaultTokens();
}

@Override
public int[] getRequiredTokens() {
return getDefaultTokens();
}
};

check.setTokens("IDENT, EXPR, ELIST");
assertArrayEquals("unexpected result",
new String[] {"IDENT, EXPR, ELIST"},
check.getTokenNames().toArray());
}

@Test
public void testVisitToken() {
final VisitCounterCheck check = new VisitCounterCheck();
Expand Down Expand Up @@ -144,6 +197,32 @@ public int[] getRequiredTokens() {
assertEquals("Invalid tab width", tabWidth, check.getTabWidth());
}

@Test
public void testFileContents() {
final AbstractCheck check = new AbstractCheck() {
@Override
public int[] getDefaultTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public int[] getAcceptableTokens() {
return getDefaultTokens();
}

@Override
public int[] getRequiredTokens() {
return getDefaultTokens();
}
};
final String[] lines = {"test"};
final FileContents fileContents = new FileContents("fileName", lines);
check.setFileContents(fileContents);

assertSame("Invalid file contents", fileContents, check.getFileContents());
assertArrayEquals("Invalid lines", lines, check.getLines());
}

@Test
public void testGetClassLoader() {
final AbstractCheck check = new AbstractCheck() {
Expand Down Expand Up @@ -208,6 +287,56 @@ public void testClearMessages() {
assertEquals("Invalid message size", 0, check.getMessages().size());
}

@Test
public void testLineColumnLog() throws Exception {
final ViolationCheck check = new ViolationCheck();
check.configure(new DefaultConfiguration("check"));
final File file = new File("fileName");
final FileText theText = new FileText(file, Collections.singletonList("test123"));

check.setFileContents(new FileContents(theText));
check.clearMessages();
check.visitToken(null);

final SortedSet<LocalizedMessage> internalMessages = check.getMessages();

assertEquals("Internal message should only have 2", 2, internalMessages.size());

final Iterator<LocalizedMessage> iterator = internalMessages.iterator();

final LocalizedMessage firstMessage = iterator.next();
assertEquals("expected line", 1, firstMessage.getLineNo());
assertEquals("expected column", 0, firstMessage.getColumnNo());

final LocalizedMessage secondMessage = iterator.next();
assertEquals("expected line", 1, secondMessage.getLineNo());
assertEquals("expected column", 6, secondMessage.getColumnNo());
}

@Test
public void testAstLog() throws Exception {
final ViolationAstCheck check = new ViolationAstCheck();
check.configure(new DefaultConfiguration("check"));
final File file = new File("fileName");
final FileText theText = new FileText(file, Collections.singletonList("test123"));

check.setFileContents(new FileContents(theText));
check.clearMessages();

final DetailAST ast = new DetailAST();
ast.setLineNo(1);
ast.setColumnNo(4);
check.visitToken(ast);

final SortedSet<LocalizedMessage> internalMessages = check.getMessages();

assertEquals("Internal message should only have 1", 1, internalMessages.size());

final LocalizedMessage firstMessage = internalMessages.iterator().next();
assertEquals("expected line", 1, firstMessage.getLineNo());
assertEquals("expected column", 5, firstMessage.getColumnNo());
}

private static final class DummyAbstractCheck extends AbstractCheck {

private static final int[] DUMMY_ARRAY = {6};
Expand Down Expand Up @@ -262,4 +391,57 @@ public void visitToken(DetailAST ast) {
}
}

private static class ViolationCheck extends AbstractCheck {

private static final String MSG_KEY = "Violation.";

@Override
public int[] getDefaultTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public int[] getAcceptableTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public int[] getRequiredTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public void visitToken(DetailAST ast) {
log(1, 5, MSG_KEY);
log(1, MSG_KEY);
}

}

private static class ViolationAstCheck extends AbstractCheck {

private static final String MSG_KEY = "Violation.";

@Override
public int[] getDefaultTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public int[] getAcceptableTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public int[] getRequiredTokens() {
return CommonUtil.EMPTY_INT_ARRAY;
}

@Override
public void visitToken(DetailAST ast) {
log(ast, MSG_KEY);
}

}

}

0 comments on commit c2ba4af

Please sign in to comment.