maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r383136 - in /maven/surefire/branches/surefire-testng: surefire-api/src/main/java/org/apache/maven/surefire/ surefire-api/src/main/java/org/apache/maven/surefire/report/ surefire-booter/src/main/java/org/apache/maven/surefire/booter/
Date Sat, 04 Mar 2006 15:23:41 GMT
Author: brett
Date: Sat Mar  4 07:23:41 2006
New Revision: 383136

URL: http://svn.apache.org/viewcvs?rev=383136&view=rev
Log:
[MSUREFIRE-62] only write results after all tests completed

Modified:
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ForkingConsoleReporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
    maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
    maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkingWriterStreamConsumer.java
    maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/Surefire.java
Sat Mar  4 07:23:41 2006
@@ -27,6 +27,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 import java.util.ResourceBundle;
 
 /**
@@ -43,9 +44,21 @@
                         ClassLoader surefireClassLoader, ClassLoader testsClassLoader )
         throws ReporterException, TestSetFailedException
     {
+        return run( reportDefinitions, testSuiteDefinition, testSetName, surefireClassLoader,
testsClassLoader, null );
+    }
+
+    public boolean run( List reportDefinitions, Object[] testSuiteDefinition, String testSetName,
+                        ClassLoader surefireClassLoader, ClassLoader testsClassLoader, Properties
results )
+        throws ReporterException, TestSetFailedException
+    {
         ReporterManager reporterManager =
             new ReporterManager( instantiateReports( reportDefinitions, surefireClassLoader
) );
 
+        if ( results != null )
+        {
+            reporterManager.initResultsFromProperties( results );
+        }
+
         int totalTests = 0;
 
         SurefireTestSuite suite =
@@ -69,6 +82,8 @@
         }
 
         reporterManager.runCompleted();
+
+        reporterManager.updateResultsProperties( results );
 
         return reporterManager.getNumErrors() == 0 && reporterManager.getNumFailures()
== 0;
     }

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractConsoleReporter.java
Sat Mar  4 07:23:41 2006
@@ -58,6 +58,11 @@
         writeHeading( "-------------------------------------------------------" );
     }
 
+    public void runCompleted()
+    {
+        super.runCompleted();    //To change body of overridden methods use File | Settings
| File Templates.
+    }
+
     public void writeHeading( String message )
     {
         writer.println( message );

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/AbstractReporter.java
Sat Mar  4 07:23:41 2006
@@ -51,6 +51,11 @@
     // Report interface
     // ----------------------------------------------------------------------
 
+    public void writeFooter( String footer )
+    {
+        writeMessage( footer );
+    }
+
     public void runStarting( int testCount )
     {
     }

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ForkingConsoleReporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ForkingConsoleReporter.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ForkingConsoleReporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ForkingConsoleReporter.java
Sat Mar  4 07:23:41 2006
@@ -23,11 +23,21 @@
 
     public static final String FORKING_PREFIX_HEADING = "@HL";
 
+    public static final String FORKING_PREFIX_FOOTER = "@FL";
+
     public void writeHeading( String message )
     {
         writer.print( FORKING_PREFIX_HEADING );
 
         super.writeHeading( message );
+    }
+
+    public void writeFooter( String footer )
+    {
+        writer.print( FORKING_PREFIX_FOOTER );
+
+        // Deliberately set to writeMessage
+        super.writeMessage( footer );
     }
 
     public void writeMessage( String message )

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/Reporter.java
Sat Mar  4 07:23:41 2006
@@ -20,6 +20,8 @@
 {
     void writeMessage( String message );
 
+    void writeFooter( String footer );
+
     // The entire run
     void runStarting( int testCount );
 

Modified: maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManager.java
Sat Mar  4 07:23:41 2006
@@ -22,6 +22,7 @@
 import java.io.PrintStream;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Properties;
 
 public class ReporterManager
 {
@@ -43,6 +44,14 @@
 
     private int skipped;
 
+    private static final String RESULTS_ERRORS = "errors";
+
+    private static final String RESULTS_COMPLETED_COUNT = "completedCount";
+
+    private static final String RESULTS_FAILURES = "failures";
+
+    private static final String RESULTS_SKIPPED = "skipped";
+
     public ReporterManager( List reports )
     {
         this.reports = reports;
@@ -144,11 +153,21 @@
             reporter.runCompleted();
         }
 
-        writeMessage( "" );
-        writeMessage( "Results :" );
-        writeMessage( "Tests run: " + completedCount + ", Failures: " + failures + ", Errors:
" + errors +
+        writeFooter( "" );
+        writeFooter( "Results :" );
+        writeFooter( "Tests run: " + completedCount + ", Failures: " + failures + ", Errors:
" + errors +
             ", Skipped: " + skipped );
-        writeMessage( "" );
+        writeFooter( "" );
+    }
+
+    private void writeFooter( String footer )
+    {
+        for ( Iterator i = reports.iterator(); i.hasNext(); )
+        {
+            Reporter report = (Reporter) i.next();
+
+            report.writeFooter( footer );
+        }
     }
 
     private ByteArrayOutputStream stdOut;
@@ -332,5 +351,21 @@
 
             reporter.testSkipped( report );
         }
+    }
+
+    public void initResultsFromProperties( Properties results )
+    {
+        errors = Integer.valueOf( results.getProperty( RESULTS_ERRORS, "0" ) ).intValue();
+        skipped = Integer.valueOf( results.getProperty( RESULTS_SKIPPED, "0" ) ).intValue();
+        failures = Integer.valueOf( results.getProperty( RESULTS_FAILURES, "0" ) ).intValue();
+        completedCount = Integer.valueOf( results.getProperty( RESULTS_COMPLETED_COUNT, "0"
) ).intValue();
+    }
+
+    public void updateResultsProperties( Properties results )
+    {
+        results.setProperty( RESULTS_ERRORS, String.valueOf( errors ) );
+        results.setProperty( RESULTS_COMPLETED_COUNT, String.valueOf( completedCount ) );
+        results.setProperty( RESULTS_FAILURES, String.valueOf( failures ) );
+        results.setProperty( RESULTS_SKIPPED, String.valueOf( skipped ) );
     }
 }

Modified: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkingWriterStreamConsumer.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkingWriterStreamConsumer.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkingWriterStreamConsumer.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkingWriterStreamConsumer.java
Sat Mar  4 07:23:41 2006
@@ -37,15 +37,23 @@
 
     private boolean showHeading;
 
-    public ForkingWriterStreamConsumer( Writer writer, boolean showHeading )
+    private int footerPrefixLength;
+
+    private boolean showFooter;
+
+    public ForkingWriterStreamConsumer( Writer writer, boolean showHeading, boolean showFooter
)
     {
         this.showHeading = showHeading;
 
+        this.showFooter = showFooter;
+
         printWriter = new PrintWriter( writer );
 
         standardPrefixLength = ForkingConsoleReporter.FORKING_PREFIX_STANDARD.length();
 
         headingPrefixLength = ForkingConsoleReporter.FORKING_PREFIX_HEADING.length();
+
+        footerPrefixLength = ForkingConsoleReporter.FORKING_PREFIX_FOOTER.length();
     }
 
     public void consumeLine( String line )
@@ -60,6 +68,13 @@
         else if ( line.startsWith( ForkingConsoleReporter.FORKING_PREFIX_STANDARD ) )
         {
             printWriter.println( line.substring( standardPrefixLength ) );
+        }
+        else if ( line.startsWith( ForkingConsoleReporter.FORKING_PREFIX_FOOTER ) )
+        {
+            if ( showFooter )
+            {
+                printWriter.println( line.substring( footerPrefixLength ) );
+            }
         }
         else
         {

Modified: maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
URL: http://svn.apache.org/viewcvs/maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java?rev=383136&r1=383135&r2=383136&view=diff
==============================================================================
--- maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
(original)
+++ maven/surefire/branches/surefire-testng/surefire-booter/src/main/java/org/apache/maven/surefire/booter/SurefireBooter.java
Sat Mar  4 07:23:41 2006
@@ -26,6 +26,7 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
@@ -127,7 +128,7 @@
         return result;
     }
 
-    private boolean runSuitesInProcess( String testSet, boolean childDelegation )
+    private boolean runSuitesInProcess( String testSet, boolean childDelegation, Properties
results )
         throws SurefireExecutionException
     {
         if ( testSuites.size() != 1 )
@@ -151,14 +152,14 @@
             Object surefire = surefireClass.newInstance();
 
             Method run = surefireClass.getMethod( "run", new Class[]{List.class, Object[].class,
String.class,
-                ClassLoader.class, ClassLoader.class} );
+                ClassLoader.class, ClassLoader.class, Properties.class} );
 
             ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader();
 
             Thread.currentThread().setContextClassLoader( testsClassLoader );
 
             Boolean result = (Boolean) run.invoke( surefire, new Object[]{reports, testSuites.get(
0 ), testSet,
-                surefireClassLoader, testsClassLoader} );
+                surefireClassLoader, testsClassLoader, results} );
 
             Thread.currentThread().setContextClassLoader( oldContextClassLoader );
 
@@ -218,7 +219,7 @@
     private boolean runSuitesForkOnce()
         throws SurefireBooterForkException
     {
-        return forkSuites( testSuites, true );
+        return forkSuites( testSuites, true, true );
     }
 
     private boolean runSuitesForkPerTestSet()
@@ -240,6 +241,7 @@
         boolean failed = false;
 
         boolean showHeading = true;
+        Properties properties = new Properties();
         for ( Iterator i = testSuites.iterator(); i.hasNext(); )
         {
             Object[] testSuite = (Object[]) i.next();
@@ -249,7 +251,8 @@
             for ( Iterator j = testSets.keySet().iterator(); j.hasNext(); )
             {
                 String testSet = (String) j.next();
-                boolean result = forkSuite( testSuite, testSet, showHeading );
+                boolean showFooter = !j.hasNext() && !i.hasNext();
+                boolean result = forkSuite( testSuite, testSet, showHeading, showFooter,
properties );
                 if ( !result )
                 {
                     failed = true;
@@ -309,28 +312,29 @@
         return testSets;
     }
 
-    private boolean forkSuites( List testSuites, boolean showHeading )
+    private boolean forkSuites( List testSuites, boolean showHeading, boolean showFooter
)
         throws SurefireBooterForkException
     {
-        Properties properties = createForkProperties( testSuites );
+        Properties properties = new Properties();
 
-        return fork( properties, showHeading );
+        setForkProperties( testSuites, properties );
+
+        return fork( properties, showHeading, showFooter );
     }
 
-    private boolean forkSuite( Object[] testSuite, String testSet, boolean showHeading )
+    private boolean forkSuite( Object[] testSuite, String testSet, boolean showHeading, boolean
showFooter,
+                               Properties properties )
         throws SurefireBooterForkException
     {
-        Properties properties = createForkProperties( Collections.singletonList( testSuite
) );
+        setForkProperties( Collections.singletonList( testSuite ), properties );
 
         properties.setProperty( "testSet", testSet );
 
-        return fork( properties, showHeading );
+        return fork( properties, showHeading, showFooter );
     }
 
-    private Properties createForkProperties( List testSuites )
+    private void setForkProperties( List testSuites, Properties properties )
     {
-        Properties properties = new Properties();
-
         addPropertiesForTypeHolder( reports, properties, "report." );
         addPropertiesForTypeHolder( testSuites, properties, "testSuite." );
 
@@ -347,7 +351,6 @@
         }
 
         properties.setProperty( "childDelegation", String.valueOf( forkConfiguration.isChildDelegation()
) );
-        return properties;
     }
 
     private File writePropertiesFile( String name, Properties properties )
@@ -356,6 +359,14 @@
         File file = File.createTempFile( name, "tmp" );
         file.deleteOnExit();
 
+        writePropertiesFile( file, name, properties );
+
+        return file;
+    }
+
+    private void writePropertiesFile( File file, String name, Properties properties )
+        throws IOException
+    {
         FileOutputStream out = new FileOutputStream( file );
 
         try
@@ -366,8 +377,6 @@
         {
             IOUtil.close( out );
         }
-
-        return file;
     }
 
     private void addPropertiesForTypeHolder( List typeHolderList, Properties properties,
String propertyPrefix )
@@ -401,7 +410,7 @@
         }
     }
 
-    private boolean fork( Properties properties, boolean showHeading )
+    private boolean fork( Properties properties, boolean showHeading, boolean showFooter
)
         throws SurefireBooterForkException
     {
         File surefireProperties;
@@ -430,9 +439,9 @@
 
         Writer consoleWriter = new OutputStreamWriter( System.out );
 
-        StreamConsumer out = new ForkingWriterStreamConsumer( consoleWriter, showHeading
);
+        StreamConsumer out = new ForkingWriterStreamConsumer( consoleWriter, showHeading,
showFooter );
 
-        StreamConsumer err = new ForkingWriterStreamConsumer( consoleWriter, showHeading
);
+        StreamConsumer err = new ForkingWriterStreamConsumer( consoleWriter, showHeading,
showFooter );
 
         if ( forkConfiguration.isDebug() )
         {
@@ -450,6 +459,29 @@
             throw new SurefireBooterForkException( "Error while executing forked tests.",
e );
         }
 
+        if ( surefireProperties != null && surefireProperties.exists() )
+        {
+            FileInputStream inStream = null;
+            try
+            {
+                inStream = new FileInputStream( surefireProperties );
+
+                properties.load( inStream );
+            }
+            catch ( FileNotFoundException e )
+            {
+                throw new SurefireBooterForkException( "Unable to reload properties file
from forked process", e );
+            }
+            catch ( IOException e )
+            {
+                throw new SurefireBooterForkException( "Unable to reload properties file
from forked process", e );
+            }
+            finally
+            {
+                IOUtil.close( inStream );
+            }
+        }
+
         return returnCode == 0;
     }
 
@@ -614,7 +646,8 @@
             setSystemProperties( new File( args[1] ) );
         }
 
-        Properties p = loadProperties( new File( args[0] ) );
+        File surefirePropertiesFile = new File( args[0] );
+        Properties p = loadProperties( surefirePropertiesFile );
 
         SurefireBooter surefireBooter = new SurefireBooter();
 
@@ -653,12 +686,14 @@
         boolean result;
         if ( testSet != null )
         {
-            result = surefireBooter.runSuitesInProcess( testSet, childDelegation );
+            result = surefireBooter.runSuitesInProcess( testSet, childDelegation, p );
         }
         else
         {
             result = surefireBooter.runSuitesInProcess( childDelegation );
         }
+
+        surefireBooter.writePropertiesFile( surefirePropertiesFile, "surefire", p );
 
         //noinspection CallToSystemExit
         System.exit( result ? TESTS_SUCCEEDED_EXIT_CODE : TESTS_FAILED_EXIT_CODE );



Mime
View raw message