View Javadoc
1 /* Runner.java */ 2 3 package org.quilt.runner; 4 5 import java.io.BufferedReader; 6 import java.io.PrintWriter; 7 import java.io.StringReader; 8 import java.io.StringWriter; 9 10 import junit.framework.*; 11 import org.apache.tools.ant.util.StringUtils; 12 13 import org.quilt.framework.QuiltTest; 14 import org.quilt.reports.Formatter; 15 16 /*** 17 * Abstract class extended by Quilt test runners. 18 */ 19 public abstract class Runner extends QuiltTest 20 implements RunnerConst, TestListener { 21 22 public abstract void run (); // constructor provides QuiltTest instance 23 public abstract int getRetCode(); 24 25 // STATIC METHODS /////////////////////////////////////////////// 26 public static String getFilteredTrace(Throwable t, boolean filtertrace) { 27 String trace = StringUtils.getStackTrace(t); 28 return filterStack(trace, filtertrace); 29 } 30 31 ///////////////////////////////////////////////////////////////// 32 // FOCUS -- LOOK AT THIS CAREFULLY 33 ///////////////////////////////////////////////////////////////// 34 35 /*** 36 * Filters stack traces from Ant, Quilt, and JUnit classes. These 37 * are usually meaningless to users, who wants to concentrate on 38 * their own code. 39 */ 40 public static String filterStack(String stack, boolean filtertrace) { 41 if ( ! filtertrace ) { 42 return stack; 43 } 44 StringWriter sw = new StringWriter(); 45 PrintWriter pw = new PrintWriter(sw); 46 StringReader sr = new StringReader(stack); 47 BufferedReader br = new BufferedReader(sr); 48 49 String line; 50 try { 51 while ((line = br.readLine()) != null) { 52 if (!filterLine(line)) { 53 pw.println(line); 54 } 55 } 56 } catch (Exception IOException) { 57 return stack; // return the stack unfiltered 58 } 59 return sw.toString(); 60 } 61 62 private static boolean filterLine(String line) { 63 for (int i = 0; i < DEFAULT_TRACE_FILTERS.length; i++) { 64 if (line.indexOf(DEFAULT_TRACE_FILTERS[i]) > 0) { 65 return true; 66 } 67 } 68 return false; 69 } 70 // NON-STATIC METHODS /////////////////////////////////////////// 71 /*** Add a result formatter. */ 72 public abstract void addFormatter(Formatter f); 73 // TestListener INTERFACE /////////////////////////////////////// 74 /*** A failure (or error) has occurred. */ 75 public abstract void addFailure(Test test, Throwable t); 76 /*** A failure (or error) has occurred. */ 77 public abstract void addFailure(Test test, AssertionFailedError t); 78 /*** An unexpected error has occurred. */ 79 public abstract void addError(Test test, Throwable t); 80 /*** Method called at start of individual test suite. */ 81 public abstract void startTest(Test t); 82 /*** Method called at end of individual test run. */ 83 public abstract void endTest(Test test); 84 /*** Process a block of output. */ 85 public abstract void handleOutput(String line); 86 /*** Process an error message */ 87 public abstract void handleErrorOutput(String line); 88 /*** Flush standard output. */ 89 public abstract void handleFlush(String line); 90 /*** Flush the error output stream. */ 91 public abstract void handleErrorFlush(String line); 92 }

This page was automatically generated by Maven