You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2022/03/25 00:40:04 UTC

[maven-surefire] branch SUREFIRE-1426_2 updated (7bd4b91 -> 2afac29)

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a change to branch SUREFIRE-1426_2
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git.


    omit 7bd4b91  [SUREFIRE-1426] Fork crash doesn't fail build with -Dmaven.test.failure.ignore=true
     new 2afac29  [SUREFIRE-1426] Fork crash doesn't fail build with -Dmaven.test.failure.ignore=true

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (7bd4b91)
            \
             N -- N -- N   refs/heads/SUREFIRE-1426_2 (2afac29)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 ...> Surefire1426JvmCrashShouldNotBeIgnoredIT.java} | 21 +++++++++++++--------
 .../pom.xml                                         | 11 +++++------
 .../src/test/java/PojoTest.java                     |  0
 3 files changed, 18 insertions(+), 14 deletions(-)
 copy surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/{Surefire408ManualProviderSelectionIT.java => Surefire1426JvmCrashShouldNotBeIgnoredIT.java} (66%)
 copy surefire-its/src/test/resources/{pojo-simple => surefire-1426-ignore-fail-jvm-crash}/pom.xml (83%)
 copy surefire-its/src/test/resources/{pojo-simple => surefire-1426-ignore-fail-jvm-crash}/src/test/java/PojoTest.java (100%)

[maven-surefire] 01/01: [SUREFIRE-1426] Fork crash doesn't fail build with -Dmaven.test.failure.ignore=true

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch SUREFIRE-1426_2
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 2afac2917a38b400126284e432de0329b32c3fd5
Author: Olivier Lamy <ol...@apache.org>
AuthorDate: Sun Feb 27 17:15:23 2022 +1000

    [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>
---
 .../maven/plugin/surefire/SurefireHelper.java      | 10 ++++-
 .../plugin/surefire/AbstractSurefireMojoTest.java  |  5 ++-
 .../maven/plugin/surefire/SurefireHelperTest.java  | 42 +++++++++++++++++++
 .../Surefire1426JvmCrashShouldNotBeIgnoredIT.java  | 47 +++++++++++++++++++++
 .../surefire-1426-ignore-fail-jvm-crash/pom.xml    | 49 ++++++++++++++++++++++
 .../src/test/java/PojoTest.java                    | 44 +++++++++++++++++++
 6 files changed, 194 insertions(+), 3 deletions(-)

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 1870223..5822451 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.plugin.surefire.log.PluginConsoleLogger;
 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;
@@ -156,7 +157,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/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
index 9d89447..8bcf947 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
@@ -2000,6 +2000,7 @@ public class AbstractSurefireMojoTest
         private List<String> includes;
         private List<String> excludes;
         private String test;
+        private boolean testFailureIgnore;
 
         private JUnitPlatformProviderInfo createJUnitPlatformProviderInfo( Artifact junitPlatformArtifact,
                                                                            TestClassPath testClasspathWrapper )
@@ -2075,13 +2076,13 @@ public class AbstractSurefireMojoTest
         @Override
         public boolean isTestFailureIgnore()
         {
-            return false;
+            return testFailureIgnore;
         }
 
         @Override
         public void setTestFailureIgnore( boolean testFailureIgnore )
         {
-
+            this.testFailureIgnore = testFailureIgnore;
         }
 
         @Override
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java
index 1ecaea7..dbe2c36 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java
@@ -19,12 +19,18 @@ package org.apache.maven.plugin.surefire;
  * under the License.
  */
 
+import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.plugin.surefire.AbstractSurefireMojoTest.Mojo;
+import org.apache.maven.plugin.surefire.log.PluginConsoleLogger;
 import org.apache.maven.surefire.api.suite.RunResult;
+import org.apache.maven.surefire.api.testset.TestSetFailedException;
+import org.apache.maven.surefire.booter.SurefireBooterForkException;
+import org.codehaus.plexus.logging.Logger;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
+import org.mockito.ArgumentCaptor;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -36,7 +42,13 @@ import static org.apache.maven.plugin.surefire.SurefireHelper.escapeToPlatformPa
 import static org.apache.maven.plugin.surefire.SurefireHelper.reportExecution;
 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.Matchers.containsString;
 import static org.junit.Assume.assumeTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import static org.powermock.api.mockito.PowerMockito.doNothing;
+import static org.powermock.api.mockito.PowerMockito.mock;
 
 /**
  * Test of {@link SurefireHelper}.
@@ -121,6 +133,36 @@ public class SurefireHelperTest
     }
 
     @Test
+    public void shouldHandleFailWithoutExitCode() throws Exception
+    {
+        RunResult summary = new RunResult( 0, 0, 0, 0 );
+        Mojo plugin = new Mojo();
+        plugin.setTestFailureIgnore( true );
+
+        Logger logger = mock( Logger.class );
+        when( logger.isErrorEnabled() ).thenReturn( true );
+        doNothing().when( logger ).error( anyString() );
+        TestSetFailedException exc = new TestSetFailedException( "failure" );
+        reportExecution( plugin, summary, new PluginConsoleLogger( logger ), exc );
+        ArgumentCaptor<String> errorMessage = ArgumentCaptor.forClass( String.class );
+        verify( logger ).error( errorMessage.capture() );
+        assertThat( errorMessage.getValue() ).contains( "failure" );
+    }
+
+    @Test
+    public void shouldHandleFailIfJvmNonZeroExitCode() throws Exception
+    {
+        RunResult summary = new RunResult( 0, 0, 0, 0 );
+        Mojo plugin = new Mojo();
+        plugin.setTestFailureIgnore( true );
+
+        SurefireBooterForkException exc = new SurefireBooterForkException( "Unrecognized option: -Xxxx" );
+        e.expect( MojoExecutionException.class );
+        e.expectMessage( containsString( "Unrecognized option: -Xxxx" ) );
+        reportExecution( plugin, summary, new PluginConsoleLogger( mock( Logger.class ) ), exc );
+    }
+
+    @Test
     public void shouldHandleFailIfNoTests() throws Exception
     {
         RunResult summary = new RunResult( 0, 0, 0, 0 );
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;
+    }
+
+}