001: /* Runner.java */
002:
003: package org.quilt.runner;
004:
005: import java.io.BufferedReader;
006: import java.io.PrintWriter;
007: import java.io.StringReader;
008: import java.io.StringWriter;
009:
010: import junit.framework.*;
011: import org.apache.tools.ant.util.StringUtils;
012:
013: import org.quilt.framework.QuiltTest;
014: import org.quilt.reports.Formatter;
015:
016: /**
017: * Abstract class extended by Quilt test runners.
018: */
019: public abstract class Runner extends QuiltTest implements RunnerConst,
020: TestListener {
021:
022: public abstract void run(); // constructor provides QuiltTest instance
023:
024: public abstract int getRetCode();
025:
026: // STATIC METHODS ///////////////////////////////////////////////
027: public static String getFilteredTrace(Throwable t,
028: boolean filtertrace) {
029: String trace = StringUtils.getStackTrace(t);
030: return filterStack(trace, filtertrace);
031: }
032:
033: /////////////////////////////////////////////////////////////////
034: // FOCUS -- LOOK AT THIS CAREFULLY
035: /////////////////////////////////////////////////////////////////
036:
037: /**
038: * Filters stack traces from Ant, Quilt, and JUnit classes. These
039: * are usually meaningless to users, who wants to concentrate on
040: * their own code.
041: */
042: public static String filterStack(String stack, boolean filtertrace) {
043: if (!filtertrace) {
044: return stack;
045: }
046: StringWriter sw = new StringWriter();
047: PrintWriter pw = new PrintWriter(sw);
048: StringReader sr = new StringReader(stack);
049: BufferedReader br = new BufferedReader(sr);
050:
051: String line;
052: try {
053: while ((line = br.readLine()) != null) {
054: if (!filterLine(line)) {
055: pw.println(line);
056: }
057: }
058: } catch (Exception IOException) {
059: return stack; // return the stack unfiltered
060: }
061: return sw.toString();
062: }
063:
064: private static boolean filterLine(String line) {
065: for (int i = 0; i < DEFAULT_TRACE_FILTERS.length; i++) {
066: if (line.indexOf(DEFAULT_TRACE_FILTERS[i]) > 0) {
067: return true;
068: }
069: }
070: return false;
071: }
072:
073: // NON-STATIC METHODS ///////////////////////////////////////////
074: /** Add a result formatter. */
075: public abstract void addFormatter(Formatter f);
076:
077: // TestListener INTERFACE ///////////////////////////////////////
078: /** A failure (or error) has occurred. */
079: public abstract void addFailure(Test test, Throwable t);
080:
081: /** A failure (or error) has occurred. */
082: public abstract void addFailure(Test test, AssertionFailedError t);
083:
084: /** An unexpected error has occurred. */
085: public abstract void addError(Test test, Throwable t);
086:
087: /** Method called at start of individual test suite. */
088: public abstract void startTest(Test t);
089:
090: /** Method called at end of individual test run. */
091: public abstract void endTest(Test test);
092:
093: /** Process a block of output. */
094: public abstract void handleOutput(String line);
095:
096: /** Process an error message */
097: public abstract void handleErrorOutput(String line);
098:
099: /** Flush standard output. */
100: public abstract void handleFlush(String line);
101:
102: /** Flush the error output stream. */
103: public abstract void handleErrorFlush(String line);
104: }
|