From c166613c0f61cdd23b8ed6ac8de36862a8579ef2 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 17 Feb 2022 18:04:35 +0100 Subject: [PATCH] [dist] Add integration test for --debug flag --- .../pmd/it/BinaryDistributionIT.java | 19 +++++++++++++++++++ .../sourceforge/pmd/it/ExecutionResult.java | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index 3f7631baa5..b0675ea236 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -93,6 +93,25 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { result.assertExecutionResult(4, ""); } + @Test + public void logging() throws Exception { + String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); + + ExecutionResult result; + + result = PMDExecutor.runPMD(tempDir, "-d", srcDir, "-R", "src/test/resources/rulesets/sample-ruleset.xml", + "-r", folder.newFile().toString()); + result.assertExecutionResult(4); + result.assertErrorOutputContains("[main] INFO net.sourceforge.pmd.PMD - Loglevel is at INFO"); + + + // now with debug + result = PMDExecutor.runPMD(tempDir, "-d", srcDir, "-R", "src/test/resources/rulesets/sample-ruleset.xml", + "-r", folder.newFile().toString(), "--debug"); + result.assertExecutionResult(4); + result.assertErrorOutputContains("[main] DEBUG net.sourceforge.pmd.PMD - Loglevel is at DEBUG"); + } + @Test public void runCPD() throws Exception { String srcDir = new File(".", "src/test/resources/sample-source-cpd/").getAbsolutePath(); diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java index 1196d99179..0cdeee62f6 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/ExecutionResult.java @@ -105,6 +105,10 @@ public class ExecutionResult { report.contains(errorMessage)); } + public void assertErrorOutputContains(String message) { + assertTrue("erroroutput didn't contain " + message, errorOutput.contains(message)); + } + static class Builder { private int exitCode; private String output;