This is an automated email from the ASF dual-hosted git repository. tibordigana pushed a commit to branch release/2.22.3 in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit f4dd60ac3fbfd7de0b28e540a9900e8daf325035 Author: Olivier Lamy <ol...@apache.org> AuthorDate: Sun Feb 27 08:15:23 2022 +0100 [SUREFIRE-1426] Fork crash doesn't fail build with -Dmaven.test.failure.ignore=true remove not needed local variable Signed-off-by: Olivier Lamy <ol...@apache.org> fix temporary debug Signed-off-by: Olivier Lamy <ol...@apache.org> [SUREFIRE-1426] Fork crash doesn't fail build with -Dmaven.test.failure.ignore=true, add an IT which show it looks to be fixed with 3.0.0-M6 but was failing with 3.0.0-M5 proposal fix in case of SurefireBooterException (i.e cannot start surefire fork) error must be reported Signed-off-by: Olivier Lamy <ol...@apache.org> (cherry picked from commit 6e60b0389814d8361e453092d3b18f52c3e4bcb1) --- .../maven/plugin/surefire/SurefireHelper.java | 10 ++++- .../Surefire1426JvmCrashShouldNotBeIgnoredIT.java | 47 +++++++++++++++++++++ .../surefire-1426-ignore-fail-jvm-crash/pom.xml | 49 ++++++++++++++++++++++ .../src/test/java/PojoTest.java | 44 +++++++++++++++++++ 4 files changed, 149 insertions(+), 1 deletion(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java index 44dbdd4..964cc8c 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java @@ -24,6 +24,7 @@ import org.apache.maven.execution.MavenSession; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.surefire.log.PluginConsoleLogger; +import org.apache.maven.surefire.booter.SurefireBooterForkException; import org.apache.maven.surefire.cli.CommandLineOption; import org.apache.maven.surefire.suite.RunResult; import org.apache.maven.surefire.testset.TestSetFailedException; @@ -154,7 +155,14 @@ public final class SurefireHelper if ( reportParameters.isTestFailureIgnore() ) { - log.error( createErrorMessage( reportParameters, result, firstForkException ) ); + String errorMessage = createErrorMessage( reportParameters, result, firstForkException ); + + if ( firstForkException instanceof SurefireBooterForkException ) + { + throw new MojoExecutionException( errorMessage, firstForkException ); + } + + log.error( errorMessage ); } else { diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1426JvmCrashShouldNotBeIgnoredIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1426JvmCrashShouldNotBeIgnoredIT.java new file mode 100644 index 0000000..5a575ab --- /dev/null +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1426JvmCrashShouldNotBeIgnoredIT.java @@ -0,0 +1,47 @@ +package org.apache.maven.surefire.its.jiras; + +/* + * 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. + */ + +import org.apache.maven.it.VerificationException; +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.junit.Test; + +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.is; + +/** + * Test https://issues.apache.org/jira/browse/SUREFIRE-1426 + * + */ +public class Surefire1426JvmCrashShouldNotBeIgnoredIT + extends SurefireJUnit4IntegrationTestCase +{ + @Test + public void mavenShouldFail() throws VerificationException + { + unpack( "surefire-1426-ignore-fail-jvm-crash" ) + .maven() + .withFailure() + .debugLogging() + .executeTest() + .assertThatLogLine( containsString( "BUILD SUCCESS" ), is( 0 ) ) + .verifyTextInLog( "BUILD FAILURE" ); + } +} diff --git a/surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/pom.xml b/surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/pom.xml new file mode 100644 index 0000000..103a39c --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/pom.xml @@ -0,0 +1,49 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ 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. + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <groupId>org.apache.maven.plugins.surefire</groupId> + <artifactId>SUREFIRE-1426</artifactId> + <version>1.0-SNAPSHOT</version> + <name>SUREFIRE-1426</name> + + <properties> + <maven.compiler.source>1.8</maven.compiler.source> + <maven.compiler.target>1.8</maven.compiler.target> + </properties> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>${surefire.version}</version> + <configuration> + <argLine>-Dfile.encoding=UTF-8 -Duser.language=en -XFFOOOBEEER -Duser.region=US -showversion -Xmx6g -Xms2g -XX:+PrintGCDetails </argLine> + <testFailureIgnore>true</testFailureIgnore> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/src/test/java/PojoTest.java b/surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/src/test/java/PojoTest.java new file mode 100644 index 0000000..18fad81 --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/src/test/java/PojoTest.java @@ -0,0 +1,44 @@ +/* + * 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. + */ + +public class PojoTest +{ + private static int calls; + + public void setUp() + { + System.out.println( "setUp called " + ++calls ); + } + + public void tearDown() + { + System.out.println( "tearDown called " + calls ); + } + + public void testSuccess() + { + assert true; + } + + public void testFailure() + { + assert false; + } + +}