maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dfabul...@apache.org
Subject svn commit: r597952 - in /maven/surefire/trunk: maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/ surefire-api/src/main/java/org/apache/maven/surefire/ surefire-booter/src/main/java/org/apache/maven/surefire/booter/ surefire-integra...
Date Sun, 25 Nov 2007 04:18:40 GMT
Author: dfabulich
Date: Sat Nov 24 20:18:39 2007
New Revision: 597952

URL: http://svn.apache.org/viewvc?rev=597952&view=rev
Log:
[SUREFIRE-350] If test parameter provided and 0 tests found, fail the build.  Added in a more
general failIfNoTests feature, which test parameter enables.

Added:
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTests.java
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTestsForkMode.java
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleTest.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/pom.xml
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/java/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/java/classWithNoTests/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/java/classWithNoTests/NoMethodsTestCase.java
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml
Modified:
    maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
    maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java

Modified: maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=597952&r1=597951&r2=597952&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Sat Nov 24 20:18:39 2007
@@ -163,7 +163,8 @@
      * Specify this parameter(can be a comma separated list) if you want to use the test
pattern matching notation, Ant
      * pattern matching, to select tests to run. The Ant pattern will be used to create an
include pattern formatted
      * like <code>**&#47;${test}.java</code> When used, the <code>includes</code>
and <code>excludes</code>
-     * patterns parameters are ignored.
+     * patterns parameters are ignored.  This parameter is ignored if
+     * TestNG suiteXmlFiles are specified.
      * 
      * @parameter expression="${test}"
      */
@@ -262,6 +263,13 @@
     private boolean redirectTestOutputToFile;
 
     /**
+     * Set this to "true" to cause a failure if there are no tests to run.
+     * 
+     * @parameter expression="${failIfNoTests}" default-value="false"
+     */
+    private boolean failIfNoTests;
+    
+    /**
      * Option to specify the forking mode. Can be "never", "once" or "always". "none" and
"pertest" are also accepted
      * for backwards compatibility.
      * 
@@ -437,10 +445,10 @@
 
             getLog().info( "Surefire report directory: " + reportsDirectory );
 
-            boolean success;
+            int result;
             try
             {
-                success = surefireBooter.run();
+                result = surefireBooter.run();
             }
             catch ( SurefireBooterForkException e )
             {
@@ -457,19 +465,28 @@
                 System.setProperties( originalSystemProperties );
             }
 
-            if ( !success )
+            if ( result == 0 ) return;
+            
+            String msg;
+            
+            if ( result == SurefireBooter.NO_TESTS_EXIT_CODE )
             {
+                if ( !failIfNoTests ) return;
+                // TODO: i18n
+                throw new MojoFailureException( "No tests were executed!" );
+            } else {
                 // TODO: i18n
-                String msg = "There are test failures.\n\nPlease refer to " + reportsDirectory
+ " for the individual test results.";
+                msg = "There are test failures.\n\nPlease refer to " + reportsDirectory +
" for the individual test results.";
 
-                if ( testFailureIgnore )
-                {
-                    getLog().error( msg );
-                }
-                else
-                {
-                    throw new MojoFailureException( msg );
-                }
+            }
+            
+            if ( testFailureIgnore )
+            {
+                getLog().error( msg );
+            }
+            else
+            {
+                throw new MojoFailureException( msg );
             }
         }
     }
@@ -485,6 +502,10 @@
 
         if ( !testClassesDirectory.exists() )
         {
+            if ( failIfNoTests )
+            {
+                throw new MojoFailureException( "No tests to run!" );
+            }
             getLog().info( "No tests to run." );
             return false;
         }
@@ -631,15 +652,17 @@
                 includes = new ArrayList();
 
                 excludes = new ArrayList();
-
-                // Allow paths delimited by '.' or '/'
-                test = test.replace('.', '/');
                 
+                failIfNoTests = true;
+
                 String[] testRegexes = StringUtils.split( test, "," );
 
                 for ( int i = 0; i < testRegexes.length; i++ )
                 {
-                    includes.add( "**/" + testRegexes[i] + ".java" );
+                    String testRegex = testRegexes[i];
+                    // Allow paths delimited by '.' or '/'
+                    testRegex = testRegex.replace('.', '/');
+                    includes.add( "**/" + testRegex + ".java" );
                 }
             }
             else
@@ -789,6 +812,8 @@
                 }
             }
         }
