From 006c4d344062777d6289ca4fb38a9cd58651e31c Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Sun, 27 Feb 2022 17:15:23 +1000 Subject: [PATCH] [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 --- .../maven/plugin/surefire/SurefireHelper.java | 7 ++- ...efire1426JvmCrashShouldNotBeIgnoredIT.java | 51 +++++++++++++++++++ .../pom.xml | 49 ++++++++++++++++++ .../src/test/java/PojoTest.java | 44 ++++++++++++++++ 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1426JvmCrashShouldNotBeIgnoredIT.java create mode 100644 surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/pom.xml create mode 100644 surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/src/test/java/PojoTest.java 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 1870223f55..d6e7fd47c5 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 @@ -27,6 +27,7 @@ import org.apache.maven.surefire.api.cli.CommandLineOption; import org.apache.maven.surefire.api.suite.RunResult; import org.apache.maven.surefire.api.testset.TestSetFailedException; +import org.apache.maven.surefire.booter.SurefireBooterForkException; import javax.annotation.Nonnull; import java.io.File; @@ -154,7 +155,11 @@ public static void reportExecution( SurefireReportParameters reportParameters, R return; } - if ( reportParameters.isTestFailureIgnore() ) + if ( firstForkException instanceof SurefireBooterForkException ) + { + throwException( reportParameters, result, firstForkException ); + } + else if ( reportParameters.isTestFailureIgnore() ) { log.error( createErrorMessage( reportParameters, result, firstForkException ) ); } 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 0000000000..a11b6ac069 --- /dev/null +++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1426JvmCrashShouldNotBeIgnoredIT.java @@ -0,0 +1,51 @@ +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 java.util.List; + +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 + { + List logs = unpack( "surefire-1426-ignore-fail-jvm-crash" ) + .maven() + .withFailure() + .debugLogging() + .executeTest() + .assertThatLogLine( containsString( "BUILD SUCCESS" ), is( 0 ) ) + .verifyTextInLog( "BUILD FAILURE" ) + .loadLogLines(); + logs.stream().forEach( line -> System.out.println( line ) ); + } +} 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 0000000000..103a39c1ba --- /dev/null +++ b/surefire-its/src/test/resources/surefire-1426-ignore-fail-jvm-crash/pom.xml @@ -0,0 +1,49 @@ + + + + + 4.0.0 + + org.apache.maven.plugins.surefire + SUREFIRE-1426 + 1.0-SNAPSHOT + SUREFIRE-1426 + + + 1.8 + 1.8 + + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + -Dfile.encoding=UTF-8 -Duser.language=en -XFFOOOBEEER -Duser.region=US -showversion -Xmx6g -Xms2g -XX:+PrintGCDetails + true + + + + + 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 0000000000..18fad81681 --- /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; + } + +}