[ 
https://issues.apache.org/jira/browse/MPMD-395?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17852875#comment-17852875
 ] 

ASF GitHub Bot commented on MPMD-395:
-------------------------------------

michael-o commented on code in PR #150:
URL: https://github.com/apache/maven-pmd-plugin/pull/150#discussion_r1629937539


##########
src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java:
##########
@@ -240,4 +241,30 @@ public void testExclusionsConfiguration() throws Exception 
{
         String str = readFile(generatedFile);
         assertEquals(0, StringUtils.countMatches(str, "<duplication"));
     }
+
+    public void testWithCpdErrors() throws Exception {
+        try {
+            File generatedReport = generateReport("cpd", 
"CpdReportTest/with-cpd-errors/pom.xml");
+            fail("MavenReportException must be thrown");
+        } catch (Exception e) {
+            assertMavenReportException("There was 1 error while executing 
CPD", e);
+            assertLogOutputContains("Lexical error in file");
+            assertLogOutputContains("BadFile.java");
+        }
+    }
+
+    private static void assertMavenReportException(String expectedMessage, 
Exception exception) {
+        // The maven report exception might be wrapped in a RuntimeException
+        assertTrue(
+                "Expected MavenReportException, but was: " + exception,
+                exception instanceof MavenReportException || 
exception.getCause() instanceof MavenReportException);
+        assertTrue(
+                "Wrong message: expected: " + expectedMessage + ", but was: " 
+ exception.toString(),
+                exception.toString().contains(expectedMessage));
+    }
+
+    private static void assertLogOutputContains(String expectedMessage) {
+        String log = CapturingPrintStream.getOutput();
+        assertTrue("Expected '" + expectedMessage + "' in log, but was:\n" + 
log, log.contains(expectedMessage));

Review Comment:
   Is the `\n` also portable on Windows?





> Build doesn't fail for invalid CPD format
> -----------------------------------------
>
>                 Key: MPMD-395
>                 URL: https://issues.apache.org/jira/browse/MPMD-395
>             Project: Maven PMD Plugin
>          Issue Type: Bug
>          Components: CPD
>    Affects Versions: 3.22.0
>            Reporter: Andreas Dangel
>            Assignee: Andreas Dangel
>            Priority: Major
>             Fix For: next-version
>
>
> See 
> [https://github.com/apache/maven-pmd-plugin/pull/144#issuecomment-2094371392]
>  
> If an exception occurs while the CPD report is created, the exception is only 
> logged but doesn't fail the build. This means, that build appears to be 
> successful, although it didn't produce all expected build artifacts.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to