maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dfabul...@apache.org
Subject svn commit: r597825 - in /maven/surefire/trunk: surefire-api/src/main/java/org/apache/maven/surefire/report/ surefire-api/src/test/java/org/apache/maven/surefire/report/ surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/
Date Sat, 24 Nov 2007 08:45:51 GMT
Author: dfabulich
Date: Sat Nov 24 00:45:50 2007
New Revision: 597825

URL: http://svn.apache.org/viewvc?rev=597825&view=rev
Log:
[SUREFIRE-166] Fixing trimStackTrace; it wasn't trimming at all if there's not causedBy. 
Added a unit test.

Added:
    maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/PojoStackTraceWriterTest.java
Removed:
    maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGStackTraceWriter.java
Modified:
    maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java
    maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java

Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java?rev=597825&r1=597824&r2=597825&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java
(original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/PojoStackTraceWriter.java
Sat Nov 24 00:45:50 2007
@@ -61,12 +61,18 @@
 
         String[] lines = StringUtils.split( text, "\n" );
         int lastLine = lines.length - 1;
+        int causedByLine = -1;
         // skip first
         for ( int i = 1; i < lines.length; i++ )
         {
-            if ( lines[i].trim().startsWith( marker ) )
+            String line = lines[i].trim();
+            if ( line.startsWith( marker ) )
             {
                 lastLine = i;
+            } else if ( line.startsWith( "Caused by" ) ) 
+            {
+                causedByLine = i;
+                break;
             }
         }
 
@@ -77,21 +83,14 @@
             trace.append( "\n" );
         }
 
-        for ( int i = lastLine; i < lines.length; i++ )
+        if ( causedByLine != -1 )
         {
-            if ( lines[i].trim().startsWith( "Caused by" ) )
+            for ( int i = causedByLine; i < lines.length; i++ )
             {
-                lastLine = i;
-                break;
+                trace.append( lines[i] );
+                trace.append( "\n" );
             }
         }
-
-        for ( int i = lastLine; i < lines.length; i++ )
-        {
-            trace.append( lines[i] );
-            trace.append( "\n" );
-        }
-
         return trace.toString();
     }
 

