Issue #2161: unify test input locations for whitespace package

This commit is contained in:
rnveach 2015-10-18 13:17:57 -04:00 committed by Roman Ivanov
parent beb0ba7574
commit 375dbf134c
20 changed files with 343 additions and 51 deletions

View File

@ -23,6 +23,7 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacter
import static com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck.FILE_CONTAINS_TAB;
import java.io.File;
import java.io.IOException;
import org.junit.Test;
@ -32,6 +33,12 @@ import com.puppycrawl.tools.checkstyle.api.Configuration;
public class FileTabCharacterCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}
@Override
protected DefaultConfiguration createCheckerConfig(
Configuration config) {

View File

@ -125,9 +125,7 @@ public class GenericWhitespaceCheckTest
@Test
public void testMethodReferences() throws Exception {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, new File("src/test/resources-noncompilable/com/puppycrawl/tools/"
+ "checkstyle/grammars/java8/"
+ "InputMethodReferencesTest3.java").getCanonicalPath(), expected);
verify(checkConfig, getNonCompilablePath("InputMethodReferencesTest3.java"), expected);
}
@Test

View File

@ -21,6 +21,9 @@ package com.puppycrawl.tools.checkstyle.checks.whitespace;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceAfterCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Before;
import org.junit.Test;
@ -32,6 +35,12 @@ public class NoWhitespaceAfterCheckTest
extends BaseCheckTestSupport {
private DefaultConfiguration checkConfig;
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}
@Before
public void setUp() {
checkConfig = createCheckConfig(NoWhitespaceAfterCheck.class);
@ -100,13 +109,13 @@ public class NoWhitespaceAfterCheckTest
"40:16: " + getCheckMessage(MSG_KEY, "int"),
"43:63: " + getCheckMessage(MSG_KEY, "getLongMultArray"),
};
verify(checkConfig, getPath("whitespace/InputNoWhitespaceAfterArrayDeclarations.java"), expected);
verify(checkConfig, getPath("InputNoWhitespaceAfterArrayDeclarations.java"), expected);
}
@Test
public void testNpe() throws Exception {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/InputNoWhiteSpaceAfterCheckFormerNpe.java"),
verify(checkConfig, getPath("InputNoWhiteSpaceAfterCheckFormerNpe.java"),
expected);
}
}

View File

@ -21,6 +21,9 @@ package com.puppycrawl.tools.checkstyle.checks.whitespace;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.NoWhitespaceBeforeCheck.MSG_KEY;
import java.io.File;
import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
@ -36,6 +39,12 @@ public class NoWhitespaceBeforeCheckTest
checkConfig = createCheckConfig(NoWhitespaceBeforeCheck.class);
}
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}
@Test
public void testDefault() throws Exception {
final String[] expected = {

View File

@ -24,6 +24,9 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPad
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.WS_NOT_PRECEDED;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.WS_PRECEDED;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;
@ -32,6 +35,12 @@ import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
public class ParenPadCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}
@Test
public void testDefault()
throws Exception {
@ -109,7 +118,7 @@ public class ParenPadCheckTest
"48:27: " + getCheckMessage(WS_PRECEDED, ")"),
"51:26: " + getCheckMessage(WS_PRECEDED, ")"),
};
verify(checkConfig, getPath("checks/whitespace/InputForWhitespace.java"), expected);
verify(checkConfig, getPath("InputForWhitespace.java"), expected);
}
@Test
@ -129,7 +138,7 @@ public class ParenPadCheckTest
"27:14: " + getCheckMessage(WS_NOT_FOLLOWED, "("),
"32:14: " + getCheckMessage(WS_NOT_FOLLOWED, "("),
};
verify(checkConfig, getPath("checks/whitespace/InputForWhitespace.java"), expected);
verify(checkConfig, getPath("InputForWhitespace.java"), expected);
}
@Test
@ -138,7 +147,7 @@ public class ParenPadCheckTest
createCheckConfig(ParenPadCheck.class);
checkConfig.addAttribute("option", PadOption.SPACE.toString());
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("whitespace/ParenPadWithSpace.java"),
verify(checkConfig, getPath("ParenPadWithSpace.java"),
expected);
}
@ -213,7 +222,7 @@ public class ParenPadCheckTest
"130:19: " + getCheckMessage(WS_FOLLOWED, "("),
"130:19: " + getCheckMessage(WS_PRECEDED, ")"),
};
verify(checkConfig, getPath("whitespace/InputParenPad.java"), expected);
verify(checkConfig, getPath("InputParenPad.java"), expected);
}
@Test
@ -228,6 +237,6 @@ public class ParenPadCheckTest
"115:53: " + getCheckMessage(WS_PRECEDED, ")"),
"115:55: " + getCheckMessage(WS_PRECEDED, ")"),
};
verify(checkConfig, getPath("whitespace/InputParenPad.java"), expected);
verify(checkConfig, getPath("InputParenPad.java"), expected);
}
}

