Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertgrzeskowiak committed Oct 30, 2024
2 parents 4f52c2d + d24adb4 commit 4cb82fe
Show file tree
Hide file tree
Showing 46 changed files with 305 additions and 317 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* text=auto

*.xml text diff=xml
*.xsd text diff=xml
*.java text diff=java
*.html text diff=html
*.vm text
Expand Down
2 changes: 1 addition & 1 deletion maven-failsafe-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>3.5.1-SNAPSHOT</version>
<version>3.5.2-SNAPSHOT</version>
</parent>

<groupId>org.apache.maven.plugins</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public final class FailsafeSummaryXmlUtils {
+ " <errors>%d</errors>\n"
+ " <failures>%d</failures>\n"
+ " <skipped>%d</skipped>\n"
+ " <flakes>%d</flakes>\n"
+ " %s\n"
+ "</failsafe-summary>";

Expand All @@ -84,12 +85,16 @@ public static RunResult toRunResult(File failsafeSummaryXml) throws Exception {
String skipped = xpath.evaluate("/failsafe-summary/skipped", root);
String failureMessage = xpath.evaluate("/failsafe-summary/failureMessage", root);
String timeout = xpath.evaluate("/failsafe-summary/@timeout", root);
String flakes = xpath.evaluate("/failsafe-summary/flakes", root);

return new RunResult(
parseInt(completed),
parseInt(errors),
parseInt(failures),
parseInt(skipped),
// FIXME Backwards compatability: to be replaced with parseInt in a future release
// synchronize with maven-surefire-plugin/src/site/resources/xsd/failsafe-summary.xsd
isBlank(flakes) ? 0 : parseInt(flakes),
isBlank(failureMessage) ? null : unescapeXml(failureMessage),
parseBoolean(timeout));
}
Expand All @@ -107,6 +112,7 @@ public static void fromRunResultToFile(RunResult fromRunResult, File toFailsafeS
fromRunResult.getErrors(),
fromRunResult.getFailures(),
fromRunResult.getSkipped(),
fromRunResult.getFlakes(),
msg);

Files.write(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
package org.apache.maven.plugin.failsafe;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.StandardOpenOption;
import java.util.Locale;

import org.apache.maven.plugin.failsafe.util.FailsafeSummaryXmlUtils;
import org.apache.maven.surefire.api.suite.RunResult;
import org.apache.maven.surefire.api.util.SureFireFileManager;
import org.junit.Test;

import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThat;

/**
Expand Down Expand Up @@ -64,6 +69,49 @@ public void testSkipped() throws Exception {
writeReadCheck(new RunResult(3, 2, 1, 0, null, true));
}

@Test
public void testFlakes() throws Exception {
writeReadCheck(new RunResult(3, 2, 1, 0, 2, null, true));
}

@Test
public void testLegacyDeserialization() throws Exception {
File legacySummary = SureFireFileManager.createTempFile("failsafe", "test");
String legacyFailsafeSummaryXmlTemplate = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<failsafe-summary xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""
+ " xsi:noNamespaceSchemaLocation=\"https://maven.apache.org/surefire/maven-surefire-plugin/xsd/failsafe-summary.xsd\""
+ " result=\"%s\" timeout=\"%s\">\n"
+ " <completed>%d</completed>\n"
+ " <errors>%d</errors>\n"
+ " <failures>%d</failures>\n"
+ " <skipped>%d</skipped>\n"
+ " %s\n"
+ "</failsafe-summary>";
String xml = format(Locale.ROOT, legacyFailsafeSummaryXmlTemplate, 0, false, 3, 2, 1, 0, "msg");
Files.write(
legacySummary.toPath(),
xml.getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING,
StandardOpenOption.WRITE);

// When the failsafe-summary.xml does not contain the <flakes> element, it should be considered as 0.
RunResult expected = new RunResult(3, 2, 1, 0, 0, null, false);
RunResult actual = FailsafeSummaryXmlUtils.toRunResult(legacySummary);

assertThat(actual.getCompletedCount()).isEqualTo(expected.getCompletedCount());

assertThat(actual.getErrors()).isEqualTo(expected.getErrors());

assertThat(actual.getFailures()).isEqualTo(expected.getFailures());

assertThat(actual.getSkipped()).isEqualTo(expected.getSkipped());

assertThat(actual.getFlakes()).isEqualTo(expected.getFlakes());

assertThat(actual).isEqualTo(expected);
}

@Test
public void testAppendSerialization() throws Exception {
RunResult simpleAggregate = getSimpleAggregate();
Expand Down
2 changes: 1 addition & 1 deletion maven-surefire-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>3.5.1-SNAPSHOT</version>
<version>3.5.2-SNAPSHOT</version>
</parent>

<artifactId>maven-surefire-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ private static String createErrorMessage(
.append(reportParameters.getFailOnFlakeCount())
.append(".");
}
msg.append("\n\nPlease refer to ")
msg.append("\n\nSee ")
.append(reportParameters.getReportsDirectory())
.append(" for the individual test results.")
.append('\n')
.append("Please refer to dump files (if any exist) ")
.append("See dump files (if any exist) ")
.append(DUMP_FILES_PRINT[0])
.append(", ")
.append(DUMP_FILES_PRINT[1])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ public void shouldHandleFailIfNoTests() throws Exception {
public void shouldHandleTestFailure() throws Exception {
RunResult summary = new RunResult(1, 0, 1, 0);
e.expect(MojoFailureException.class);
e.expectMessage("There are test failures.\n\nPlease refer to null "
+ "for the individual test results.\nPlease refer to dump files (if any exist) "
e.expectMessage("There are test failures.\n\nSee null "
+ "for the individual test results.\nSee dump files (if any exist) "
+ "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream.");
reportExecution(new Mojo(), summary, null, null);
}
Expand All @@ -175,8 +175,8 @@ public void failsIfThereAreTooManyFlakes() throws Exception {
Mojo reportParameters = new Mojo();
reportParameters.setFailOnFlakeCount(1);
e.expect(MojoFailureException.class);
e.expectMessage("There is 1 flake and failOnFlakeCount is set to 1.\n\nPlease refer to null "
+ "for the individual test results.\nPlease refer to dump files (if any exist) "
e.expectMessage("There is 1 flake and failOnFlakeCount is set to 1.\n\nSee null "
+ "for the individual test results.\nSee dump files (if any exist) "
+ "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream.");
reportExecution(reportParameters, summary, null, null);
}
Expand All @@ -188,8 +188,8 @@ public void reportsFailuresAndFlakes() throws Exception {
reportParameters.setFailOnFlakeCount(1);
e.expect(MojoFailureException.class);
e.expectMessage("There are test failures.\nThere are 2 flakes and failOnFlakeCount is set to 1."
+ "\n\nPlease refer to null "
+ "for the individual test results.\nPlease refer to dump files (if any exist) "
+ "\n\nSee null "
+ "for the individual test results.\nSee dump files (if any exist) "
+ "[date].dump, [date]-jvmRun[N].dump and [date].dumpstream.");
reportExecution(reportParameters, summary, null, null);
}
Expand Down
2 changes: 1 addition & 1 deletion maven-surefire-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire</artifactId>
<version>3.5.1-SNAPSHOT</version>
<version>3.5.2-SNAPSHOT</version>
</parent>

<groupId>org.apache.maven.plugins</groupId>
Expand Down
4 changes: 2 additions & 2 deletions maven-surefire-plugin/src/site/fml/faq.fml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ under the License.
<question>What is the difference between maven-failsafe-plugin and maven-surefire-plugin?</question>
<answer>
<p>
<a href="http://maven.apache.org/plugins/maven-surefire-plugin">maven-surefire-plugin</a>
<a href="http://maven.apache.org/plugins/maven-surefire-plugin/">maven-surefire-plugin</a>
is designed for running unit tests and if any of the tests fail then it will fail the build immediately.
</p>
<p>
<a href="http://maven.apache.org/plugins/maven-failsafe-plugin">maven-failsafe-plugin</a>
<a href="http://maven.apache.org/plugins/maven-failsafe-plugin/">maven-failsafe-plugin</a>
is designed for running integration tests, and decouples failing the build if there
are test failures from actually running the tests.
</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!--~ Licensed to the Apache Software Foundation (ASF) under one~ or more contributor license agreements. See the NOTICE file~ distributed with this work for additional information~ regarding copyright ownership. The ASF licenses this file~ to you under the Apache License, Version 2.0 (the~ "License"); you may not use this file except in compliance~ with the License. You may obtain a copy of the License at~~ http://www.apache.org/licenses/LICENSE-2.0~~ Unless required by applicable law or agreed to in writing,~ software distributed under the License is distributed on an~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY~ KIND, either express or implied. See the License for the~ specific language governing permissions and limitations~ under the License.--><xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <xsd:element name="failsafe-summary"> <xsd:complexType> <xsd:sequence> <xsd:element name="completed" type="xsd:int"/> <xsd:element name="errors" type="xsd:int"/> <xsd:element name="failures" type="xsd:int"/> <xsd:element name="skipped" type="xsd:int"/> <xsd:element name="failureMessage" type="xsd:string" nillable="true"/> </xsd:sequence> <xsd:attribute name="result" type="errorType" use="optional"/> <xsd:attribute name="timeout" type="xsd:boolean" use="required"/> </xsd:complexType> </xsd:element> <xsd:simpleType name="errorType"> <xsd:restriction base="xsd:string"> <xsd:enumeration id="FAILURE" value="255"/> <xsd:enumeration id="NO_TESTS" value="254"/> </xsd:restriction> </xsd:simpleType></xsd:schema>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<xsd:schema version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="failsafe-summary">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="completed" type="xsd:int"/>
<xsd:element name="errors" type="xsd:int"/>
<xsd:element name="failures" type="xsd:int"/>
<xsd:element name="skipped" type="xsd:int"/>
<xsd:element name="flakes" type="xsd:int" minOccurs="0"/>
<xsd:element name="failureMessage" type="xsd:string" nillable="true"/>
</xsd:sequence>
<xsd:attribute name="result" type="errorType" use="optional"/>
<xsd:attribute name="timeout" type="xsd:boolean" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="errorType">
<xsd:restriction base="xsd:string">
<xsd:enumeration id="FAILURE" value="255"/>
<xsd:enumeration id="NO_TESTS" value="254"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>

Loading

0 comments on commit 4cb82fe

Please sign in to comment.