+        
+        surefireBooter.setFailIfNoTests( failIfNoTests );
 
         surefireBooter.setRedirectTestOutputToFile( redirectTestOutputToFile );
 

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java?rev=597952&r1=597951&r2=597952&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
Sat Nov 24 20:18:39 2007
@@ -39,19 +39,24 @@
  */
 public class Surefire
 {
+    
+    private static final int SUCCESS = 0;
+    private static final int NO_TESTS = 254;
+    private static final int FAILURE = 255;
+    
     private ResourceBundle bundle = ResourceBundle.getBundle( SUREFIRE_BUNDLE_NAME );
 
     public static final String SUREFIRE_BUNDLE_NAME = "org.apache.maven.surefire.surefire";
 
-    public boolean run( List reportDefinitions, Object[] testSuiteDefinition, String testSetName,
-                        ClassLoader surefireClassLoader, ClassLoader testsClassLoader )
+    public int run( List reportDefinitions, Object[] testSuiteDefinition, String testSetName,
+                        ClassLoader surefireClassLoader, ClassLoader testsClassLoader, Boolean
failIfNoTests )
         throws ReporterException, TestSetFailedException
     {
-        return run( reportDefinitions, testSuiteDefinition, testSetName, surefireClassLoader,
testsClassLoader, null );
+        return run( reportDefinitions, testSuiteDefinition, testSetName, surefireClassLoader,
testsClassLoader, null, failIfNoTests );
     }
 
-    public boolean run( List reportDefinitions, Object[] testSuiteDefinition, String testSetName,
-                        ClassLoader surefireClassLoader, ClassLoader testsClassLoader, Properties
results )
+    public int run( List reportDefinitions, Object[] testSuiteDefinition, String testSetName,
+                        ClassLoader surefireClassLoader, ClassLoader testsClassLoader, Properties
results, Boolean failIfNoTests )
         throws ReporterException, TestSetFailedException
     {
         ReporterManager reporterManager =
@@ -90,12 +95,28 @@
         {
             reporterManager.updateResultsProperties( results );
         }
+        
+        if ( failIfNoTests.booleanValue() )
+        {
+            if ( reporterManager.getNbTests() == 0 )
+            {
+                return NO_TESTS;
+            }
+        }
+        
+        if ( reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures()
== 0 )
+        {
+            return SUCCESS;
+        }
+        else
+        {
+            return FAILURE;
+        }
 
-        return reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures()
== 0;
     }
 
-    public boolean run( List reportDefinitions, List testSuiteDefinitions, ClassLoader surefireClassLoader,
-                        ClassLoader testsClassLoader )
+    public int run( List reportDefinitions, List testSuiteDefinitions, ClassLoader surefireClassLoader,
+                        ClassLoader testsClassLoader, Boolean failIfNoTests )
         throws ReporterException, TestSetFailedException
     {
         ReporterManager reporterManager =
@@ -134,8 +155,22 @@
         }
 
         reporterManager.runCompleted();
+        if ( failIfNoTests.booleanValue() )
+        {
+            if ( reporterManager.getNbTests() == 0 )
+            {
+                return NO_TESTS;
+            }
+        }
 
-        return reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures()
== 0;
+        if ( reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures()
== 0 )
+        {
+            return SUCCESS;
+        }
+        else
+        {
+            return FAILURE;
+        }
     }
 
     private SurefireTestSuite createSuiteFromDefinition( Object[] definition, ClassLoader
surefireClassLoader,

Modified: maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=597952&r1=597951&r2=597952&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
(original)
+++ maven/surefire/trunk/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Sat Nov 24 20:18:39 2007
@@ -78,6 +78,8 @@
     private List surefireBootClassPathUrls = new ArrayList();
 
     private List testSuites = new ArrayList();
+    
+    private boolean failIfNoTests = false;
 
     private boolean redirectTestOutputToFile = false;
 
@@ -87,9 +89,11 @@
 
     private ForkConfiguration forkConfiguration;
 
-    private static final int TESTS_SUCCEEDED_EXIT_CODE = 0;
+    public static final int TESTS_SUCCEEDED_EXIT_CODE = 0;
 
-    private static final int TESTS_FAILED_EXIT_CODE = 255;
+    public static final int TESTS_FAILED_EXIT_CODE = 255;
+    
+    public static final int NO_TESTS_EXIT_CODE = 254;
 
     private static Method assertionStatusMethod;
 
@@ -178,6 +182,16 @@
     }
 
     /**
+     * Setting this to true will cause a failure if there are no tests to run
+     *
+     * @param redirectTestOutputToFile
+     */
+    public void setFailIfNoTests( boolean failIfNoTests )
+    {
+        this.failIfNoTests = failIfNoTests;
+    }
+    
+    /**
      * When forking, setting this to true will make the test output to be saved in a file
instead of showing it on the
      * standard output
      *
@@ -211,10 +225,10 @@
         this.forkConfiguration = forkConfiguration;
     }
 
-    public boolean run()
+    public int run()
         throws SurefireBooterForkException, SurefireExecutionException
     {
-        boolean result;
+        int result;
 
         if ( ForkConfiguration.FORK_NEVER.equals( forkConfiguration.getForkMode() ) )
         {
@@ -235,7 +249,7 @@
         return result;
     }
 
-    private boolean runSuitesInProcess( String testSet, Properties results )
+    private int runSuitesInProcess( String testSet, Properties results )
         throws SurefireExecutionException
     {
         if ( testSuites.size() != 1 )
@@ -262,15 +276,15 @@
 
             Method run =
                 surefireClass.getMethod( "run", new Class[] { List.class, Object[].class,
String.class,
-                    ClassLoader.class, ClassLoader.class, Properties.class } );
+                    ClassLoader.class, ClassLoader.class, Properties.class, Boolean.class
} );
 
             Thread.currentThread().setContextClassLoader( testsClassLoader );
 
-            Boolean result =
-                (Boolean) run.invoke( surefire, new Object[] { reports, testSuites.get( 0
), testSet,
-                    surefireClassLoader, testsClassLoader, results } );
+            Integer result =
+                (Integer) run.invoke( surefire, new Object[] { reports, testSuites.get( 0
), testSet,
+                    surefireClassLoader, testsClassLoader, results, new Boolean( failIfNoTests
) } );
 
-            return result.booleanValue();
+            return result.intValue();
         }
         catch ( InvocationTargetException e )
         {
@@ -286,7 +300,7 @@
         }
     }
 
-    private boolean runSuitesInProcess()
+    private int runSuitesInProcess()
         throws SurefireExecutionException
     {
         // TODO: replace with plexus
@@ -311,15 +325,15 @@
 
             Method run =
                 surefireClass.getMethod( "run", new Class[] { List.class, List.class, ClassLoader.class,
-                    ClassLoader.class } );
+                    ClassLoader.class, Boolean.class } );
 
             Thread.currentThread().setContextClassLoader( testsClassLoader );
 
-            Boolean result =
-                (Boolean) run.invoke( surefire, new Object[] { reports, testSuites, surefireClassLoader,
-                    testsClassLoader } );
+            Integer result =
+                (Integer) run.invoke( surefire, new Object[] { reports, testSuites, surefireClassLoader,
+                    testsClassLoader, new Boolean( failIfNoTests ) } );
 
-            return result.booleanValue();
+            return result.intValue();
         }
         catch ( InvocationTargetException e )
         {
@@ -346,13 +360,13 @@
         System.setProperty( "surefire.test.class.path", sb.toString() );
     }
     
-    private boolean runSuitesForkOnce()
+    private int runSuitesForkOnce()
         throws SurefireBooterForkException
     {
         return forkSuites( testSuites, true, true );
     }
 
-    private boolean runSuitesForkPerTestSet()
+    private int runSuitesForkPerTestSet()
         throws SurefireBooterForkException
     {
         ClassLoader testsClassLoader;
@@ -368,7 +382,7 @@
             throw new SurefireBooterForkException( "Unable to create classloader to find
test suites", e );
         }
 
-        boolean failed = false;
+        int globalResult = 0;
 
         boolean showHeading = true;
         Properties properties = new Properties();
@@ -382,16 +396,16 @@
             {
                 String testSet = (String) j.next();
                 boolean showFooter = !j.hasNext() && !i.hasNext();
-                boolean result = forkSuite( testSuite, testSet, showHeading, showFooter,
properties );
-                if ( !result )
+                int result = forkSuite( testSuite, testSet, showHeading, showFooter, properties
);
+                if ( result > globalResult )
                 {
-                    failed = true;
+                    globalResult = result;
                 }
                 showHeading = false;
             }
         }
 
-        return !failed;
+        return globalResult;
     }
 
     private Map getTestSets( Object[] testSuite, ClassLoader testsClassLoader, ClassLoader
surefireClassLoader )
@@ -442,7 +456,7 @@
         return testSets;
     }
 
-    private boolean forkSuites( List testSuites, boolean showHeading, boolean showFooter
)
+    private int forkSuites( List testSuites, boolean showHeading, boolean showFooter )
         throws SurefireBooterForkException
     {
         Properties properties = new Properties();
@@ -452,7 +466,7 @@
         return fork( properties, showHeading, showFooter );
     }
 
-    private boolean forkSuite( Object[] testSuite, String testSet, boolean showHeading, boolean
showFooter,
+    private int forkSuite( Object[] testSuite, String testSet, boolean showHeading, boolean
showFooter,
                                Properties properties )
         throws SurefireBooterForkException
     {
@@ -483,6 +497,7 @@
         properties.setProperty( "childDelegation", String.valueOf( childDelegation ) );
         properties.setProperty( "enableAssertions", String.valueOf( enableAssertions ) );
         properties.setProperty( "useSystemClassLoader", String.valueOf( useSystemClassLoader()
) );
+        properties.setProperty( "failIfNoTests", String.valueOf( failIfNoTests ) );
     }
 
     private File writePropertiesFile( String name, Properties properties )
@@ -580,7 +595,7 @@
         return forkConfiguration.isUseSystemClassLoader() && ( isForked || forkConfiguration.isForking()
);
     }
 
-    private boolean fork( Properties properties, boolean showHeading, boolean showFooter
)
+    private int fork( Properties properties, boolean showHeading, boolean showFooter )
         throws SurefireBooterForkException
     {
         File surefireProperties;
@@ -669,7 +684,7 @@
             }
         }
 
-        return returnCode == 0;
+        return returnCode;
     }
 
     private ClassLoader createClassLoader( List classPathUrls, ClassLoader parent )
@@ -931,6 +946,10 @@
                     surefireBooter.forkConfiguration.setUseSystemClassLoader( Boolean.valueOf(
                                                                                         
      p.getProperty( "useSystemClassLoader" ) ).booleanValue() );
                 }
+                else if ( "failIfNoTests".equals( name ) )
+                {
+                    surefireBooter.setFailIfNoTests( Boolean.valueOf( p.getProperty( "failIfNoTests"
) ).booleanValue() );
+                }
             }
 
             for (Iterator cpi = classPathUrls.keySet().iterator(); cpi.hasNext();)
@@ -946,7 +965,7 @@
             }
 
             String testSet = p.getProperty( "testSet" );
-            boolean result;
+            int result;
             if ( testSet != null )
             {
                 result = surefireBooter.runSuitesInProcess( testSet, p );
@@ -959,7 +978,7 @@
             surefireBooter.writePropertiesFile( surefirePropertiesFile, "surefire", p );
 
             // noinspection CallToSystemExit
-            System.exit( result ? TESTS_SUCCEEDED_EXIT_CODE : TESTS_FAILED_EXIT_CODE );
+            System.exit( result );
         }
         catch ( Throwable t )
         {

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTests.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTests.java?rev=597952&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTests.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTests.java
Sat Nov 24 20:18:39 2007
@@ -0,0 +1,56 @@
+package org.apache.maven.surefire.its;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * Test failIfNoTests
+ * 
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ * 
+ */
+public class TestFailIfNoTests
+    extends AbstractMavenIntegrationTestCase
+{
+    public void testFailIfNoTests ()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration-noTests"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        List goals = new ArrayList();
+        goals.add( "test" );
+        goals.add( "-DfailIfNoTests" );
+        verifier.executeGoals( goals );
+        verifier.resetStreams();
+        
+        try {
+            verifier.verifyErrorFreeLog();
+            fail ( "Build didn't fail, but it should" );
+        } catch ( VerificationException e ) {
+            // as expected
+        }
+                
+    }
+    
+    public void testDontFailIfNoTests()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration-noTests"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        verifier.executeGoal( "test" );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        File reportsDir = new File( testDir, "target/surefire-reports" );
+        assertFalse ( "Unexpected reports directory", reportsDir.exists() );
+    }
+
+}

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTestsForkMode.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTestsForkMode.java?rev=597952&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTestsForkMode.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestFailIfNoTestsForkMode.java
Sat Nov 24 20:18:39 2007
@@ -0,0 +1,83 @@
+package org.apache.maven.surefire.its;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+import org.apache.maven.reporting.MavenReportException;
+
+/**
+ * Test failIfNoTests with various forkModes.
+ * 
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ * 
+ */
+public class TestFailIfNoTestsForkMode
+    extends AbstractMavenIntegrationTestCase
+{
+    public void testFailIfNoTestsForkModeAlways () throws Exception
+    {
+        doTest("always", true);
+    }
+    
+    public void testFailIfNoTestsForkModeNever() throws Exception 
+    {
+        doTest( "never", true );
+    }
+    
+    public void testFailIfNoTestsForkModeOnce() throws Exception 
+    {
+        doTest( "once", true );
+    }
+    
+    public void testDontFailIfNoTestsForkModeAlways () throws Exception
+    {
+        doTest("always", false);
+    }
+    
+    public void testDontFailIfNoTestsForkModeNever() throws Exception 
+    {
+        doTest( "never", false );
+    }
+    
+    public void testDontFailIfNoTestsForkModeOnce() throws Exception 
+    {
+        doTest( "once", false );
+    }
+    
+    private void doTest(String forkMode, boolean failIfNoTests)
+        throws IOException, VerificationException, MavenReportException
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration-classWithNoTests"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        List goals = new ArrayList();
+        goals.add( "test" );
+        goals.add( "-DforkMode=" + forkMode );
+        goals.add( "-DfailIfNoTests=" + failIfNoTests );
+        verifier.executeGoals( goals );
+        verifier.resetStreams();
+        if (failIfNoTests)
+        {
+            try 
+            {
+                verifier.verifyErrorFreeLog();
+                fail( "Build did not fail, but it should have" );
+            } catch (VerificationException e )
+            {
+                // this is what we expected
+            }
+        }
+        else
+        {
+            verifier.verifyErrorFreeLog();
+            File reportsDir = new File( testDir, "target/surefire-reports" );
+            assertFalse ( "Unexpected reports directory", reportsDir.exists() );
+        }
+    }
+}

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleTest.java?rev=597952&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleTest.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestSingleTest.java
Sat Nov 24 20:18:39 2007
@@ -0,0 +1,75 @@
+package org.apache.maven.surefire.its;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.maven.integrationtests.AbstractMavenIntegrationTestCase;
+import org.apache.maven.it.VerificationException;
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+/**
+ * Test running a single test with -Dtest=BasicTest
+ * 
+ * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
+ * 
+ */
+public class TestSingleTest
+    extends AbstractMavenIntegrationTestCase
+{
+    public void testSingleTest ()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        List goals = new ArrayList();
+        goals.add( "test" );
+        goals.add( "-Dtest=BasicTest" );
+        verifier.executeGoals( goals );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+        
+        HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, testDir );        
+    }
+    
+    public void XXXtestSingleTestDotJava()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        List goals = new ArrayList();
+        goals.add( "test" );
+        goals.add( "-Dtest=BasicTest.java" );
+        verifier.executeGoals( goals );
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, testDir );
+    }
+
+    public void testSingleTestNonExistent()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/default-configuration"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        List goals = new ArrayList();
+        goals.add( "test" );
+        goals.add( "-Dtest=DoesNotExist" );
+        verifier.executeGoals( goals );
+        verifier.resetStreams();
+        try {
+            verifier.verifyErrorFreeLog();
+            fail( "Build should have failed" );
+        } catch (VerificationException e) {
+            // as expected
+        }
+        
+        File reportsDir = new File( testDir, "target/surefire-reports" );
+        assertFalse ( "Unexpected reports directory", reportsDir.exists() );
+    }
+    
+}

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Nov 24 20:18:39 2007
@@ -0,0 +1,5 @@
+.classpath
+.project
+target
+.settings
+log.txt

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/pom.xml?rev=597952&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/pom.xml
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/pom.xml
Sat Nov 24 20:18:39 2007
@@ -0,0 +1,41 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>default-configuration</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for default configuration</name>
+  <description>Test for default surefire configuration</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/java/classWithNoTests/NoMethodsTestCase.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/java/classWithNoTests/NoMethodsTestCase.java?rev=597952&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/java/classWithNoTests/NoMethodsTestCase.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-classWithNoTests/src/test/java/classWithNoTests/NoMethodsTestCase.java
Sat Nov 24 20:18:39 2007
@@ -0,0 +1 @@
+public class NoMethodsTestCase {}
\ No newline at end of file

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sat Nov 24 20:18:39 2007
@@ -0,0 +1,5 @@
+.classpath
+.project
+target
+.settings
+log.txt

Added: 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=597952&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/default-configuration-noTests/pom.xml
Sat Nov 24 20:18:39 2007
@@ -0,0 +1,41 @@
+<?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/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>default-configuration</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for default configuration</name>
+  <description>Test for default surefire configuration</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
+</project>



Mime
View raw message