o active the new text file reports which capture any stack traces that

occur as well as stdout and std err

o there is a new parameter that is accepted so you can use a simplifed
  regex from the command line

  m2 surefire:test -D=test=FooTest

  is implicitly **/FooTest.java and the directory scanner is used

  so you can this to run a single test if you like or a set of tests:

  m2 surefire:test -Dtest=*Foo*

  is implicitly **/*Foo*.java

  You can also specify a comma separated list if you wish:

  m2 surefire:test -Dtest=*Foo*,*Bar*

  whic is implicitly **/*Foo*.java,**/*Bar*.java

  This just makes running a smaller set of tests easier while trying
  to pin point problems.


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@163120 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2004-09-20 03:14:22 +00:00
parent d99e3305c6
commit c0a6388337
2 changed files with 116 additions and 13 deletions

View File

@ -17,12 +17,12 @@
<dependency>
<groupId>surefire</groupId>
<artifactId>surefire</artifactId>
<version>1.1</version>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>surefire</groupId>
<artifactId>surefire-booter</artifactId>
<version>1.1</version>
<version>1.2-SNAPSHOT</version>
</dependency>
</dependencies>
</project>

View File

@ -7,6 +7,12 @@ import org.apache.maven.plugin.PluginExecutionResponse;
import java.io.File;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.StringTokenizer;
import java.lang.reflect.Array;
/**
* @goal test
@ -67,6 +73,20 @@ import java.util.List;
* validator=""
* expression="#project.classpathElements"
* description=""
* @parameter
* name="reportsDirectory"
* type="String"
* required="false"
* validator=""
* expression="#project.build.directory/surefire-reports"
* description="Base directory where all reports are written to."
* @parameter
* name="test"
* type="String"
* required="false"
* validator=""
* expression="#test"
* description="Specify this parameter if you want to use the test regex notation to select tests to run."
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
@ -92,26 +112,60 @@ public class SurefirePlugin
String testClassesDirectory = (String) request.getParameter( "testClassesDirectory" );
List includes = (List) request.getParameter( "includes" );
List excludes = (List) request.getParameter( "excludes" );
String[] classpathElements = (String[]) request.getParameter( "classpathElements" );
String reportsDirectory = (String) request.getParameter( "reportsDirectory" );
String test = (String) request.getParameter( "test" );
// ----------------------------------------------------------------------
// Setup the surefire booter
// ----------------------------------------------------------------------
SurefireBooter surefireBooter = new SurefireBooter();
surefireBooter.setReportsDirectory( reportsDirectory );
// ----------------------------------------------------------------------
// Check to see if we are running a single test. The raw parameter will
// come through if it has not been set.
// ----------------------------------------------------------------------
if ( !test.equals( "#test" ) )
{
// FooTest -> **/FooTest.java
List includes = new ArrayList();
List excludes = new ArrayList();
String[] testRegexes = split( test, ",", -1 );
for ( int i = 0; i < testRegexes.length; i++ )
{
includes.add( "**/" + testRegexes[i] + ".java" );
}
surefireBooter.addBattery( "org.codehaus.surefire.battery.DirectoryBattery", new Object[]{basedir, includes, excludes} );
}
else
{
List includes = (List) request.getParameter( "includes" );
List excludes = (List) request.getParameter( "excludes" );
surefireBooter.addBattery( "org.codehaus.surefire.battery.DirectoryBattery", new Object[]{basedir, includes, excludes} );
}
// ----------------------------------------------------------------------
//
// ----------------------------------------------------------------------
System.setProperty( "basedir", basedir );
SurefireBooter surefireBooter = new SurefireBooter();
surefireBooter.addBattery( "org.codehaus.surefire.battery.DirectoryBattery", new Object[]{basedir, includes, excludes} );
// TODO: there should be a better way to construct a classpath
surefireBooter.addClassPathUrl( new File( mavenRepoLocal, "junit/jars/junit-3.8.1.jar" ).getPath() );
surefireBooter.addClassPathUrl( new File( mavenRepoLocal, "surefire/jars/surefire-1.1.jar" ).getPath() );
surefireBooter.addClassPathUrl( new File( mavenRepoLocal, "surefire/jars/surefire-1.2-SNAPSHOT.jar" ).getPath() );
surefireBooter.addClassPathUrl( new File( classesDirectory ).getPath() );
@ -122,7 +176,9 @@ public class SurefirePlugin
surefireBooter.addClassPathUrl( classpathElements[i] );
}
surefireBooter.addReport( "org.codehaus.surefire.report.ConsoleReport" );
surefireBooter.addReport( "org.codehaus.surefire.report.ConsoleReporter" );
surefireBooter.addReport( "org.codehaus.surefire.report.FileReporter" );
boolean success = surefireBooter.run();
@ -131,4 +187,51 @@ public class SurefirePlugin
response.setExecutionFailure( true, new SurefireFailureResponse( null ) );
}
}
protected String[] split( String str, String separator, int max )
{
StringTokenizer tok = null;
if ( separator == null )
{
// Null separator means we're using StringTokenizer's default
// delimiter, which comprises all whitespace characters.
tok = new StringTokenizer( str );
}
else
{
tok = new StringTokenizer( str, separator );
}
int listSize = tok.countTokens();
if ( max > 0 && listSize > max )
{
listSize = max;
}
String[] list = new String[listSize];
int i = 0;
int lastTokenBegin = 0;
int lastTokenEnd = 0;
while ( tok.hasMoreTokens() )
{
if ( max > 0 && i == listSize - 1 )
{
// In the situation where we hit the max yet have
// tokens left over in our input, the last list
// element gets all remaining text.
String endToken = tok.nextToken();
lastTokenBegin = str.indexOf( endToken, lastTokenEnd );
list[i] = str.substring( lastTokenBegin );
break;
}
else
{
list[i] = tok.nextToken();
lastTokenBegin = str.indexOf( list[i], lastTokenEnd );
lastTokenEnd = lastTokenBegin + list[i].length();
}
i++;
}
return list;
}
}