Search in sources :

Example 26 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestWriteDumpChecker method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("AVOID_USING_WRITEDUMP");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Example 27 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestFiles method test.

@Test
public void test() throws IOException, CFLintScanException, CFLintConfigurationException {
    final String inputString = FileUtil.loadFile(sourceFile);
    final File expectedFile = new File(sourceFile.getPath().replaceAll("\\.cf.", ".expected.txt"));
    final String expectedFileText = expectedFile.exists() ? FileUtil.loadFile(expectedFile) : null;
    String expectedText = expectedFileText;
    final CFLintConfiguration config = loadPluginInfo(sourceFile.getParentFile());
    final CFLintAPI cflint = new CFLintAPI(config);
    cflint.setLogError(true);
    CFLintResult result = cflint.scan(inputString, sourceFile.getPath());
    // Support the processing of a second source file in a single test
    final File nextFile = new File(sourceFile.getPath() + ".2");
    if (nextFile.exists()) {
        final String inputString2 = FileUtil.loadFile(nextFile);
        result = cflint.scan(inputString2, nextFile.getPath().replaceAll("[.]2$", ""));
    }
    final StringWriter writer = new StringWriter();
    result.writeJSON(writer);
    final String actualTree = writer.toString();
    if (expectedText == null || expectedText.trim().length() == 0) {
        writeExpectFile(expectedFile, actualTree);
        System.out.println("Tree written to " + expectedFile);
    } else {
        if (autoReplaceFailed && !actualTree.equals(expectedText)) {
            System.out.println("Replaced content of " + expectedFile);
            expectedText = actualTree;
            writeExpectFile(expectedFile, actualTree);
        }
        assertEquals(expectedText.replaceAll("\\\\", "/").replaceAll("/+", "/").replaceAll("\r\n", "\n").replaceAll("\"timestamp\" : \\d+", "\"timestamp\" : 0"), actualTree.replaceAll("\\\\", "/").replaceAll("/+", "/").replaceAll("\r\n", "\n").replaceAll("\"timestamp\" : \\d+", "\"timestamp\" : 0"));
    }
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) StringWriter(java.io.StringWriter) CFLintConfiguration(com.cflint.config.CFLintConfiguration) File(java.io.File) CFLintResult(com.cflint.api.CFLintResult) Test(org.junit.Test)

Example 28 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestAbortChecker method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("AVOID_USING_ABORT");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Example 29 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestArgumentNames method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("ARGUMENT_MISSING_NAME", "ARGUMENT_INVALID_NAME", "ARGUMENT_ALLCAPS_NAME", "ARGUMENT_TOO_SHORT", "ARGUMENT_TOO_LONG", "ARGUMENT_TOO_WORDY", "ARGUMENT_IS_TEMPORARY", "ARGUMENT_HAS_PREFIX_OR_POSTFIX");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Example 30 with CFLintAPI

use of com.cflint.api.CFLintAPI in project CFLint by cflint.

the class TestArrayNewChecker method setUp.

@Before
public void setUp() throws Exception {
    final ConfigBuilder configBuilder = new ConfigBuilder().include("AVOID_USING_ARRAYNEW");
    cfBugs = new CFLintAPI(configBuilder.build());
}
Also used : CFLintAPI(com.cflint.api.CFLintAPI) ConfigBuilder(com.cflint.config.ConfigBuilder) Before(org.junit.Before)

Aggregations

CFLintAPI (com.cflint.api.CFLintAPI)55 ConfigBuilder (com.cflint.config.ConfigBuilder)53 Before (org.junit.Before)53 CFLintConfig (com.cflint.config.CFLintConfig)3 CFLintPluginInfo (com.cflint.config.CFLintPluginInfo)3 PluginInfoRule (com.cflint.config.CFLintPluginInfo.PluginInfoRule)3 PluginMessage (com.cflint.config.CFLintPluginInfo.PluginInfoRule.PluginMessage)3 CFLintResult (com.cflint.api.CFLintResult)2 StringWriter (java.io.StringWriter)2 CFLintConfiguration (com.cflint.config.CFLintConfiguration)1 CFLintConfigurationException (com.cflint.exception.CFLintConfigurationException)1 CFLintScanException (com.cflint.exception.CFLintScanException)1 MarshallerException (com.cflint.xml.MarshallerException)1 File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 Writer (java.io.Writer)1