elharo commented on code in PR #3589:
URL: https://github.com/apache/maven-surefire/pull/3589#discussion_r4550550908


##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporter.java:
##########
@@ -61,7 +62,7 @@ static File getReportFile(
             File reportsDirectory, String reportEntryName, String 
reportNameSuffix, String fileExtension) {
         String fileName =
                 reportEntryName + (isNotBlank(reportNameSuffix) ? "-" + 
reportNameSuffix : "") + fileExtension;
-        return new File(reportsDirectory, stripIllegalFilenameChars(fileName));
+        return new File(reportsDirectory, 
truncateFileName(stripIllegalFilenameChars(fileName)));

Review Comment:
   maybe just one makeFileNameMethod?



##########
maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java:
##########
@@ -65,6 +65,33 @@ private TestSetStats createTestSetStats() {
         return new TestSetStats(true, true);
     }
 
+    /**
+     * SUREFIRE-2233: a report file name derived from a long, deeply nested 
test class name must
+     * still be creatable, even on filesystems with a low per-component length 
limit.
+     */
+    @Test
+    public void testVeryLongFileNameIsTruncated() {
+        File reportDir = new File("target");
+        StringBuilder packageBuilder = new StringBuilder("org.example.");
+        for (int i = 0; i < 12; i++) {
+            packageBuilder.append("subpackage1.");
+        }
+        String longTestName = packageBuilder + 
"TestWithAnExceptionallyLongAndDeeplyNestedFullyQualifiedClassName";
+        reportEntry = new SimpleReportEntry(NORMAL_RUN, 1L, longTestName, 
null, longTestName, null);
+        WrappedReportEntry wrappedReportEntry =
+                new WrappedReportEntry(reportEntry, ReportEntryType.SUCCESS, 
1771085631L, 12, null, null);
+        reporter = new FileReporter(reportDir, null, Charset.defaultCharset(), 
false, false, false);
+        reporter.testSetCompleted(wrappedReportEntry, createTestSetStats(), 
new ArrayList<>());
+
+        File[] createdReports = reportDir.listFiles((dir, name) -> 
name.endsWith(".txt") && name.contains("_"));
+        assertTrue(
+                createdReports != null && createdReports.length == 1,
+                "exactly one truncated report file should have been created in 
" + reportDir.getAbsolutePath());
+        assertTrue(createdReports[0].getName().length() < 
longTestName.length() + ".txt".length());

Review Comment:
   should test expected name for equality somewhere



##########
maven-surefire-common/src/test/java/org/apache/maven/surefire/report/FileReporterTest.java:
##########
@@ -65,6 +65,33 @@ private TestSetStats createTestSetStats() {
         return new TestSetStats(true, true);
     }
 
+    /**
+     * SUREFIRE-2233: a report file name derived from a long, deeply nested 
test class name must
+     * still be creatable, even on filesystems with a low per-component length 
limit.
+     */
+    @Test
+    public void testVeryLongFileNameIsTruncated() {
+        File reportDir = new File("target");
+        StringBuilder packageBuilder = new StringBuilder("org.example.");
+        for (int i = 0; i < 12; i++) {
+            packageBuilder.append("subpackage1.");
+        }
+        String longTestName = packageBuilder + 
"TestWithAnExceptionallyLongAndDeeplyNestedFullyQualifiedClassName";
+        reportEntry = new SimpleReportEntry(NORMAL_RUN, 1L, longTestName, 
null, longTestName, null);
+        WrappedReportEntry wrappedReportEntry =
+                new WrappedReportEntry(reportEntry, ReportEntryType.SUCCESS, 
1771085631L, 12, null, null);
+        reporter = new FileReporter(reportDir, null, Charset.defaultCharset(), 
false, false, false);

Review Comment:
   UTF-8, not default charset



##########
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/FileReporterUtils.java:
##########
@@ -43,6 +48,27 @@ public static String stripIllegalFilenameChars(String 
original) {
         return result.toString();
     }
 
+    /**
+     * Shortens a report file name that would otherwise exceed common 
filesystem limits
+     * (e.g. a deeply nested, long test class name), keeping it unique by 
appending a hash
+     * of the untruncated name.
+     *
+     * @param fileName the file name, including its extension
+     * @return {@code fileName} unchanged if it already fits, otherwise a 
truncated name of
+     *         the same extension
+     */
+    public static String truncateFileName(String fileName) {

Review Comment:
   private or package protected, not public



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to