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 2011/11/28 16:32:55 UTC

svn commit: r1207303 - in /maven/surefire/trunk: surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ surefire-integration-tests/src/test/resources/default-configuration-noTests/ surefire-providers/surefire-junit47/src/main/java/org/...

Author: krosenvold
Date: Mon Nov 28 15:32:53 2011
New Revision: 1207303

URL: http://svn.apache.org/viewvc?rev=1207303&view=rev
Log:
o Fixed problem when there were no tests to run

Fixed with IT.

Modified:
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestFailIfNoTestsIT.java
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SurefireVerifierTestClass.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestFailIfNoTestsIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestFailIfNoTestsIT.java?rev=1207303&r1=1207302&r2=1207303&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestFailIfNoTestsIT.java (original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CheckTestFailIfNoTestsIT.java Mon Nov 28 15:32:53 2011
@@ -32,32 +32,26 @@ import java.util.List;
  * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
  */
 public class CheckTestFailIfNoTestsIT
-    extends AbstractSurefireIntegrationTestClass
+    extends SurefireVerifierTestClass
 {
+
+    public CheckTestFailIfNoTestsIT() {
+        super("/default-configuration-noTests");
+    }
+
     public void testFailIfNoTests()
         throws Exception
     {
-        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration-noTests" );
-
-        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
-        List<String> goals = this.getInitialGoals();
-        goals.add( "test" );
-        goals.add( "-DfailIfNoTests" );
+        failIfNoTests(true);
 
         try
         {
-            executeGoals( verifier, goals );
-            verifier.resetStreams();
-            verifier.verifyErrorFreeLog();
+            executeTest();
+            verifyErrorFreeLog();
             fail( "Build didn't fail, but it should" );
         }
-        catch ( VerificationException e )
-        {
-            // as expected
-        }
-        finally
+        catch ( VerificationException ignore )
         {
-            verifier.resetStreams();
         }
 
     }
@@ -65,15 +59,22 @@ public class CheckTestFailIfNoTestsIT
     public void testDontFailIfNoTests()
         throws Exception
     {
-        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration-noTests" );
+        failIfNoTests(false);
+        executeTest();
+        verifyErrorFreeLog();
 
-        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
-        this.executeGoal( verifier, "test" );
-        verifier.verifyErrorFreeLog();
-        verifier.resetStreams();
-
-        File reportsDir = new File( testDir, "target/surefire-reports" );
+        File reportsDir = getSurefireReportsFile("");
         assertFalse( "Unexpected reports directory", reportsDir.exists() );
     }
 
+    public void test48CategoriesFailWhenNoTests()
+        throws Exception
+    {
+        failIfNoTests(false);
+        activateProfile("junit47");
+        addD("junit.version", "4.8.1");
+        executeTest();
+        verifyErrorFreeLog();
+    }
+
 }

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SurefireVerifierTestClass.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SurefireVerifierTestClass.java?rev=1207303&r1=1207302&r2=1207303&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SurefireVerifierTestClass.java (original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/SurefireVerifierTestClass.java Mon Nov 28 15:32:53 2011
@@ -287,6 +287,11 @@ public abstract class SurefireVerifierTe
         addGoal( "-DforkMode=" + forkMode );
     }
 
+    protected void failIfNoTests( boolean fail)
+    {
+        addGoal( "-DfailIfNoTests=" + fail );
+    }
+
     protected void activateProfile( String profile )
     {
         addGoal( "-P" + profile );
@@ -411,7 +416,13 @@ public abstract class SurefireVerifierTe
 
     protected void parallel( String parallel )
     {
-        addGoal( "-Dparallel=" + parallel );
+        addD( "parallel", parallel );
     }
 
+    protected void addD( String variable, String value )
+    {
+        addGoal( "-D" + variable + "=" + value);
+    }
+
+
 }

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml?rev=1207303&r1=1207302&r2=1207303&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml (original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml Mon Nov 28 15:32:53 2011
@@ -21,29 +21,52 @@
 <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>
+    <modelVersion>4.0.0</modelVersion>
 
-  <groupId>org.apache.maven.plugins.surefire</groupId>
-  <artifactId>default-configuration-noTests</artifactId>
-  <version>1.0-SNAPSHOT</version>
-  <name>Test for no test directory</name>
+    <groupId>org.apache.maven.plugins.surefire</groupId>
+    <artifactId>default-configuration-noTests</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <name>Test for no test directory</name>
 
-  <dependencies>
-    <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.1</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
+    <properties>
+        <junit.version>3.8.1</junit.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>${junit.version}</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 
-  <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <version>${surefire.version}</version>
-      </plugin>
-    </plugins>
-  </build>
+    <build>
+        <plugins>
+            <plugin>
+                <artifactId>maven-surefire-plugin</artifactId>
+                <version>${surefire.version}</version>
+            </plugin>
+        </plugins>
+    </build>
+    <profiles>
+        <profile>
+            <id>junit47</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <version>${surefire.version}</version>
+                        <dependencies>
+                            <dependency>
+                                <groupId>org.apache.maven.surefire</groupId>
+                                <artifactId>surefire-junit47</artifactId>
+                                <version>${surefire.version}</version>
+                            </dependency>
+                        </dependencies>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
 
 </project>

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java?rev=1207303&r1=1207302&r2=1207303&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java Mon Nov 28 15:32:53 2011
@@ -113,12 +113,18 @@ public class JUnitCoreProvider
         final ConsoleLogger consoleLogger = providerParameters.getConsoleLogger();
         consoleLogger.info( message );
 
-        final Filter filter = jUnit48Reflector.isJUnit48Available() ? createJUnit48Filter() : null;
+        Filter filter = jUnit48Reflector.isJUnit48Available() ? createJUnit48Filter() : null;
 
         if ( testsToRun == null )
         {
             testsToRun = forkTestSet == null ? getSuitesAsList( filter ) : TestsToRun.fromClass( (Class) forkTestSet );
         }
+
+        if (testsToRun.size() == 0)
+        {
+            filter = null;
+        }
+
         final Map<String, TestSet> testSetMap = new ConcurrentHashMap<String, TestSet>();
 
         RunListener listener = ConcurrentReporterManager.createInstance( testSetMap, reporterFactory,