Skip to content

Commit

Permalink
Issue checkstyle#6294: added test cases to kill indentation profile m…
Browse files Browse the repository at this point in the history
…utations
  • Loading branch information
rnveach committed Dec 22, 2018
1 parent d944cdd commit 0cf7377
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 2 deletions.
6 changes: 4 additions & 2 deletions config/pmd-test.xml
Expand Up @@ -63,7 +63,8 @@
JavadocTokenTypesTest.TokenValues contains several asserts as it checks each
token explicitly.
XdocsPagesTest.getModulePropertyExpectedTypeName is a complicated list of
different checks. -->
different checks.
IndentationCheckTest has a lot of cases. -->
<property name="violationSuppressXPath"
value="//ClassOrInterfaceDeclaration[@Image='JavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenValues']
Expand All @@ -72,7 +73,8 @@
| //ClassOrInterfaceDeclaration[@Image='XdocsPagesTest']
//MethodDeclaration[@Name='getModulePropertyExpectedTypeName']
| //ClassOrInterfaceDeclaration[@Image='GeneratedJavadocTokenTypesTest']
//MethodDeclaration[@Name='testTokenNumbers']"/>
//MethodDeclaration[@Name='testTokenNumbers']
| //ClassOrInterfaceDeclaration[@Image='IndentationCheckTest']"/>
</properties>
</rule>

Expand Down
Expand Up @@ -87,6 +87,7 @@ public void testCommentIsAtTheEndOfBlock() throws Exception {
"551: " + getCheckMessage(MSG_KEY_SINGLE, 550, 12, 8),
"557: " + getCheckMessage(MSG_KEY_SINGLE, 555, 0, 8),
"562: " + getCheckMessage(MSG_KEY_SINGLE, 561, 0, 8),
"577: " + getCheckMessage(MSG_KEY_SINGLE, 574, 0, 8),
};
final String testInputFile = "InputCommentsIndentationCommentIsAtTheEndOfBlock.java";
verify(checkConfig, getPath(testInputFile), expected);
Expand Down Expand Up @@ -116,6 +117,7 @@ public void testCommentIsInsideSwitchBlock() throws Exception {
"229: " + getCheckMessage(MSG_KEY_SINGLE, "228, 230", 6, "12, 12"),
"276: " + getCheckMessage(MSG_KEY_BLOCK, "275, 279", 11, "16, 12"),
"281: " + getCheckMessage(MSG_KEY_SINGLE, "280, 282", 11, "16, 12"),
"311: " + getCheckMessage(MSG_KEY_SINGLE, "312", 0, "8"),
};
final String testInputFile = "InputCommentsIndentationInSwitchBlock.java";
verify(checkConfig, getPath(testInputFile), expected);
Expand Down
Expand Up @@ -709,6 +709,11 @@ public void testInvalidSwitchWithChecker()
"93: " + getCheckMessage(MSG_ERROR, "switch rcurly", 10, 8),
"95: " + getCheckMessage(MSG_ERROR, "switch lcurly", 10, 8),
"96: " + getCheckMessage(MSG_ERROR, "switch rcurly", 6, 8),
"99: " + getCheckMessage(MSG_CHILD_ERROR, "case", 8, 12),
"100: " + getCheckMessage(MSG_ERROR, "if", 12, 16),
"101: " + getCheckMessage(MSG_CHILD_ERROR, "if", 16, 20),
"102: " + getCheckMessage(MSG_ERROR, "else", 12, 16),
"103: " + getCheckMessage(MSG_CHILD_ERROR, "else", 16, 20),
};
verifyWarns(checkConfig, fileName, expected);
}
Expand Down Expand Up @@ -1095,6 +1100,8 @@ public void testInvalidIfWithChecker()
"257: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
"258: " + getCheckMessage(MSG_CHILD_ERROR, "if", 0, 12),
"259: " + getCheckMessage(MSG_ERROR, "if rcurly", 0, 8),
"260: " + getCheckMessage(MSG_ERROR, "if", 0, 8),
"262: " + getCheckMessage(MSG_ERROR, "else", 0, 8),
};
verifyWarns(checkConfig, fileName, expected);
}
Expand Down Expand Up @@ -1203,6 +1210,18 @@ public void testInvalidForWithChecker()
"71: " + getCheckMessage(MSG_CHILD_ERROR, "for", 14, 16),
"72: " + getCheckMessage(MSG_CHILD_ERROR, "for", 10, 12),
"81: " + getCheckMessage(MSG_ERROR, "for rparen", 12, 8),
"86: " + getCheckMessage(MSG_ERROR, "method def modifier", 2, 4),
"87: " + getCheckMessage(MSG_ERROR, "for", 4, 8),
"88: " + getCheckMessage(MSG_CHILD_ERROR, "for", 8, 12),
"89: " + getCheckMessage(MSG_CHILD_ERROR, "for", 6, 12),
"90: " + getCheckMessage(MSG_CHILD_ERROR, "method call", 8, 16),
"92: " + getCheckMessage(MSG_ERROR, "for", 0, 8),
"93: " + getCheckMessage(MSG_ERROR, "for lparen", 0, 8),
"94: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
"95: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
"96: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
"97: " + getCheckMessage(MSG_ERROR, ";", 0, 4),
"98: " + getCheckMessage(MSG_CHILD_ERROR, "for", 0, 12),
};
verifyWarns(checkConfig, fileName, expected);
}
Expand Down Expand Up @@ -1700,6 +1719,17 @@ public void testPackageDeclaration3() throws Exception {
verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration3.java"), expected);
}

