You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kr...@apache.org on 2013/03/26 17:04:03 UTC
[7/7] git commit: [SUREFIRE-972] Bizarre noclassdef found
[SUREFIRE-972] Bizarre noclassdef found
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/ebd229df
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/ebd229df
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/ebd229df
Branch: refs/heads/surfire97
Commit: ebd229df566aa3661f060458b289413ecd6c9374
Parents: c1e06f8
Author: Kristian Rosenvold <kr...@apache.org>
Authored: Tue Mar 26 16:52:33 2013 +0100
Committer: Kristian Rosenvold <kr...@apache.org>
Committed: Tue Mar 26 17:03:52 2013 +0100
----------------------------------------------------------------------
.../maven/surefire/booter/ForkingRunListener.java | 2 +-
.../maven/surefire/booter/ProviderFactory.java | 2 +-
.../surefire-972-bizarre-noclassdef/boom/pom.xml | 51 +++++++++++++++
.../org/apache/maven/surefire/crb/ClassRuleIT.java | 24 +++++++
.../class-rule/pom.xml | 17 +++++
.../ExampleClassRule.java | 29 ++++++++
.../surefire-972-bizarre-noclassdef/pom.xml | 32 +++++++++
.../surefire/common/junit4/JUnit4RunListener.java | 22 ++++++-
8 files changed, 175 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
index d20fcf2..bbc6078 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
@@ -129,7 +129,7 @@ public class ForkingRunListener
public void testError( ReportEntry report )
{
- target.print( toString( BOOTERCODE_TEST_ERROR, report, testSetChannelId ) );
+ target.print( toString( BOOTERCODE_TEST_ERROR, report, testSetChannelId ) );
}
public void testFailed( ReportEntry report )
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
----------------------------------------------------------------------
diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
index a21da57..5d9e4b1 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ProviderFactory.java
@@ -113,7 +113,7 @@ public class ProviderFactory
surefireReflector.setIfDirScannerAware( o, providerConfiguration.getDirScannerParams() );
Object provider = surefireReflector.instantiateProvider( starterConfiguration.getProviderClassName(), o );
- Thread.currentThread().setContextClassLoader( systemClassLoader );
+// Thread.currentThread().setContextClassLoader( systemClassLoader );
return new ProviderProxy( provider, testsClassLoader );
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/pom.xml b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/pom.xml
new file mode 100644
index 0000000..d5e9fbc
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/pom.xml
@@ -0,0 +1,51 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>class-rule-boom-boom</artifactId>
+ <parent>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>class-rule-boom</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>class-rule</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${surefire.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ <configuration>
+ <forkMode>always</forkMode>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>surefire-junit47</artifactId>
+ <version>${surefire.version}</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ </plugins>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/src/test/java/org/apache/maven/surefire/crb/ClassRuleIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/src/test/java/org/apache/maven/surefire/crb/ClassRuleIT.java b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/src/test/java/org/apache/maven/surefire/crb/ClassRuleIT.java
new file mode 100644
index 0000000..5554fd9
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/boom/src/test/java/org/apache/maven/surefire/crb/ClassRuleIT.java
@@ -0,0 +1,24 @@
+package org.apache.maven.surefire.crb;
+
+import org.junit.Assert;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: benson
+ * Date: 3/16/13
+ * Time: 11:00 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ClassRuleIT extends Assert {
+
+ @ClassRule
+ public static ExampleClassRule rule = new ExampleClassRule(ExampleClassRule.someStaticFunction());
+
+ @Test
+ public void dummyTest() {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/pom.xml b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/pom.xml
new file mode 100644
index 0000000..e9f44e3
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/pom.xml
@@ -0,0 +1,17 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>class-rule</artifactId>
+ <parent>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>class-rule-boom</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/src/main/java/org.apache.maven.surefire.crb/ExampleClassRule.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/src/main/java/org.apache.maven.surefire.crb/ExampleClassRule.java b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/src/main/java/org.apache.maven.surefire.crb/ExampleClassRule.java
new file mode 100644
index 0000000..430f7d2
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/class-rule/src/main/java/org.apache.maven.surefire.crb/ExampleClassRule.java
@@ -0,0 +1,29 @@
+package org.apache.maven.surefire.crb;
+
+import org.junit.rules.ExternalResource;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: benson
+ * Date: 3/16/13
+ * Time: 10:52 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class ExampleClassRule extends ExternalResource {
+
+ public ExampleClassRule(String dummy) {
+ //
+ }
+
+ protected void before() throws Throwable {
+ System.err.println("ExampleClassRule.before()");
+ }
+
+ protected void after() {
+ System.err.println("ExampleClassRule.after()");
+ }
+
+ public static String someStaticFunction() {
+ throw new RuntimeException("Surprise!");
+ }
+}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/pom.xml b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/pom.xml
new file mode 100644
index 0000000..be4df33
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/surefire-972-bizarre-noclassdef/pom.xml
@@ -0,0 +1,32 @@
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.maven.surefire</groupId>
+ <artifactId>class-rule-boom</artifactId>
+ <packaging>pom</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <modules>
+ <module>class-rule</module>
+ <module>boom</module>
+ </modules>
+ <build>
+ <pluginManagement>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <showDeprecation>true</showDeprecation>
+ <showWarnings>true</showWarnings>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.14</version>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+</project>
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ebd229df/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
----------------------------------------------------------------------
diff --git a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
index 50c7498..ed2a9b7 100644
--- a/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
+++ b/surefire-providers/common-junit4/src/main/java/org/apache/maven/surefire/common/junit4/JUnit4RunListener.java
@@ -98,8 +98,12 @@ public class JUnit4RunListener
public void testFailure( Failure failure )
throws Exception
{
+ String testHeader = failure.getTestHeader();
+ if (isInsaneJunitNullString( testHeader )){
+ testHeader = "Failure when constructing test";
+ }
ReportEntry report =
- SimpleReportEntry.withException( getClassName( failure.getDescription() ), failure.getTestHeader(),
+ SimpleReportEntry.withException( getClassName( failure.getDescription() ), testHeader,
createStackTraceWriter( failure ) );
if ( failure.getException() instanceof AssertionError )
@@ -146,9 +150,23 @@ public class JUnit4RunListener
return new SimpleReportEntry( getClassName( description ), description.getDisplayName() );
}
+ private boolean isInsaneJunitNullString(String value){
+ return "null".equals( value );
+ }
public String getClassName( Description description )
{
- return extractClassName( description );
+ String name = extractClassName( description );
+ if (name == null || isInsaneJunitNullString( name )){
+ // This can happen upon early failures (class instantiation error etc)
+ Description subDescription = description.getChildren().get( 0 );
+ if (subDescription != null){
+ name = extractClassName( subDescription );
+ }
+ if (name == null){
+ name = "Test Instantiation Error";
+ }
+ }
+ return name;
}
public static String extractClassName( Description description )