Search in sources :

Example 1 with CFLintExceptionListener

use of com.cflint.plugins.exceptions.CFLintExceptionListener in project CFLint by cflint.

the class TestFiles method test.

@Test
public void test() throws IOException, URISyntaxException, JAXBException, TransformerException {
    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());
    CFLint cflint = new CFLint(config);
    cflint.setVerbose(true);
    cflint.setLogError(true);
    cflint.addExceptionListener(new CFLintExceptionListener() {

        @Override
        public void exceptionOccurred(Throwable exception, String messageCode, String filename, Integer line, Integer column, String functionName, String expression) {
            exception.printStackTrace();
            fail("Error scanning " + filename);
        }
    });
    cflint.process(inputString, sourceFile.getPath());
    //List<BugInfo> result = cflint.getBugs().getFlatBugList();
    StringWriter writer = new StringWriter();
    new JSONOutput().output(cflint.getBugs(), writer, false);
    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"), actualTree.replaceAll("\\\\", "/").replaceAll("/+", "/").replaceAll("\r\n", "\n"));
    }
}
Also used : CFLintExceptionListener(com.cflint.plugins.exceptions.CFLintExceptionListener) StringWriter(java.io.StringWriter) CFLint(com.cflint.CFLint) CFLintConfiguration(com.cflint.config.CFLintConfiguration) JSONOutput(com.cflint.JSONOutput) File(java.io.File) Test(org.junit.Test)

Aggregations

CFLint (com.cflint.CFLint)1 JSONOutput (com.cflint.JSONOutput)1 CFLintConfiguration (com.cflint.config.CFLintConfiguration)1 CFLintExceptionListener (com.cflint.plugins.exceptions.CFLintExceptionListener)1 File (java.io.File)1 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1