-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SUREFIRE-1614] JUnit Runner that writes to System.out corrupts Suref…
…ire's STDOUT when using JUnit's Vintage Engine
- Loading branch information
Showing
5 changed files
with
156 additions
and
28 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
...fire-its/src/test/java/org/apache/maven/surefire/its/JUnitPlatformStreamCorruptionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.apache.maven.surefire.its; | ||
|
||
/* | ||
* 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.OutputValidator; | ||
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; | ||
import static org.fest.assertions.Assertions.assertThat; | ||
import static org.hamcrest.CoreMatchers.startsWith; | ||
|
||
public class JUnitPlatformStreamCorruptionIT | ||
extends SurefireJUnit4IntegrationTestCase | ||
{ | ||
@Before | ||
public void setUp() | ||
{ | ||
assumeJavaVersion( 1.8d ); | ||
} | ||
|
||
@Test | ||
public void warningIsNotEmitted() throws VerificationException | ||
{ | ||
OutputValidator validator = unpack( "/surefire-1614-stream-corruption" ) | ||
.executeTest() | ||
.verifyErrorFree( 1 ); | ||
|
||
List<String> lines = validator.loadLogLines( | ||
startsWith( "[WARNING] Corrupted STDOUT by directly writing to native stream in forked JVM" ) ); | ||
|
||
assertThat( lines ) | ||
.isEmpty(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
surefire-its/src/test/resources/surefire-1614-stream-corruption/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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>junit-platform-1.0.0</artifactId> | ||
<version>1.0</version> | ||
<name>[SUREFIRE-1614] JUnit 5: Vintage Output Stream Corruption</name> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
<version>5.3.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>${surefire.version}</version> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
22 changes: 22 additions & 0 deletions
22
...esources/surefire-1614-stream-corruption/src/test/java/com/example/demo/CustomRunner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.demo; | ||
|
||
import org.junit.runners.BlockJUnit4ClassRunner; | ||
import org.junit.runners.model.InitializationError; | ||
import org.junit.runners.model.TestClass; | ||
|
||
public class CustomRunner | ||
extends BlockJUnit4ClassRunner | ||
{ | ||
|
||
public CustomRunner( Class<?> klass ) throws InitializationError | ||
{ | ||
super( klass ); | ||
} | ||
|
||
@Override | ||
protected TestClass createTestClass( Class<?> testClass ) | ||
{ | ||
System.out.println( "Creating test class" ); | ||
return super.createTestClass( testClass ); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...e-1614-stream-corruption/src/test/java/com/example/demo/SurefireStreamCorruptionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.example.demo; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith( CustomRunner.class ) | ||
public class SurefireStreamCorruptionTest | ||
{ | ||
@Test | ||
public void contextLoads() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters