Skip to content

Commit 6e60b03

Browse files
olamyTibor17
authored andcommitted
[SUREFIRE-1426] Fork crash doesn't fail build with -Dmaven.test.failure.ignore=true
remove not needed local variable Signed-off-by: Olivier Lamy <[email protected]> fix temporary debug Signed-off-by: Olivier Lamy <[email protected]> [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 <[email protected]>
1 parent 8bf29be commit 6e60b03

File tree

6 files changed

+194
-3
lines changed

6 files changed

+194
-3
lines changed

maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/SurefireHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.maven.surefire.api.cli.CommandLineOption;
2828
import org.apache.maven.surefire.api.suite.RunResult;
2929
import org.apache.maven.surefire.api.testset.TestSetFailedException;
30+
import org.apache.maven.surefire.booter.SurefireBooterForkException;
3031

3132
import javax.annotation.Nonnull;
3233
import java.io.File;
@@ -156,7 +157,14 @@ public static void reportExecution( SurefireReportParameters reportParameters, R
156157

157158
if ( reportParameters.isTestFailureIgnore() )
158159
{
159-
log.error( createErrorMessage( reportParameters, result, firstForkException ) );
160+
String errorMessage = createErrorMessage( reportParameters, result, firstForkException );
161+
162+
if ( firstForkException instanceof SurefireBooterForkException )
163+
{
164+
throw new MojoExecutionException( errorMessage, firstForkException );
165+
}
166+
167+
log.error( errorMessage );
160168
}
161169
else
162170
{

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,7 @@ public static class Mojo
20002000
private List<String> includes;
20012001
private List<String> excludes;
20022002
private String test;
2003+
private boolean testFailureIgnore;
20032004

20042005
private JUnitPlatformProviderInfo createJUnitPlatformProviderInfo( Artifact junitPlatformArtifact,
20052006
TestClassPath testClasspathWrapper )
@@ -2075,13 +2076,13 @@ public void setSkip( boolean skip )
20752076
@Override
20762077
public boolean isTestFailureIgnore()
20772078
{
2078-
return false;
2079+
return testFailureIgnore;
20792080
}
20802081

20812082
@Override
20822083
public void setTestFailureIgnore( boolean testFailureIgnore )
20832084
{
2084-
2085+
this.testFailureIgnore = testFailureIgnore;
20852086
}
20862087

20872088
@Override

maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/SurefireHelperTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,18 @@
1919
* under the License.
2020
*/
2121

22+
import org.apache.maven.plugin.MojoExecutionException;
2223
import org.apache.maven.plugin.MojoFailureException;
2324
import org.apache.maven.plugin.surefire.AbstractSurefireMojoTest.Mojo;
25+
import org.apache.maven.plugin.surefire.log.PluginConsoleLogger;
2426
import org.apache.maven.surefire.api.suite.RunResult;
27+
import org.apache.maven.surefire.api.testset.TestSetFailedException;
28+
import org.apache.maven.surefire.booter.SurefireBooterForkException;
29+
import org.codehaus.plexus.logging.Logger;
2530
import org.junit.Rule;
2631
import org.junit.Test;
2732
import org.junit.rules.ExpectedException;
33+
import org.mockito.ArgumentCaptor;
2834

2935
import java.io.File;
3036
import java.util.ArrayList;
@@ -36,7 +42,13 @@
3642
import static org.apache.maven.plugin.surefire.SurefireHelper.reportExecution;
3743
import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
3844
import static org.assertj.core.api.Assertions.assertThat;
45+
import static org.hamcrest.Matchers.containsString;
3946
import static org.junit.Assume.assumeTrue;
47+
import static org.mockito.ArgumentMatchers.anyString;
48+
import static org.mockito.Mockito.verify;
49+
import static org.mockito.Mockito.when;
50+
import static org.powermock.api.mockito.PowerMockito.doNothing;
51+
import static org.powermock.api.mockito.PowerMockito.mock;
4052

4153
/**
4254
* Test of {@link SurefireHelper}.
@@ -120,6 +132,36 @@ public void shouldEscapeWindowsPath()
120132
assertThat( escaped ).isEqualTo( root + "\\" + pathToJar );
121133
}
122134

135+
@Test
136+
public void shouldHandleFailWithoutExitCode() throws Exception
137+
{
138+
RunResult summary = new RunResult( 0, 0, 0, 0 );
139+
Mojo plugin = new Mojo();
140+
plugin.setTestFailureIgnore( true );
141+
142+
Logger logger = mock( Logger.class );
143+
when( logger.isErrorEnabled() ).thenReturn( true );
144+
doNothing().when( logger ).error( anyString() );
145+
TestSetFailedException exc = new TestSetFailedException( "failure" );
146+
reportExecution( plugin, summary, new PluginConsoleLogger( logger ), exc );
147+
ArgumentCaptor<String> errorMessage = ArgumentCaptor.forClass( String.class );
148+
verify( logger ).error( errorMessage.capture() );
149+
assertThat( errorMessage.getValue() ).contains( "failure" );
150+
}
151+
152+
@Test
153+
public void shouldHandleFailIfJvmNonZeroExitCode() throws Exception
154+
{
155+
RunResult summary = new RunResult( 0, 0, 0, 0 );
156+
Mojo plugin = new Mojo();
157+
plugin.setTestFailureIgnore( true );
158+
159+
SurefireBooterForkException exc = new SurefireBooterForkException( "Unrecognized option: -Xxxx" );
160+
e.expect( MojoExecutionException.class );
161+
e.expectMessage( containsString( "Unrecognized option: -Xxxx" ) );
162+
reportExecution( plugin, summary, new PluginConsoleLogger( mock( Logger.class ) ), exc );
163+
}
164+
123165
@Test
124166
public void shouldHandleFailIfNoTests() throws Exception
125167
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package org.apache.maven.surefire.its.jiras;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.apache.maven.it.VerificationException;
23+
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
24+
import org.junit.Test;
25+
26+
import static org.hamcrest.Matchers.containsString;
27+
import static org.hamcrest.Matchers.is;
28+
29+
/**
30+
* Test https://issues.apache.org/jira/browse/SUREFIRE-1426
31+
*
32+
*/
33+
public class Surefire1426JvmCrashShouldNotBeIgnoredIT
34+
extends SurefireJUnit4IntegrationTestCase
35+
{
36+
@Test
37+
public void mavenShouldFail() throws VerificationException
38+
{
39+
unpack( "surefire-1426-ignore-fail-jvm-crash" )
40+
.maven()
41+
.withFailure()
42+
.debugLogging()
43+
.executeTest()
44+
.assertThatLogLine( containsString( "BUILD SUCCESS" ), is( 0 ) )
45+
.verifyTextInLog( "BUILD FAILURE" );
46+
}
47+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.apache.maven.plugins.surefire</groupId>
27+
<artifactId>SUREFIRE-1426</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
<name>SUREFIRE-1426</name>
30+
31+
<properties>
32+
<maven.compiler.source>1.8</maven.compiler.source>
33+
<maven.compiler.target>1.8</maven.compiler.target>
34+
</properties>
35+
36+
<build>
37+
<plugins>
38+
<plugin>
39+
<groupId>org.apache.maven.plugins</groupId>
40+
<artifactId>maven-surefire-plugin</artifactId>
41+
<version>${surefire.version}</version>
42+
<configuration>
43+
<argLine>-Dfile.encoding=UTF-8 -Duser.language=en -XFFOOOBEEER -Duser.region=US -showversion -Xmx6g -Xms2g -XX:+PrintGCDetails </argLine>
44+
<testFailureIgnore>true</testFailureIgnore>
45+
</configuration>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
public class PojoTest
21+
{
22+
private static int calls;
23+
24+
public void setUp()
25+
{
26+
System.out.println( "setUp called " + ++calls );
27+
}
28+
29+
public void tearDown()
30+
{
31+
System.out.println( "tearDown called " + calls );
32+
}
33+
34+
public void testSuccess()
35+
{
36+
assert true;
37+
}
38+
39+
public void testFailure()
40+
{
41+
assert false;
42+
}
43+
44+
}

0 commit comments

Comments
 (0)