Skip to content

Commit c670335

Browse files
NissMoonymichael-o
NissMoony
authored andcommitted
[SUREFIRE-1934] Ability to disable system-out/system-err for successfully passed tests
Co-authored-by: Michael Osipov <[email protected]> This closes #670
1 parent bce1b39 commit c670335

File tree

24 files changed

+337
-16
lines changed

24 files changed

+337
-16
lines changed

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/AbstractSurefireMojo.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,16 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
690690
@Parameter(property = "enableAssertions", defaultValue = "true")
691691
private boolean enableAssertions;
692692

693+
/**
694+
* Flag for including/excluding {@code <system-out />} and {@code <system-err />} elements for
695+
* successfully passed tests in XML reports.
696+
* Note that the default value may change to {@code false} is a future version.
697+
*
698+
* @since 3.3.1
699+
*/
700+
@Parameter(property = "enableOutErrElements", defaultValue = "true")
701+
private boolean enableOutErrElements;
702+
693703
/**
694704
* The current build session instance.
695705
*/
@@ -1474,6 +1484,10 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
14741484
Double.toString(getParallelTestsTimeoutForcedInSeconds()));
14751485
getProperties()
14761486
.setProperty(ProviderParameterNames.PARALLEL_OPTIMIZE_PROP, Boolean.toString(isParallelOptimized()));
1487+
getProperties()
1488+
.setProperty(
1489+
ProviderParameterNames.ENABLE_OUT_ERR_ELEMENTS_PROP,
1490+
Boolean.toString(isEnableOutErrElements()));
14771491

14781492
String message = "parallel='" + usedParallel + '\''
14791493
+ ", perCoreThreadCount=" + getPerCoreThreadCount()
@@ -1482,7 +1496,8 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
14821496
+ ", threadCountSuites=" + getThreadCountSuites()
14831497
+ ", threadCountClasses=" + getThreadCountClasses()
14841498
+ ", threadCountMethods=" + getThreadCountMethods()
1485-
+ ", parallelOptimized=" + isParallelOptimized();
1499+
+ ", parallelOptimized=" + isParallelOptimized()
1500+
+ ", enableOutErrElements=" + isEnableOutErrElements();
14861501

14871502
logDebugOrCliShowErrors(message);
14881503
}
@@ -1976,6 +1991,7 @@ private StartupReportConfiguration getStartupReportConfiguration(String configCh
19761991
getReportSchemaLocation(),
19771992
getEncoding(),
19781993
isForking,
1994+
isEnableOutErrElements(),
19791995
xmlReporter,
19801996
outReporter,
19811997
testsetReporter);
@@ -2516,6 +2532,7 @@ private String getConfigChecksum() {
25162532
checksum.add(getTempDir());
25172533
checksum.add(useModulePath());
25182534
checksum.add(getEnableProcessChecker());
2535+
checksum.add(isEnableOutErrElements());
25192536
addPluginSpecificChecksumItems(checksum);
25202537
return checksum.getSha1();
25212538
}
@@ -3472,6 +3489,15 @@ public void setEnableAssertions(boolean enableAssertions) {
34723489
this.enableAssertions = enableAssertions;
34733490
}
34743491