Added: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/PojoStackTraceWriterTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/PojoStackTraceWriterTest.java?rev=597825&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/PojoStackTraceWriterTest.java
(added)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/PojoStackTraceWriterTest.java
Sat Nov 24 00:45:50 2007
@@ -0,0 +1,114 @@
+package org.apache.maven.surefire.report;
+
+import java.io.PrintWriter;
+
+import junit.framework.TestCase;
+
+public class PojoStackTraceWriterTest
+    extends TestCase
+{
+
+    public void testWriteTrimmedTraceToString()
+    {
+        String stackTrace = "junit.framework.AssertionFailedError: blah\n" + 
+        "    at junit.framework.Assert.fail(Assert.java:47)\n" + 
+        "    at TestSurefire3.testQuote(TestSurefire3.java:23)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)\n"
+ 
+        "    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n"
+ 
+        "    at java.lang.reflect.Method.invoke(Method.java:585)\n" + 
+        "    at junit.framework.TestCase.runTest(TestCase.java:154)\n" + 
+        "    at junit.framework.TestCase.runBare(TestCase.java:127)\n" + 
+        "    at junit.framework.TestResult$1.protect(TestResult.java:106)\n" + 
+        "    at junit.framework.TestResult.runProtected(TestResult.java:124)\n" + 
+        "    at junit.framework.TestResult.run(TestResult.java:109)\n" + 
+        "    at junit.framework.TestCase.run(TestCase.java:118)\n" + 
+        "    at junit.framework.TestSuite.runTest(TestSuite.java:208)\n" + 
+        "    at junit.framework.TestSuite.run(TestSuite.java:203)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)\n"
+ 
+        "    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n"
+ 
+        "    at java.lang.reflect.Method.invoke(Method.java:585)\n" + 
+        "    at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)\n"
+ 
+        "    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)\n"
+ 
+        "    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)\n"
+ 
+        "    at org.apache.maven.surefire.Surefire.run(Surefire.java:132)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)\n"
+ 
+        "    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n"
+ 
+        "    at java.lang.reflect.Method.invoke(Method.java:585)\n" + 
+        "    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:318)\n"
+ 
+        "    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:956)\n";
+        MockThrowable t = new MockThrowable(stackTrace);
+        PojoStackTraceWriter w = new PojoStackTraceWriter("TestSurefire3", "testQuote", t);
+        String out = w.writeTrimmedTraceToString();
+        String expected = "junit.framework.AssertionFailedError: blah\n" + 
+        		"    at junit.framework.Assert.fail(Assert.java:47)\n" + 
+        		"    at TestSurefire3.testQuote(TestSurefire3.java:23)\n";
+        assertEquals( expected, out );
+    }
+
+    public void testCausedBy() {
+        String stackTrace = "java.lang.RuntimeException: blah\n" + 
+        "    at TestSurefire3.testBlah(TestSurefire3.java:45)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)\n"
+ 
+        "    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n"
+ 
+        "    at java.lang.reflect.Method.invoke(Method.java:585)\n" + 
+        "    at junit.framework.TestCase.runTest(TestCase.java:154)\n" + 
+        "    at junit.framework.TestCase.runBare(TestCase.java:127)\n" + 
+        "    at junit.framework.TestResult$1.protect(TestResult.java:106)\n" + 
+        "    at junit.framework.TestResult.runProtected(TestResult.java:124)\n" + 
+        "    at junit.framework.TestResult.run(TestResult.java:109)\n" + 
+        "    at junit.framework.TestCase.run(TestCase.java:118)\n" + 
+        "    at junit.framework.TestSuite.runTest(TestSuite.java:208)\n" + 
+        "    at junit.framework.TestSuite.run(TestSuite.java:203)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)\n"
+ 
+        "    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n"
+ 
+        "    at java.lang.reflect.Method.invoke(Method.java:585)\n" + 
+        "    at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:213)\n"
+ 
+        "    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)\n"
+ 
+        "    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)\n"
+ 
+        "    at org.apache.maven.surefire.Surefire.run(Surefire.java:132)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n" + 
+        "    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)\n"
+ 
+        "    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)\n"
+ 
+        "    at java.lang.reflect.Method.invoke(Method.java:585)\n" + 
+        "    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:318)\n"
+ 
+        "    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:956)\n"
+ 
+        "Caused by: junit.framework.AssertionFailedError: \"\n" + 
+        "    at junit.framework.Assert.fail(Assert.java:47)\n" + 
+        "    at TestSurefire3.testQuote(TestSurefire3.java:23)\n" + 
+        "    at TestSurefire3.testBlah(TestSurefire3.java:43)\n" + 
+        "    at TestSurefire3.testBlah(TestSurefire3.java:43)\n" + 
+        "    ... 26 more\n";
+        MockThrowable t = new MockThrowable(stackTrace);
+        PojoStackTraceWriter w = new PojoStackTraceWriter("TestSurefire3", "testBlah", t);
+        String out = w.writeTrimmedTraceToString();
+        String expected = "java.lang.RuntimeException: blah\n" + 
+        "    at TestSurefire3.testBlah(TestSurefire3.java:45)\n" + 
+        "Caused by: junit.framework.AssertionFailedError: \"\n" + 
+        "    at junit.framework.Assert.fail(Assert.java:47)\n" + 
+        "    at TestSurefire3.testQuote(TestSurefire3.java:23)\n" + 
+        "    at TestSurefire3.testBlah(TestSurefire3.java:43)\n" + 
+        "    at TestSurefire3.testBlah(TestSurefire3.java:43)\n" + 
+        "    ... 26 more\n";
+        assertEquals( expected, out );
+    }
+    
+    class MockThrowable extends Throwable {
+        private static final long serialVersionUID = 1L;
+        private String stackTrace;
+        
+        public MockThrowable(String stackTrace) {
+            this.stackTrace = stackTrace;
+        }
+        
+        public void printStackTrace( PrintWriter s )
+        {
+            s.write( stackTrace );
+        }
+    }
+
+}

Modified: maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java?rev=597825&r1=597824&r2=597825&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGReporter.java
Sat Nov 24 00:45:50 2007
@@ -22,6 +22,7 @@
 import java.util.ResourceBundle;
 
 import org.apache.maven.surefire.Surefire;
+import org.apache.maven.surefire.report.PojoStackTraceWriter;
 import org.apache.maven.surefire.report.ReportEntry;
 import org.apache.maven.surefire.report.ReporterException;
 import org.apache.maven.surefire.report.ReporterManager;
@@ -95,7 +96,8 @@
         String rawString = bundle.getString( "executeException" );
 
         ReportEntry report = new ReportEntry( source, getUserFriendlyTestName( result ),
rawString,
-                                              new TestNGStackTraceWriter( result ) );
+            new PojoStackTraceWriter( result.getTestClass().getRealClass().getName(),
+            result.getMethod().getMethodName(), result.getThrowable() ) );
 
         reportManager.testFailed( report );
     }
@@ -118,8 +120,10 @@
     {
         String rawString = bundle.getString( "executeException" );
 
-        ReportEntry report = new ReportEntry( source, getUserFriendlyTestName( result ),
rawString,
-                                              new TestNGStackTraceWriter( result ) );
+        ReportEntry report =
+            new ReportEntry( source, getUserFriendlyTestName( result ), rawString,
+                new PojoStackTraceWriter( result.getTestClass().getRealClass().getName(),
+                result.getMethod().getMethodName(), result.getThrowable() ) );
 
         reportManager.testError( report );
     }



Mime
View raw message