View File

@ -24,6 +24,9 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPad
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.WS_NOT_PRECEDED;
import static com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck.WS_PRECEDED;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Assert;
import org.junit.Test;
@ -34,6 +37,12 @@ import com.puppycrawl.tools.checkstyle.api.TokenTypes;
public class TypecastParenPadCheckTest
extends BaseCheckTestSupport {
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}
@Test
public void testDefault()
throws Exception {
@ -71,7 +80,7 @@ public class TypecastParenPadCheckTest
createCheckConfig(TypecastParenPadCheck.class);
checkConfig.addAttribute("option", PadOption.SPACE.toString());
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("checks/whitespace/InputWhitespaceAround.java"),
verify(checkConfig, getPath("InputWhitespaceAround.java"),
expected);
}

View File

@ -23,6 +23,9 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterC
import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAfterCheck.WS_TYPECAST;
import static org.junit.Assert.assertArrayEquals;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Before;
import org.junit.Test;
@ -39,6 +42,12 @@ public class WhitespaceAfterCheckTest
checkConfig = createCheckConfig(WhitespaceAfterCheck.class);
}
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}
@Test
public void testGetRequiredTokens() {
WhitespaceAfterCheck checkObj = new WhitespaceAfterCheck();
@ -65,9 +74,9 @@ public class WhitespaceAfterCheckTest
@Test
public void testSemi() throws Exception {
final String[] expected = {
"58:23: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
"58:29: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
"107:19: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
"54:23: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
"54:29: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
"103:19: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
};
verify(checkConfig, getPath("InputBraces.java"), expected);
}
@ -78,7 +87,7 @@ public class WhitespaceAfterCheckTest
"14:31: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
"17:31: " + getCheckMessage(WS_NOT_FOLLOWED, ";"),
};
verify(checkConfig, getPath("checks/whitespace/InputForWhitespace.java"), expected);
verify(checkConfig, getPath("InputForWhitespace.java"), expected);
}
@Test
@ -94,7 +103,7 @@ public class WhitespaceAfterCheckTest
@Test
public void test1322879() throws Exception {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("checks/whitespace/InputWhitespaceAround.java"),
verify(checkConfig, getPath("InputWhitespaceAround.java"),
expected);
}
}

View File

