1 2 3 package org.quilt.reports; 4 5 import java.io.IOException ; 6 import java.io.OutputStream ; 7 import java.io.PrintWriter ; 8 import java.io.StringWriter ; 9 import java.text.NumberFormat ; 10 11 import junit.framework.AssertionFailedError; 12 import junit.framework.Test; 13 14 import org.apache.tools.ant.BuildException; 15 16 import org.quilt.framework.*; 17 import org.quilt.runner.Runner; 18 19 public class BriefFormatter extends BaseFormatter { 20 21 22 public BriefFormatter() { 23 results = new StringWriter (); 24 resultWriter = new PrintWriter (results); 25 } 26 27 29 32 public void endTestSuite(QuiltTest suite) throws BuildException { 33 StringBuffer sb = new StringBuffer ("Testsuite: " + suite.getName() 34 + "\nTests run: " + suite.runCount() 35 + ", Failures: " + suite.failureCount() 36 + ", Errors: " + suite.errorCount() 37 + ", Time elapsed: " 38 + numberFormat.format( suite.getRunTime() / 1000.0) 39 + " sec\n\n" ); 40 41 if (systemOutput != null && systemOutput.length() > 0) { 42 sb.append( 43 "------------- Standard Output ----------------\n" 44 + systemOutput 45 + "------------- ---------------- ---------------\n"); 46 } 47 48 if (systemError != null && systemError.length() > 0) { 49 sb.append( 50 "------------- Standard Error -----------------\n" 51 + systemError 52 + "------------- ---------------- ---------------\n"); 53 } 54 55 if (output != null) { 56 try { 57 output.write(sb.toString()); 58 resultWriter.close(); 59 output.write(results.toString()); 60 output.flush(); 61 } finally { 62 if (out != System.out && 63 out != System.err) { 64 try { 65 out.close(); 66 } catch (IOException e) { 67 } 68 } 69 } 70 } 71 } 72 73 77 public void addFailure(Test test, Throwable t) { 78 formatError("\tFAILED", test, t); 79 } 80 81 85 public void addFailure(Test test, AssertionFailedError t) { 86 addFailure(test, (Throwable ) t); 87 } 88 89 92 public void addError(Test test, Throwable error) { 93 formatError("\tCaused an ERROR", test, error); 94 } 95 96 98 99 private synchronized void formatError(String msg, Test test, 100 Throwable error) { 101 if (test == null) { 102 resultWriter.println("Null test: " + msg); 103 104 } else { 105 endTest(test); 106 resultWriter.println("Testcase: " + test + ": " + msg); 107 } 108 resultWriter.println(error.getMessage()); 109 String strace = runner.getFilteredTrace(error, filtertrace); 110 resultWriter.println(strace); 111 resultWriter.println(); 112 } 113 } 114 | Popular Tags |