Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SUREFIRE-1934] Ability to disable system-out/system-err for successfuly passed tests. #670

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -679,6 +679,16 @@ public abstract class AbstractSurefireMojo extends AbstractMojo implements Suref
@Parameter(property = "enableAssertions", defaultValue = "true")
private boolean enableAssertions;

/**
* Flag for including/excluding system-out and system-err elements in xml reports.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

XML

* <br>
* True by default.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are redundant, Plugin Tools will take care of that.

*
* @since 3.0.0
Copy link
Member

@michael-o michael-o Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be 3.2.4

*/
@Parameter(property = "enableOutputElements", defaultValue = "true")
private boolean enableOutputElements;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename to enableOutErrElements this will better reflect the intent w/o even reading the docs.


/**
* The current build session instance.
*/
Expand Down Expand Up @@ -1476,6 +1486,9 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
Double.toString(getParallelTestsTimeoutForcedInSeconds()));
getProperties()
.setProperty(ProviderParameterNames.PARALLEL_OPTIMIZE_PROP, Boolean.toString(isParallelOptimized()));
getProperties()
.setProperty(
ProviderParameterNames.ENABLE_OUTPUT_ELEMENTS_PROP, Boolean.toString(isEnableOutputElements()));

String message = "parallel='" + usedParallel + '\''
+ ", perCoreThreadCount=" + getPerCoreThreadCount()
Expand All @@ -1484,7 +1497,8 @@ private void convertJunitCoreParameters() throws MojoExecutionException {
+ ", threadCountSuites=" + getThreadCountSuites()
+ ", threadCountClasses=" + getThreadCountClasses()
+ ", threadCountMethods=" + getThreadCountMethods()
+ ", parallelOptimized=" + isParallelOptimized();
+ ", parallelOptimized=" + isParallelOptimized()
+ ", enableOutputElements=" + isEnableOutputElements();

logDebugOrCliShowErrors(message);
}
Expand Down Expand Up @@ -1978,6 +1992,7 @@ private StartupReportConfiguration getStartupReportConfiguration(String configCh
getReportSchemaLocation(),
getEncoding(),
isForking,
isEnableOutputElements(),
xmlReporter,
outReporter,
testsetReporter);
Expand Down Expand Up @@ -2518,6 +2533,7 @@ private String getConfigChecksum() {
checksum.add(getTempDir());
checksum.add(useModulePath());
checksum.add(getEnableProcessChecker());
checksum.add(isEnableOutputElements());
addPluginSpecificChecksumItems(checksum);
return checksum.getSha1();
}
Expand Down Expand Up @@ -3474,6 +3490,15 @@ public void setEnableAssertions(boolean enableAssertions) {
this.enableAssertions = enableAssertions;
}

public boolean isEnableOutputElements() {
return enableOutputElements;
}

@SuppressWarnings("UnusedDeclaration")
public void setEnableOutputElements(boolean enableOutputElements) {
this.enableOutputElements = enableOutputElements;
}