@Test
public void testPackageDeclaration4() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
checkConfig.addAttribute("tabWidth", "4");
final String[] expected = {
"2: " + getCheckMessage(MSG_ERROR, "com", 0, 4),
"3: " + getCheckMessage(MSG_ERROR, "checks", 0, 4),
};
verifyWarns(checkConfig, getPath("InputIndentationPackageDeclaration4.java"), expected);
}

@Test
public void testLambda1() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
Expand Down Expand Up @@ -1974,6 +2004,19 @@ public void testEmptyArray() throws Exception {
verifyWarns(checkConfig, getPath("InputIndentationEmptyArray.java"), expected);
}

@Test
public void testNewHandler() throws Exception {
final DefaultConfiguration checkConfig = createModuleConfig(IndentationCheck.class);
checkConfig.addAttribute("tabWidth", "4");
final String[] expected = {
"8: " + getCheckMessage(MSG_ERROR, "Object", 0, 12),
"10: " + getCheckMessage(MSG_ERROR, "(", 0, 12),
"13: " + getCheckMessage(MSG_CHILD_ERROR, "operator new", 0, 8),
"15: " + getCheckMessage(MSG_ERROR, "operator new lparen", 0, 8),
};
verifyWarns(checkConfig, getPath("InputIndentationNewHandler.java"), expected);
}

private static final class IndentAudit implements AuditListener {

private final IndentComment[] comments;
Expand Down
Expand Up @@ -570,6 +570,19 @@ void InputCommentsIndentationCommentIsAtTheEndOfBlock(String s) {
//comment
}

int foo76() {
return 0;
/* test
* test */
// test
}

void foo77() {
try {
/* CHECKSTYLE:OFF */} catch(Exception e) {
}
}

// We almost reached the end of the class here.
}
// The END of the class.
Expand Up @@ -302,4 +302,22 @@ public void foo13() {
break;
}
}

public void foo14() {
int a = 1;
switch (a) {
case 1:
default:
// violation
}
}

public void foo15() {
int a = 1;
switch (a) {
case 1:
default:
// violation
}
}
}
Expand Up @@ -83,4 +83,19 @@ private void method1() //indent:4 exp:4
} //indent:8 exp:8
} //indent:4 exp:4

public void doSmth() { //indent:2 exp:4 warn
for (int h //indent:4 exp:8 warn
: new int[] {}) { //indent:8 exp:12 warn
System.getProperty( //indent:6 exp:12 warn
"someString"); //indent:8 exp:16 warn
} //indent:8 exp:8
for //indent:0 exp:8 warn
( //indent:0 exp:8 warn
int i = 0 //indent:0 exp:12 warn
; //indent:0 exp:4 warn
i < 5 //indent:0 exp:12 warn
; //indent:0 exp:4 warn
i++) {} //indent:0 exp:12 warn
} //indent:4 exp:4

} //indent:0 exp:0
Expand Up @@ -257,6 +257,10 @@ public void parenIfTest() { //indent:4 exp:4
|| test) { //indent:0 exp:12 warn
System.getProperty("blah"); //indent:0 exp:12 warn
} //indent:0 exp:8 warn
if (test) //indent:0 exp:8 warn
System.getProperty("blah"); //indent:0 exp:0
else //indent:0 exp:8 warn
System.getProperty("blah"); //indent:0 exp:0

} //indent:4 exp:4

Expand Down
Expand Up @@ -95,6 +95,14 @@ private void method1() { //indent:4 exp:4
{ //indent:10 exp:8 warn
} //indent:6 exp:8 warn

switch (s) { //indent:8 exp:8
case 1: //indent:8 exp:12 warn
if (true) //indent:12 exp:16 warn
break; //indent:16 exp:20 warn
else //indent:12 exp:16 warn
break; //indent:16 exp:20 warn
} //indent:8 exp:8

} //indent:4 exp:4

} //indent:0 exp:0
@@ -0,0 +1,17 @@
package com.puppycrawl.tools.checkstyle.checks.indentation.indentation; //indent:0 exp:0

public class InputIndentationNewHandler //indent:0 exp:0
{ //indent:0 exp:0
public void test() { //indent:4 exp:4
Object o = new Object(); //indent:8 exp:8
Object p = new //indent:8 exp:8
Object(); //indent:0 exp:12 warn
Object q = new Object//indent:8 exp:8
(); //indent:0 exp:12 warn
o = new Integer("".indexOf("5")); //indent:8 exp:8
o = new //indent:8 exp:8
Integer("".indexOf("5")); //indent:0 exp:8 warn
o = new Integer//indent:8 exp:8
("".indexOf("5")); //indent:0 exp:8 warn
} //indent:4 exp:4
} //indent:0 exp:0
@@ -0,0 +1,5 @@
package//indent:0 exp:>=0
com.puppycrawl.tools.checkstyle.//indent:0 exp:4 warn
checks.indentation.indentation;//indent:0 exp:4 warn

public class InputIndentationPackageDeclaration4 {}//indent:0 exp:0

0 comments on commit 0cf7377

Please sign in to comment.