3492+
public boolean isEnableOutErrElements() {
3493+
return enableOutErrElements;
3494+
}
3495+
3496+
@SuppressWarnings("UnusedDeclaration")
3497+
public void setEnableOutErrElements(boolean enableOutErrElements) {
3498+
this.enableOutErrElements = enableOutErrElements;
3499+
}
3500+
34753501
public MavenSession getSession() {
34763502
return session;
34773503
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/CommonReflector.java

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
8686
String.class,
8787
String.class,
8888
boolean.class,
89+
boolean.class,
8990
statelessTestsetReporter,
9091
consoleOutputReporter,
9192
statelessTestsetInfoReporter);
@@ -103,6 +104,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
103104
reporterConfiguration.getXsdSchemaLocation(),
104105
reporterConfiguration.getEncoding().name(),
105106
reporterConfiguration.isForking(),
107+
reporterConfiguration.isEnableOutErrElements(),
106108
reporterConfiguration.getXmlReporter().clone(surefireClassLoader),
107109
reporterConfiguration.getConsoleOutputReporter().clone(surefireClassLoader),
108110
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader)

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/StartupReportConfiguration.java

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public final class StartupReportConfiguration {
8585

8686
private final boolean isForking;
8787

88+
private final boolean enableOutErrElements;
89+
8890
private final SurefireStatelessReporter xmlReporter;
8991

9092
private final SurefireConsoleOutputReporter consoleOutputReporter;
@@ -108,6 +110,7 @@ public StartupReportConfiguration(
108110
String xsdSchemaLocation,
109111
String encoding,
110112
boolean isForking,
113+
boolean enableOutErrElements,
111114
SurefireStatelessReporter xmlReporter,
112115
SurefireConsoleOutputReporter consoleOutputReporter,
113116
SurefireStatelessTestsetInfoReporter testsetReporter) {
@@ -127,6 +130,7 @@ public StartupReportConfiguration(
127130
String charset = trimToNull(encoding);
128131
this.encoding = charset == null ? UTF_8 : Charset.forName(charset);
129132
this.isForking = isForking;
133+
this.enableOutErrElements = enableOutErrElements;
130134
this.xmlReporter = xmlReporter;
131135
this.consoleOutputReporter = consoleOutputReporter;
132136
this.testsetReporter = testsetReporter;
@@ -177,6 +181,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> instantiat
177181
trimStackTrace,
178182
rerunFailingTestsCount,
179183
xsdSchemaLocation,
184+
enableOutErrElements,
180185
testClassMethodRunHistory);
181186

182187
return xmlReporter.isDisable() ? null : xmlReporter.createListener(xmlReporterConfig);
@@ -239,6 +244,10 @@ public boolean isForking() {
239244
return isForking;
240245
}
241246

247+
public boolean isEnableOutErrElements() {
248+
return enableOutErrElements;
249+
}
250+
242251
private File resolveReportsDirectory(Integer forkNumber) {
243252
return forkNumber == null ? reportsDirectory : replaceForkThreadsInPath(reportsDirectory, forkNumber);
244253
}

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/DefaultStatelessReportMojoConfiguration.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,15 @@ public DefaultStatelessReportMojoConfiguration(
4343
boolean trimStackTrace,
4444
int rerunFailingTestsCount,
4545
String xsdSchemaLocation,
46+
boolean enableOutErrElements,
4647
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory) {
47-
super(reportsDirectory, reportNameSuffix, trimStackTrace, rerunFailingTestsCount, xsdSchemaLocation);
48+
super(
49+
reportsDirectory,
50+
reportNameSuffix,
51+
trimStackTrace,
52+
rerunFailingTestsCount,
53+
xsdSchemaLocation,
54+
enableOutErrElements);
4855
this.testClassMethodRunHistory = testClassMethodRunHistory;
4956
}
5057

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireStatelessReporter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
6868
false,
6969
false,
7070
false,
71-
false);
71+
false,
72+
configuration.isEnableOutErrElements());
7273
}
7374

7475
@Override

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/junit5/JUnit5Xml30StatelessReporter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
107107
getUsePhrasedFileName(),
108108
getUsePhrasedTestSuiteClassName(),
109109
getUsePhrasedTestCaseClassName(),
110-
getUsePhrasedTestCaseMethodName());
110+
getUsePhrasedTestCaseMethodName(),
111+
configuration.isEnableOutErrElements());
111112
}
112113

