From 1bed0ffe7259698db0e326326a995395d76cf74e Mon Sep 17 00:00:00 2001 From: evenisse Date: Wed, 14 Jan 2004 15:58:07 +0000 Subject: [PATCH] Move to maven components module git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@114584 13f79535-47bb-0310-9956-ffa450edef68 --- surefire/src/surefire-runner/.cvsignore | 5 - surefire/src/surefire-runner/project.xml | 30 - .../maven/test/MavenJUnitTestSuite.java | 368 --------- .../maven/test/MavenTestSuiteLoader.java | 33 - .../org/apache/maven/test/ResultPrinter.java | 143 ---- .../org/apache/maven/test/TestRunner.java | 149 ---- .../src/surefire-runner/surefire-runner.ipr | 160 ---- .../src/surefire-runner/surefire-runner.iws | 704 ------------------ 8 files changed, 1592 deletions(-) delete mode 100644 surefire/src/surefire-runner/.cvsignore delete mode 100644 surefire/src/surefire-runner/project.xml delete mode 100644 surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenJUnitTestSuite.java delete mode 100644 surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenTestSuiteLoader.java delete mode 100644 surefire/src/surefire-runner/src/main/org/apache/maven/test/ResultPrinter.java delete mode 100644 surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java delete mode 100644 surefire/src/surefire-runner/surefire-runner.ipr delete mode 100644 surefire/src/surefire-runner/surefire-runner.iws diff --git a/surefire/src/surefire-runner/.cvsignore b/surefire/src/surefire-runner/.cvsignore deleted file mode 100644 index 7244964b..00000000 --- a/surefire/src/surefire-runner/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -target -velocity.log -maven.log -.classpath -.project diff --git a/surefire/src/surefire-runner/project.xml b/surefire/src/surefire-runner/project.xml deleted file mode 100644 index 1269664d..00000000 --- a/surefire/src/surefire-runner/project.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - 3 - maven - surefire-runner - surefire-runner - Surefire Test Runner - 1.0 - - Run JUnit tests - http://maven.apache.org/reference/plugins/surefire-runner - /www/maven.apache.org/reference/plugins/surefire-runner - - scm:cvs:pserver:anoncvs@cvs.apache.org:/home/cvspublic:maven/src/plugins-build/surefire-runner - http://cvs.apache.org/viewcvs/maven/src/plugins-build/surefire-runner - - - - - - junit - junit - 3.8.1 - - - - src/main - - diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenJUnitTestSuite.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenJUnitTestSuite.java deleted file mode 100644 index c9026b5a..00000000 --- a/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenJUnitTestSuite.java +++ /dev/null @@ -1,368 +0,0 @@ -package org.apache.maven.test; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestResult; - -import java.io.PrintWriter; -import java.io.StringWriter; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Enumeration; -import java.util.Vector; - -/** - * A TestSuite is a Composite of Tests. - * It runs a collection of test cases. Here is an example using - * the dynamic test definition. - *
- * TestSuite suite= new TestSuite();
- * suite.addTest(new MathTest("testAdd"));
- * suite.addTest(new MathTest("testDivideByZero"));
- * 
- * Alternatively, a TestSuite can extract the tests to be run automatically. - * To do so you pass the class of your TestCase class to the - * TestSuite constructor. - *
- * TestSuite suite= new TestSuite(MathTest.class);
- * 
- * This constructor creates a suite with all the methods - * starting with "test" that take no arguments. - * - * @see junit.framework.Test - */ -public class MavenJUnitTestSuite - implements Test -{ - private Vector fTests = new Vector( 10 ); - - private String fName; - - private Class junitTest = null; - - private Class testResultClass = null; - - /** - * Constructs an empty TestSuite. - */ - public MavenJUnitTestSuite() - { - } - - /** - * Constructs a TestSuite from the given class with the given name. - */ - public MavenJUnitTestSuite( Class theClass ) - { - this( theClass, ClassLoader.getSystemClassLoader() ); - } - - /** - * Constructs a TestSuite from the given class. Adds all the methods - * starting with "test" as test cases to the suite. - * Parts of this method was written at 2337 meters in the H�ffih�tte, - * Kanton Uri - */ - public MavenJUnitTestSuite( final Class theClass, ClassLoader classLoader ) - { - try - { - junitTest = classLoader.loadClass( "junit.framework.Test" ); - - testResultClass = classLoader.loadClass( "junit.framework.TestResult" ); - } - catch ( ClassNotFoundException e ) - { - } - - fName = theClass.getName(); - try - { - getTestConstructor( theClass ); // Avoid generating multiple error messages - } - catch ( NoSuchMethodException e ) - { - addTest( warning( "Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()" ) ); - return; - } - - if ( !Modifier.isPublic( theClass.getModifiers() ) ) - { - addTest( warning( "Class " + theClass.getName() + " is not public" ) ); - return; - } - - Class superClass = theClass; - Vector names = new Vector(); - - while ( junitTest.isAssignableFrom( superClass ) ) - { - Method[] methods = superClass.getDeclaredMethods(); - for ( int i = 0; i < methods.length; i++ ) - { - addTestMethod( methods[i], names, theClass ); - } - superClass = superClass.getSuperclass(); - } - - if ( fTests.size() == 0 ) - { - addTest( warning( "No tests found in " + theClass.getName() ) ); - } - } - - /** - * Constructs an empty TestSuite. - */ - public MavenJUnitTestSuite( String name ) - { - setName( name ); - } - - /** - * Adds a test to the suite. - */ - public void addTest( Object test ) - { - fTests.addElement( test ); - } - - /** - * Adds the tests from the given class to the suite - */ - public void addTestSuite( Class testClass ) - { - addTest( new MavenJUnitTestSuite( testClass ) ); - } - - private void addTestMethod( Method m, Vector names, Class theClass ) - { - String name = m.getName(); - - if ( names.contains( name ) ) - { - return; - } - - if ( !isPublicTestMethod( m ) ) - { - if ( isTestMethod( m ) ) - { - addTest( warning( "Test method isn't public: " + m.getName() ) ); - } - return; - } - - names.addElement( name ); - - addTest( createTest( theClass, name ) ); - } - - /** - * ...as the moon sets over the early morning Merlin, Oregon - * mountains, our intrepid adventurers type... - */ - static public Object createTest( Class theClass, String name ) - { - Constructor constructor; - - try - { - constructor = getTestConstructor( theClass ); - } - catch ( NoSuchMethodException e ) - { - return warning( "Class " + theClass.getName() + " has no public constructor TestCase(String name) or TestCase()" ); - } - Object test; - try - { - if ( constructor.getParameterTypes().length == 0 ) - { - test = constructor.newInstance( new Object[0] ); - - if ( test instanceof TestCase ) - { - ( (TestCase) test ).setName( name ); - } - } - else - { - test = constructor.newInstance( new Object[]{name} ); - } - } - catch ( InstantiationException e ) - { - return ( warning( "Cannot instantiate test case: " + name + " (" + exceptionToString( e ) + ")" ) ); - } - catch ( InvocationTargetException e ) - { - return ( warning( "Exception in constructor: " + name + " (" + exceptionToString( e.getTargetException() ) + ")" ) ); - } - catch ( IllegalAccessException e ) - { - return ( warning( "Cannot access test case: " + name + " (" + exceptionToString( e ) + ")" ) ); - } - - return test; - } - - /** - * Converts the stack trace into a string - */ - private static String exceptionToString( Throwable t ) - { - StringWriter stringWriter = new StringWriter(); - PrintWriter writer = new PrintWriter( stringWriter ); - t.printStackTrace( writer ); - return stringWriter.toString(); - - } - - /** - * Counts the number of test cases that will be run by this test. - */ - public int countTestCases() - { - int count = 0; - for ( Enumeration e = tests(); e.hasMoreElements(); ) - { - Test test = (Test) e.nextElement(); - count = count + test.countTestCases(); - } - return count; - } - - /** - * Gets a constructor which takes a single String as - * its argument or a no arg constructor. - */ - public static Constructor getTestConstructor( Class theClass ) - throws NoSuchMethodException - { - Class[] args = {String.class}; - - try - { - return theClass.getConstructor( args ); - } - catch ( NoSuchMethodException e ) - { - // fall through - } - return theClass.getConstructor( new Class[0] ); - } - - private boolean isPublicTestMethod( Method m ) - { - return isTestMethod( m ) && Modifier.isPublic( m.getModifiers() ); - } - - private boolean isTestMethod( Method m ) - { - String name = m.getName(); - Class[] parameters = m.getParameterTypes(); - Class returnType = m.getReturnType(); - return parameters.length == 0 && name.startsWith( "test" ) && returnType.equals( Void.TYPE ); - } - - /** - * Runs the tests and collects their result in a TestResult. - */ - public void run( TestResult result ) - { - for ( Enumeration e = tests(); e.hasMoreElements(); ) - { - if ( result.shouldStop() ) - { - break; - } - - Object test = e.nextElement(); - - runTest( test, result ); - } - } - - public void runTest( Object test, TestResult result ) - { - try - { - Method m = test.getClass().getMethod( "run", new Class[] { testResultClass } ); - - m.invoke( test, new Object[] { result } ); - } - catch ( Exception e ) - { - e.printStackTrace(); - } - } - - /** - * Returns the test at the given index - */ - public Test testAt( int index ) - { - return (Test) fTests.elementAt( index ); - } - - /** - * Returns the number of tests in this suite - */ - public int testCount() - { - return fTests.size(); - } - - /** - * Returns the tests as an enumeration - */ - public Enumeration tests() - { - return fTests.elements(); - } - - /** - */ - public String toString() - { - if ( getName() != null ) - return getName(); - return super.toString(); - } - - /** - * Sets the name of the suite. - * @param name The name to set - */ - public void setName( String name ) - { - fName = name; - } - - /** - * Returns the name of the suite. Not all - * test suites have a name and this method - * can return null. - */ - public String getName() - { - return fName; - } - - /** - * Returns a test which will fail and log a warning message. - */ - private static Test warning( final String message ) - { - return new TestCase( "warning" ) - { - protected void runTest() - { - fail( message ); - } - }; - } -} diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenTestSuiteLoader.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenTestSuiteLoader.java deleted file mode 100644 index b07d3983..00000000 --- a/surefire/src/surefire-runner/src/main/org/apache/maven/test/MavenTestSuiteLoader.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.apache.maven.test; - -import junit.runner.TestSuiteLoader; - -/** - * - * - * @author Jason van Zyl - * - * @version $Id: MavenTestSuiteLoader.java,v 1.1 2004/01/09 16:23:01 jvanzyl Exp $ - */ -public class MavenTestSuiteLoader - implements TestSuiteLoader -{ - private ClassLoader classLoader; - - public MavenTestSuiteLoader( ClassLoader classLoader ) - { - this.classLoader = classLoader; - } - - public Class load( String className ) - throws ClassNotFoundException - { - return classLoader.loadClass( className ); - } - - public Class reload( Class clazz ) - throws ClassNotFoundException - { - return clazz; - } -} diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/ResultPrinter.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/ResultPrinter.java deleted file mode 100644 index ad85f262..00000000 --- a/surefire/src/surefire-runner/src/main/org/apache/maven/test/ResultPrinter.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.apache.maven.test; - -import java.io.PrintStream; -import java.text.NumberFormat; -import java.util.Enumeration; - -import junit.framework.AssertionFailedError; -import junit.framework.Test; -import junit.framework.TestFailure; -import junit.framework.TestListener; -import junit.framework.TestResult; -import junit.runner.BaseTestRunner; - -public class ResultPrinter implements TestListener -{ - PrintStream fWriter; - int fColumn = 0; - - public ResultPrinter( PrintStream writer ) - { - fWriter = writer; - } - - synchronized void print( TestResult result, long runTime, String testName ) - { - //printErrors( result ); - //printFailures( result ); - printFooter( result, runTime, testName ); - } - - protected void printErrors( TestResult result ) - { - printDefects( result.errors(), result.errorCount(), "error" ); - } - - protected void printFailures( TestResult result ) - { - printDefects( result.failures(), result.failureCount(), "failure" ); - } - - protected void printDefects( Enumeration booBoos, int count, String type ) - { - if ( count == 0 ) - { - return; - } - if ( count == 1 ) - { - getWriter().println( "There was " + count + " " + type + ":" ); - } - else - { - getWriter().println( "There were " + count + " " + type + "s:" ); - } - - for ( int i = 1; booBoos.hasMoreElements(); i++ ) - { - printDefect( (TestFailure) booBoos.nextElement(), i ); - } - } - - public void printDefect( TestFailure booBoo, int count ) - { // only public for testing purposes - printDefectHeader( booBoo, count ); - printDefectTrace( booBoo ); - } - - protected void printDefectHeader( TestFailure booBoo, int count ) - { - // I feel like making this a println, then adding a line giving the throwable a chance to print something - // before we get to the stack trace. - getWriter().print( count + ") " + booBoo.failedTest() ); - } - - protected void printDefectTrace( TestFailure booBoo ) - { - getWriter().print( BaseTestRunner.getFilteredTrace( booBoo.trace() ) ); - } - - protected void printFooter( TestResult result, long runtime, String testName ) - { - getWriter().println( " [funit] Running " + testName ); - - getWriter().println( " [funit] Tests run: " + result.runCount() + - ", Failures: " + result.failureCount() + - ", Errors: " + result.errorCount() + - ", Time elapsed: " + elapsedTimeAsString( runtime ) + " sec" ); - - printErrors( result ); - printFailures( result ); - } - - /** - * Returns the formatted string of the elapsed time. - * Duplicated from BaseTestRunner. Fix it. - */ - protected String elapsedTimeAsString( long runTime ) - { - return NumberFormat.getInstance().format( (double) runTime / 1000 ); - } - - public PrintStream getWriter() - { - return fWriter; - } - - /** - * @see junit.framework.TestListener#addError(Test, Throwable) - */ - public void addError( Test test, Throwable t ) - { - getWriter().print( "E" ); - } - - /** - * @see junit.framework.TestListener#addFailure(Test, AssertionFailedError) - */ - public void addFailure( Test test, AssertionFailedError t ) - { - getWriter().print( "F" ); - } - - /** - * @see junit.framework.TestListener#endTest(Test) - */ - public void endTest( Test test ) - { - } - - /** - * @see junit.framework.TestListener#startTest(Test) - */ - public void startTest( Test test ) - { - getWriter().print( "." ); - if ( fColumn++ >= 40 ) - { - getWriter().println(); - fColumn = 0; - } - } - -} diff --git a/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java b/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java deleted file mode 100644 index 13c0d867..00000000 --- a/surefire/src/surefire-runner/src/main/org/apache/maven/test/TestRunner.java +++ /dev/null @@ -1,149 +0,0 @@ -package org.apache.maven.test; - -import junit.framework.Test; -import junit.framework.TestResult; -import junit.framework.TestSuite; -import junit.runner.BaseTestRunner; -import junit.runner.TestSuiteLoader; - -import java.io.PrintStream; - -public class TestRunner - extends BaseTestRunner -{ - private ResultPrinter resultPrinter; - - public static final int SUCCESS_EXIT = 0; - - public static final int FAILURE_EXIT = 1; - - public static final int EXCEPTION_EXIT = 2; - - private static final String FS = System.getProperty( "file.separator" ); - - public TestRunner() - { - this( System.out ); - } - - public TestRunner( PrintStream writer ) - { - this( new ResultPrinter( writer ) ); - } - - public TestRunner( ResultPrinter printer ) - { - resultPrinter = printer; - } - - private ClassLoader classLoader; - - public void runTestClasses( ClassLoader classLoader, String[] tests ) - throws Exception - { - this.classLoader = classLoader; - - String s; - - for ( int i = 0; i < tests.length; i++ ) - { - s = tests[i]; - - s = s.substring( 0, s.indexOf( "." ) ); - - s = s.replace( FS.charAt( 0 ), ".".charAt( 0 ) ); - - Class clazz = null; - - try - { - clazz = classLoader.loadClass( s ); - } - catch ( ClassNotFoundException e ) - { - System.out.println( "Can't find className = " + s ); - - continue; - } - - TestResult result = run( clazz, s ); - - if ( result.errorCount() > 0 || result.failureCount() > 0 ) - { - failures = "true"; - } - } - } - - private String failures = "false"; - - public String failures() - { - return failures; - } - - public TestResult run( Class testClass, String testName ) - { - return run( new TestSuite( testClass ), testName ); - - //return run( new MavenJUnitTestSuite( testClass, classLoader ), testName ); - } - - public TestResult run( Test test, String testName ) - { - TestRunner runner = new TestRunner(); - - return runner.doRun( test, testName ); - } - - public TestSuiteLoader getLoader() - { - return new MavenTestSuiteLoader( classLoader ); - } - - public void testFailed( int status, Test test, Throwable t ) - { - } - - public void testStarted( String testName ) - { - } - - public void testEnded( String testName ) - { - } - - protected TestResult createTestResult() - { - return new TestResult(); - } - - public TestResult doRun( Test suite, String testName ) - { - TestResult result = createTestResult(); - - long startTime = System.currentTimeMillis(); - - suite.run( result ); - - long endTime = System.currentTimeMillis(); - - long runTime = endTime - startTime; - - resultPrinter.print( result, runTime, testName ); - - return result; - } - - protected void runFailed( String message ) - { - System.err.println( message ); - - System.exit( FAILURE_EXIT ); - } - - public void setPrinter( ResultPrinter printer ) - { - resultPrinter = printer; - } -} diff --git a/surefire/src/surefire-runner/surefire-runner.ipr b/surefire/src/surefire-runner/surefire-runner.ipr deleted file mode 100644 index 804db6b7..00000000 --- a/surefire/src/surefire-runner/surefire-runner.ipr +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/surefire/src/surefire-runner/surefire-runner.iws b/surefire/src/surefire-runner/surefire-runner.iws deleted file mode 100644 index 56f67bcc..00000000 --- a/surefire/src/surefire-runner/surefire-runner.iws +++ /dev/null @@ -1,704 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - localhost - 5050 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file