public MavenSession getSession() {
return session;
}
Expand Down
Expand Up @@ -86,6 +86,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
String.class,
String.class,
boolean.class,
boolean.class,
statelessTestsetReporter,
consoleOutputReporter,
statelessTestsetInfoReporter);
Expand All @@ -103,6 +104,7 @@ private Object createStartupReportConfiguration(@Nonnull StartupReportConfigurat
reporterConfiguration.getXsdSchemaLocation(),
reporterConfiguration.getEncoding().name(),
reporterConfiguration.isForking(),
reporterConfiguration.isEnableOutputElements(),
reporterConfiguration.getXmlReporter().clone(surefireClassLoader),
reporterConfiguration.getConsoleOutputReporter().clone(surefireClassLoader),
reporterConfiguration.getTestsetReporter().clone(surefireClassLoader)
Expand Down
Expand Up @@ -85,6 +85,8 @@ public final class StartupReportConfiguration {

private final boolean isForking;

private final boolean enableOutputElements;

private final SurefireStatelessReporter xmlReporter;

private final SurefireConsoleOutputReporter consoleOutputReporter;
Expand All @@ -108,6 +110,7 @@ public StartupReportConfiguration(
String xsdSchemaLocation,
String encoding,
boolean isForking,
boolean enableOutputElements,
SurefireStatelessReporter xmlReporter,
SurefireConsoleOutputReporter consoleOutputReporter,
SurefireStatelessTestsetInfoReporter testsetReporter) {
Expand All @@ -127,6 +130,7 @@ public StartupReportConfiguration(
String charset = trimToNull(encoding);
this.encoding = charset == null ? UTF_8 : Charset.forName(charset);
this.isForking = isForking;
this.enableOutputElements = enableOutputElements;
this.xmlReporter = xmlReporter;
this.consoleOutputReporter = consoleOutputReporter;
this.testsetReporter = testsetReporter;
Expand Down Expand Up @@ -177,6 +181,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> instantiat
trimStackTrace,
rerunFailingTestsCount,
xsdSchemaLocation,
enableOutputElements,
testClassMethodRunHistory);

return xmlReporter.isDisable() ? null : xmlReporter.createListener(xmlReporterConfig);
Expand Down Expand Up @@ -239,6 +244,10 @@ public boolean isForking() {
return isForking;
}

public boolean isEnableOutputElements() {
return enableOutputElements;
}

private File resolveReportsDirectory(Integer forkNumber) {
return forkNumber == null ? reportsDirectory : replaceForkThreadsInPath(reportsDirectory, forkNumber);
}
Expand Down
Expand Up @@ -43,8 +43,15 @@ public DefaultStatelessReportMojoConfiguration(
boolean trimStackTrace,
int rerunFailingTestsCount,
String xsdSchemaLocation,
boolean enableOutputElements,
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory) {
super(reportsDirectory, reportNameSuffix, trimStackTrace, rerunFailingTestsCount, xsdSchemaLocation);
super(
reportsDirectory,
reportNameSuffix,
trimStackTrace,
rerunFailingTestsCount,
xsdSchemaLocation,
enableOutputElements);
this.testClassMethodRunHistory = testClassMethodRunHistory;
}

Expand Down
Expand Up @@ -64,6 +64,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
configuration.getRerunFailingTestsCount(),
configuration.getTestClassMethodRunHistory(),
configuration.getXsdSchemaLocation(),
configuration.isEnableOutputElements(),
getVersion(),
false,
false,
Expand Down
Expand Up @@ -103,6 +103,7 @@ public StatelessReportEventListener<WrappedReportEntry, TestSetStats> createList
configuration.getRerunFailingTestsCount(),
configuration.getTestClassMethodRunHistory(),
configuration.getXsdSchemaLocation(),
configuration.isEnableOutputElements(),
getVersion(),
getUsePhrasedFileName(),
getUsePhrasedTestSuiteClassName(),
Expand Down
Expand Up @@ -29,7 +29,7 @@ class NullStatelessXmlReporter extends StatelessXmlReporter {
static final NullStatelessXmlReporter INSTANCE = new NullStatelessXmlReporter();

private NullStatelessXmlReporter() {
super(null, null, false, 0, null, null, null, false, false, false, false);
super(null, null, false, 0, null, null, true, null, false, false, false, false);
}

@Override
Expand Down
Expand Up @@ -101,6 +101,8 @@ public class StatelessXmlReporter implements StatelessReportEventListener<Wrappe

private final String xsdSchemaLocation;

private final boolean enableOutputElements;

private final String xsdVersion;

// Map between test class name and a map between test method name
Expand All @@ -122,6 +124,7 @@ public StatelessXmlReporter(
int rerunFailingTestsCount,
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistoryMap,
String xsdSchemaLocation,
boolean enableOutputElements,
String xsdVersion,
boolean phrasedFileName,
boolean phrasedSuiteName,
Expand All @@ -133,6 +136,7 @@ public StatelessXmlReporter(
this.rerunFailingTestsCount = rerunFailingTestsCount;
this.testClassMethodRunHistoryMap = testClassMethodRunHistoryMap;
this.xsdSchemaLocation = xsdSchemaLocation;
this.enableOutputElements = enableOutputElements;
this.xsdVersion = xsdVersion;
this.phrasedFileName = phrasedFileName;
this.phrasedSuiteName = phrasedSuiteName;
Expand Down Expand Up @@ -223,11 +227,14 @@ private void serializeTestClassWithoutRerun(
ppw,
methodEntry,
trimStackTrace,
enableOutputElements,
outputStream,
methodEntry.getReportEntryType().getXmlTag(),
false);
}
createOutErrElements(fw, ppw, methodEntry, outputStream);
if (enableOutputElements) {
createOutErrElements(fw, ppw, methodEntry, outputStream);
}
ppw.endElement();
}
}
Expand Down Expand Up @@ -258,10 +265,13 @@ private void serializeTestClassWithRerun(
ppw,
singleRunEntry,
trimStackTrace,
enableOutputElements,
outputStream,
singleRunEntry.getReportEntryType().getXmlTag(),
false);
createOutErrElements(fw, ppw, singleRunEntry, outputStream);
if (enableOutputElements) {
createOutErrElements(fw, ppw, singleRunEntry, outputStream);
}
} else if (singleRunEntry.getReportEntryType() == SKIPPED) {
// The version 3.1.0 should produce a new XSD schema with version 3.1.0, see SUREFIRE-1986,
// and the XSD schema should add a new element "rerunSkipped"
Expand All @@ -274,6 +284,7 @@ private void serializeTestClassWithRerun(
ppw,
singleRunEntry,
trimStackTrace,
enableOutputElements,
outputStream,
singleRunEntry.getReportEntryType().getRerunXmlTag(),
true);
Expand All @@ -299,6 +310,7 @@ private void serializeTestClassWithRerun(
ppw,
singleRunEntry,
trimStackTrace,
enableOutputElements,
outputStream,
singleRunEntry.getReportEntryType().getFlakyXmlTag(),
true);
Expand All @@ -313,6 +325,7 @@ private void serializeTestClassWithRerun(
ppw,
firstMethodEntry,
trimStackTrace,
enableOutputElements,
outputStream,
firstMethodEntry.getReportEntryType().getXmlTag(),
false);
Expand Down Expand Up @@ -430,6 +443,7 @@ private static void getTestProblems(
XMLWriter ppw,
WrappedReportEntry report,
boolean trimStackTrace,
boolean enableOutputElements,
OutputStream fw,
String testErrorType,
boolean createOutErrElementsInside)
Expand Down Expand Up @@ -470,7 +484,7 @@ private static void getTestProblems(
}
}

if (createOutErrElementsInside) {
if (enableOutputElements && createOutErrElementsInside) {
createOutErrElements(outputStreamWriter, ppw, report, fw);
}

Expand Down
Expand Up @@ -82,6 +82,7 @@ public void setup() {
null,
null,
false,
true,
xmlReporter,
consoleOutputReporter,
infoReporter);
Expand Down
Expand Up @@ -162,6 +162,7 @@ public void processShouldExitWithoutSayingGoodBye() throws Exception {
null,
null,
true,
true,
xmlReporter,
outputReporter,
statelessTestsetInfoReporter);
Expand Down Expand Up @@ -247,6 +248,7 @@ public void processShouldWaitForAck() throws Exception {
null,
null,
true,
true,
xmlReporter,
outputReporter,
statelessTestsetInfoReporter);
Expand Down
Expand Up @@ -66,6 +66,7 @@ private static StartupReportConfiguration defaultValue() {
null,
null,
true,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void shouldCreateConsoleListener() {
String schema = "https://maven.apache.org/surefire/maven-surefire-plugin/xsd/surefire-test-report-3.0.xsd";
Map<String, Deque<WrappedReportEntry>> testClassMethodRunHistory = new HashMap<>();
DefaultStatelessReportMojoConfiguration config = new DefaultStatelessReportMojoConfiguration(
reportsDirectory, reportNameSuffix, true, 5, schema, testClassMethodRunHistory);
reportsDirectory, reportNameSuffix, true, 5, schema, true, testClassMethodRunHistory);
SurefireStatelessReporter extension = new SurefireStatelessReporter();

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

assertThat(extension.getVersion()).isEqualTo("3.0");
Expand Down
Expand Up @@ -90,6 +90,7 @@ public void testMergeTestHistoryResult() throws Exception {
null,
null,
false,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down Expand Up @@ -293,6 +294,7 @@ public void testLogger() {
null,
null,
false,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down Expand Up @@ -357,6 +359,7 @@ public void testCreateReporterWithZeroStatistics() {
null,
null,
false,
true,
new SurefireStatelessReporter(),
new SurefireConsoleOutputReporter(),
new SurefireStatelessTestsetInfoReporter());
Expand Down
Expand Up @@ -105,6 +105,7 @@ public void testFileNameWithoutSuffix() {
0,
new ConcurrentHashMap<String, Deque<WrappedReportEntry>>(),
XSD,
true,
"3.0",
false,
false,
Expand Down Expand Up @@ -165,6 +166,7 @@ public void testAllFieldsSerialized() throws IOException {
0,
new ConcurrentHashMap<String, Deque<WrappedReportEntry>>(),
XSD,
true,
"3.0",
false,
false,
Expand Down Expand Up @@ -267,6 +269,7 @@ public void testOutputRerunFlakyFailure() throws IOException {
1,
new HashMap<String, Deque<WrappedReportEntry>>(),
XSD,
true,
"3.0",
false,
false,
Expand Down Expand Up @@ -370,7 +373,7 @@ public void testOutputRerunFlakyAssumption() throws IOException {
rerunStats.testSucceeded(testTwoSecondError);

StatelessXmlReporter reporter = new StatelessXmlReporter(
reportDir, null, false, 1, new HashMap<>(), XSD, "3.0", false, false, false, false);
reportDir, null, false, 1, new HashMap<>(), XSD, true, "3.0", false, false, false, false);

WrappedReportEntry testSetReportEntry = new WrappedReportEntry(
new SimpleReportEntry(
Expand Down
Expand Up @@ -45,4 +45,6 @@ public class ProviderParameterNames {
public static final String PARALLEL_TIMEOUTFORCED_PROP = "paralleltimeoutforced";

public static final String PARALLEL_OPTIMIZE_PROP = "paralleloptimization";

public static final String ENABLE_OUTPUT_ELEMENTS_PROP = "enableoutputelements";
}