113114
@Override

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/NullStatelessXmlReporter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class NullStatelessXmlReporter extends StatelessXmlReporter {
2929
static final NullStatelessXmlReporter INSTANCE = new NullStatelessXmlReporter();
3030

3131
private NullStatelessXmlReporter() {
32-
super(null, null, false, 0, null, null, null, false, false, false, false);
32+
super(null, null, false, 0, null, null, null, false, false, false, false, true);
3333
}
3434

3535
@Override

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public class StatelessXmlReporter implements StatelessReportEventListener<Wrappe
116116

117117
private final boolean phrasedMethodName;
118118

119+
private final boolean enableOutErrElements;
120+
119121
public StatelessXmlReporter(
120122
File reportsDirectory,
121123
String reportNameSuffix,
@@ -127,13 +129,15 @@ public StatelessXmlReporter(
127129
boolean phrasedFileName,
128130
boolean phrasedSuiteName,
129131
boolean phrasedClassName,
130-
boolean phrasedMethodName) {
132+
boolean phrasedMethodName,
133+
boolean enableOutErrElements) {
131134
this.reportsDirectory = reportsDirectory;
132135
this.reportNameSuffix = reportNameSuffix;
133136
this.trimStackTrace = trimStackTrace;
134137
this.rerunFailingTestsCount = rerunFailingTestsCount;
135138
this.testClassMethodRunHistoryMap = testClassMethodRunHistoryMap;
136139
this.xsdSchemaLocation = xsdSchemaLocation;
140+
this.enableOutErrElements = enableOutErrElements;
137141
this.xsdVersion = xsdVersion;
138142
this.phrasedFileName = phrasedFileName;
139143
this.phrasedSuiteName = phrasedSuiteName;
@@ -228,7 +232,9 @@ private void serializeTestClassWithoutRerun(
228232
methodEntry.getReportEntryType().getXmlTag(),
229233
false);
230234
}
231-
createOutErrElements(fw, ppw, methodEntry, outputStream);
235+
if (methodEntry.getReportEntryType() != SUCCESS || enableOutErrElements) {
236+
createOutErrElements(fw, ppw, methodEntry, outputStream);
237+
}
232238
ppw.endElement();
233239
}
234240
}

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/CommonReflectorTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public void setup() {
8282
null,
8383
null,
8484
false,
85+
true,
8586
xmlReporter,
8687
consoleOutputReporter,
8788
infoReporter);

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/ForkStarterTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ public void processShouldExitWithoutSayingGoodBye() throws Exception {
162162
null,
163163
null,
164164
true,
165+
true,
165166
xmlReporter,
166167
outputReporter,
167168
statelessTestsetInfoReporter);
@@ -247,6 +248,7 @@ public void processShouldWaitForAck() throws Exception {
247248
null,
248249
null,
249250
true,
251+
true,
250252
xmlReporter,
251253
outputReporter,
252254
statelessTestsetInfoReporter);

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/booterclient/TestSetMockReporterFactory.java

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ private static StartupReportConfiguration defaultValue() {
6666
null,
6767
null,
6868
true,
69+
true,
6970
new SurefireStatelessReporter(),
7071
new SurefireConsoleOutputReporter(),
7172
new SurefireStatelessTestsetInfoReporter());

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/StatelessReporterTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void shouldCreateConsoleListener() {
6666
String schema = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd";
6767
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory = new HashMap<>();
6868
DefaultStatelessReportMojoConfiguration config = new DefaultStatelessReportMojoConfiguration(
69-
reportsDirectory, reportNameSuffix, true, 5, schema, testClassMethodRunHistory);
69+
reportsDirectory, reportNameSuffix, true, 5, schema, true, testClassMethodRunHistory);
7070
SurefireStatelessReporter extension = new SurefireStatelessReporter();
7171

7272
assertThat(extension.getVersion()).isEqualTo("3.0.1");
@@ -141,7 +141,7 @@ public void shouldCreateJUnit5ConsoleListener() {
141141
String schema = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report.xsd";
142142
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory = new HashMap<>();
143143
DefaultStatelessReportMojoConfiguration config = new DefaultStatelessReportMojoConfiguration(
144-
reportsDirectory, reportNameSuffix, true, 5, schema, testClassMethodRunHistory);
144+
reportsDirectory, reportNameSuffix, true, 5, schema, true, testClassMethodRunHistory);
145145
JUnit5Xml30StatelessReporter extension = new JUnit5Xml30StatelessReporter();
146146