@ -23,6 +23,9 @@ import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAround
import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck.WS_NOT_PRECEDED;
import static org.junit.Assert.assertArrayEquals;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.Before;
import org.junit.Test;
@ -40,6 +43,12 @@ public class WhitespaceAroundTest
checkConfig = createCheckConfig(WhitespaceAroundCheck.class);
}
@Override
protected String getPath(String filename) throws IOException {
return super.getPath("checks" + File.separator
+ "whitespace" + File.separator + filename);
}
@Test
public void testGetRequiredTokens() {
WhitespaceAroundCheck checkObj = new WhitespaceAroundCheck();
@ -108,14 +117,14 @@ public class WhitespaceAroundTest
public void testIt3()
throws Exception {
final String[] expected = {
"41:14: " + getCheckMessage(WS_NOT_FOLLOWED, "while"),
"58:12: " + getCheckMessage(WS_NOT_FOLLOWED, "for"),
"37:14: " + getCheckMessage(WS_NOT_FOLLOWED, "while"),
"54:12: " + getCheckMessage(WS_NOT_FOLLOWED, "for"),
// + ":58:23: ';' is not followed by whitespace.",
// + ":58:29: ';' is not followed by whitespace.",
"115:27: " + getCheckMessage(WS_NOT_FOLLOWED, "{"),
"115:27: " + getCheckMessage(WS_NOT_PRECEDED, "}"),
"118:40: " + getCheckMessage(WS_NOT_FOLLOWED, "{"),
"118:40: " + getCheckMessage(WS_NOT_PRECEDED, "}"),
"111:27: " + getCheckMessage(WS_NOT_FOLLOWED, "{"),
"111:27: " + getCheckMessage(WS_NOT_PRECEDED, "}"),
"114:40: " + getCheckMessage(WS_NOT_FOLLOWED, "{"),
"114:40: " + getCheckMessage(WS_NOT_PRECEDED, "}"),
};
verify(checkConfig, getPath("InputBraces.java"), expected);
}
@ -126,8 +135,8 @@ public class WhitespaceAroundTest
checkConfig.addAttribute("allowEmptyMethods", "true");
checkConfig.addAttribute("allowEmptyConstructors", "true");
final String[] expected = {
"41:14: " + getCheckMessage(WS_NOT_FOLLOWED, "while"),
"58:12: " + getCheckMessage(WS_NOT_FOLLOWED, "for"),
"37:14: " + getCheckMessage(WS_NOT_FOLLOWED, "while"),
"54:12: " + getCheckMessage(WS_NOT_FOLLOWED, "for"),
};
verify(checkConfig, getPath("InputBraces.java"), expected);
}
@ -145,7 +154,7 @@ public class WhitespaceAroundTest
@Test
public void test1322879And1649038() throws Exception {
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig, getPath("checks/whitespace/InputWhitespaceAround.java"),
verify(checkConfig, getPath("InputWhitespaceAround.java"),
expected);
}
@ -155,7 +164,7 @@ public class WhitespaceAroundTest
final String[] expected = {
"19:20: " + getCheckMessage(WS_NOT_PRECEDED, ":"),
};
verify(checkConfig, getPath("checks/whitespace/InputWhitespaceAround.java"),
verify(checkConfig, getPath("InputWhitespaceAround.java"),
expected);
}
@ -170,7 +179,7 @@ public class WhitespaceAroundTest
"31:21: " + getCheckMessage(WS_NOT_FOLLOWED, "{"),
"31:21: " + getCheckMessage(WS_NOT_PRECEDED, "}"),
};
verify(checkConfig, getPath("whitespace/InputEmptyTypesAndCycles.java"),
verify(checkConfig, getPath("InputEmptyTypesAndCycles.java"),
expected);
}
@ -189,7 +198,7 @@ public class WhitespaceAroundTest
"60:18: " + getCheckMessage(WS_NOT_FOLLOWED, "{"),
"60:18: " + getCheckMessage(WS_NOT_PRECEDED, "}"),
};
verify(checkConfig, getPath("whitespace/InputEmptyTypesAndCycles.java"),
verify(checkConfig, getPath("InputEmptyTypesAndCycles.java"),
expected);
}
@ -198,9 +207,7 @@ public class WhitespaceAroundTest
final String[] expected = {
"6:15: " + getCheckMessage(WS_NOT_FOLLOWED, "switch"),
};
verify(checkConfig,
getPath("whitespace/InputSwitchWhitespaceAround.java"),
expected);
verify(checkConfig, getPath("InputSwitchWhitespaceAround.java"), expected);
}
@Test
@ -208,18 +215,14 @@ public class WhitespaceAroundTest
final String[] expected = {
"9:16: " + getCheckMessage(WS_NOT_FOLLOWED, "while"),
};
verify(checkConfig,
getPath("whitespace/InputDoWhileWhitespaceAround.java"),
expected);
verify(checkConfig, getPath("InputDoWhileWhitespaceAround.java"), expected);
}
@Test
public void allowEmptyMethods() throws Exception {
checkConfig.addAttribute("allowEmptyMethods", "true");
final String[] expected = ArrayUtils.EMPTY_STRING_ARRAY;
verify(checkConfig,
getPath("checks/whitespace/InputWhitespaceAround.java"),
expected);
verify(checkConfig, getPath("InputWhitespaceAround.java"), expected);
}
@Test

View File

@ -0,0 +1,18 @@
//Compilable with Java8
package com.puppycrawl.tools.checkstyle.checks.whitespace;
import java.util.function.Supplier;
public static class InputMethodReferencesTest3
{
public static class SomeClass {
public static class Nested<V> {
public Nested() {
}
}
}
public <V> void methodName(V value) {
MyClass<T>::myMethod;
Supplier<SomeClass.Nested<V>> passes = SomeClass.Nested::new;
Supplier<SomeClass.Nested<V>> fails = SomeClass.Nested<V>::new;
}
}

View File

@ -2,12 +2,8 @@
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
/**
* Test case for correct use of braces.
* @author Oliver Burn
**/
class InputBraces
{
/** @return helper func **/

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.whitespace;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
public class InputDoWhileWhitespaceAround {

View File

@ -2,7 +2,7 @@
// Test case file for checkstyle.
// Created: 2001
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.whitespace;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
import java.util.Collection;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.whitespace;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
public class InputNoWhiteSpaceAfterCheckFormerNpe
{

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.whitespace;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
public class InputNoWhitespaceAfterArrayDeclarations
{

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.whitespace;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
import java.io.IOException;
import java.io.StringWriter;

View File

@ -0,0 +1,225 @@
////////////////////////////////////////////////////////////////////////////////
// Test case file for checkstyle.
// Created: Feb-2001
// Ignore error
////////////////////////////////////////////////////////////////////////////////
package com.puppycrawl.tools.checkstyle.checks.whitespace;
import java.io.*;
/**
* Contains simple mistakes:
* - Long lines
* - Tabs
* - Format of variables and parameters
* - Order of modifiers
* @author Oliver Burn
**/
final class InputSimple
{
// Long line ----------------------------------------------------------------
// Contains a tab -> <-
// Contains trailing whitespace ->
// Name format tests
//
/** Invalid format **/
public static final int badConstant = 2;
/** Valid format **/
public static final int MAX_ROWS = 2;
/** Invalid format **/
private static int badStatic = 2;
/** Valid format **/
private static int sNumCreated = 0;
/** Invalid format **/
private int badMember = 2;
/** Valid format **/
private int mNumCreated1 = 0;
/** Valid format **/
protected int mNumCreated2 = 0;
/** commas are wrong **/
private int[] mInts = new int[] {1,2, 3,
4};
//
// Accessor tests
//
/** should be private **/
public static int sTest1;
/** should be private **/
protected static int sTest3;
/** should be private **/
static int sTest2;
/** should be private **/
int mTest1;
/** should be private **/
public int mTest2;
//
// Parameter name format tests
//
/**
* @return hack
* @param badFormat1 bad format
* @param badFormat2 bad format
* @param badFormat3 bad format
* @throws java.lang.Exception abc
**/
int test1(int badFormat1,int badFormat2,
final int badFormat3)
throws java.lang.Exception
{
return 0;
}
/** method that is 20 lines long **/
private void longMethod()
{
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
}
/** constructor that is 10 lines long **/
private InputSimple()
{
// a line
// a line
// a line
// a line
// a line
// a line
// a line
// a line
}
/** test local variables */
private void localVariables()
{
// normal decl
int abc = 0;
int ABC = 0;
// final decls
final int cde = 0;
final int CDE = 0;
// decl in for loop init statement
for (int k = 0; k < 1; k++)
{
String innerBlockVariable = "";
}
for (int I = 0; I < 1; I++)
{
String InnerBlockVariable = "";
}
}
/** test method pattern */
void ALL_UPPERCASE_METHOD()
{
}
/** test illegal constant **/
private static final int BAD__NAME = 3;
// A very, very long line that is OK because it matches the regexp "^.*is OK.*regexp.*$"
// long line that has a tab -> <- and would be OK if tab counted as 1 char
// tabs that count as one char because of their position -> <- -> <-, OK
/** some lines to test the error column after tabs */
void errorColumnAfterTabs()
{
// with tab-width 8 all statements below start at the same column,
// with different combinations of ' ' and '\t' before the statement
int tab0 =1;
int tab1 =1;
int tab2 =1;
int tab3 =1;
int tab4 =1;
int tab5 =1;
}
// FIXME:
/* FIXME: a
* FIXME:
* TODO
*/
/* NOTHING */
/* YES */ /* FIXME: x */ /* YES!! */
/** test long comments **/
void veryLong()
{
/*
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
blah blah blah blah
enough talk */
}
/**
* @see to lazy to document all args. Testing excessive # args
**/
void toManyArgs(int aArg1, int aArg2, int aArg3, int aArg4, int aArg5,
int aArg6, int aArg7, int aArg8, int aArg9)
{
}
}
/** Test class for variable naming in for each clauses. */
class InputSimple2
{
/** Some more Javadoc. */
public void doSomething()
{
//"O" should be named "o"
for (Object O : new java.util.ArrayList())
{
}
}
}
/** Test enum for member naming check */
enum MyEnum1
{
/** ABC constant */
ABC,
/** XYZ constant */
XYZ;
/** Should be mSomeMemeber */
private int someMember;
}

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.whitespace;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
public class InputSwitchWhitespaceAround {

View File

@ -4,7 +4,7 @@
////////////////////////////////////////////////////////////////////////////////
package com . puppycrawl
.tools.
checkstyle;
checkstyle.checks.whitespace;
/**
* Class for testing whitespace issues.

View File

@ -1,4 +1,4 @@
package com.puppycrawl.tools.checkstyle.whitespace;
package com.puppycrawl.tools.checkstyle.checks.whitespace;
public class ParenPadWithSpace
{