147147
assertThat(extension.getVersion()).isEqualTo("3.0.1");

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public void testMergeTestHistoryResult() throws Exception {
8585
null,
8686
null,
8787
false,
88+
true,
8889
new SurefireStatelessReporter(),
8990
new SurefireConsoleOutputReporter(),
9091
new SurefireStatelessTestsetInfoReporter());
@@ -288,6 +289,7 @@ public void testLogger() {
288289
null,
289290
null,
290291
false,
292+
true,
291293
new SurefireStatelessReporter(),
292294
new SurefireConsoleOutputReporter(),
293295
new SurefireStatelessTestsetInfoReporter());
@@ -352,6 +354,7 @@ public void testCreateReporterWithZeroStatistics() {
352354
null,
353355
null,
354356
false,
357+
true,
355358
new SurefireStatelessReporter(),
356359
new SurefireConsoleOutputReporter(),
357360
new SurefireStatelessTestsetInfoReporter());

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporterTest.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ public void testFileNameWithoutSuffix() {
109109
false,
110110
false,
111111
false,
112-
false);
112+
false,
113+
true);
113114
reporter.cleanTestHistoryMap();
114115

115116
ReportEntry reportEntry = new SimpleReportEntry(
@@ -169,7 +170,8 @@ public void testAllFieldsSerialized() throws IOException {
169170
false,
170171
false,
171172
false,
172-
false);
173+
false,
174+
true);
173175
reporter.testSetCompleted(testSetReportEntry, stats);
174176

175177
FileInputStream fileInputStream = new FileInputStream(expectedReportFile);
@@ -271,7 +273,8 @@ public void testOutputRerunFlakyFailure() throws IOException {
271273
false,
272274
false,
273275
false,
274-
false);
276+
false,
277+
true);
275278

276279
reporter.testSetCompleted(testSetReportEntry, stats);
277280
reporter.testSetCompleted(testSetReportEntry, rerunStats);
@@ -370,7 +373,7 @@ public void testOutputRerunFlakyAssumption() throws IOException {
370373
rerunStats.testSucceeded(testTwoSecondError);
371374

372375
StatelessXmlReporter reporter = new StatelessXmlReporter(
373-
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false);
376+
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false, true);
374377

375378
WrappedReportEntry testSetReportEntry = new WrappedReportEntry(
376379
new SimpleReportEntry(
@@ -534,7 +537,7 @@ public void testReporterHandlesATestWithoutMessageAndWithEmptyStackTrace() {
534537
null);
535538

536539
StatelessXmlReporter reporter = new StatelessXmlReporter(
537-
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false);
540+
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0.1", false, false, false, false, true);
538541

539542
reporter.testSetCompleted(testReport, stats);
540543
}

surefire-api/src/main/java/org/apache/maven/surefire/api/booter/ProviderParameterNames.java

+2
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ public class ProviderParameterNames {
4545
public static final String PARALLEL_TIMEOUTFORCED_PROP = "paralleltimeoutforced";
4646

4747
public static final String PARALLEL_OPTIMIZE_PROP = "paralleloptimization";
48+
49+
public static final String ENABLE_OUT_ERR_ELEMENTS_PROP = "enableouterrelements";
4850
}

surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/StatelessReportMojoConfiguration.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,21 @@ public class StatelessReportMojoConfiguration {
3636

3737
private final String xsdSchemaLocation;
3838

39+
private final boolean enableOutErrElements;
40+
3941
public StatelessReportMojoConfiguration(
4042
File reportsDirectory,
4143
String reportNameSuffix,
4244
boolean trimStackTrace,
4345
int rerunFailingTestsCount,
44-
String xsdSchemaLocation) {
46+
String xsdSchemaLocation,
47+
boolean enableOutErrElements) {
4548
this.reportsDirectory = reportsDirectory;
4649
this.reportNameSuffix = reportNameSuffix;
4750
this.trimStackTrace = trimStackTrace;
4851
this.rerunFailingTestsCount = rerunFailingTestsCount;
4952
this.xsdSchemaLocation = xsdSchemaLocation;
53+
this.enableOutErrElements = enableOutErrElements;
5054
}
5155

5256
public File getReportsDirectory() {
@@ -68,4 +72,8 @@ public int getRerunFailingTestsCount() {
6872
public String getXsdSchemaLocation() {
6973
return xsdSchemaLocation;
7074
}
75+
76+
public boolean isEnableOutErrElements() {
77+
return enableOutErrElements;
78+
}
7179
}

0 commit comments

Comments
 (0)