001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs.optional.junit;
020:
021: import java.io.IOException;
022: import java.io.OutputStream;
023: import org.apache.tools.ant.AntClassLoader;
024: import org.apache.tools.ant.types.Permissions;
025:
026: /**
027: * Handles the portions of {@link JUnitTask} which need to directly access
028: * actual JUnit classes, so that junit.jar need not be on Ant's startup classpath.
029: * Neither JUnitTask.java nor JUnitTaskMirror.java nor their transitive static
030: * deps may import any junit.** classes!
031: * Specifically, need to not refer to
032: * - JUnitResultFormatter or its subclasses
033: * - JUnitVersionHelper
034: * - JUnitTestRunner
035: * Cf. JUnitTask.SplitLoader#isSplit(String)
036: * Public only to permit access from classes in this package; do not use directly.
037: *
038: * @since 1.7
039: * @see "bug #38799"
040: */
041: public interface JUnitTaskMirror {
042:
043: /**
044: * Add the formatter to be called when the jvm exits before
045: * the test suite finishs.
046: * @param test the test.
047: * @param formatter the fomatter to use.
048: * @param out the output stream to use.
049: * @param message the message to write out.
050: * @param testCase the name of the test.
051: */
052: void addVmExit(JUnitTest test,
053: JUnitResultFormatterMirror formatter, OutputStream out,
054: String message, String testCase);
055:
056: /**
057: * Create a new test runner for a test.
058: * @param test the test to run.
059: * @param haltOnError if true halt the tests if an error occurs.
060: * @param filterTrace if true filter the stack traces.
061: * @param haltOnFailure if true halt the test if a failure occurs.
062: * @param showOutput if true show output.
063: * @param logTestListenerEvents if true log test listener events.
064: * @param classLoader the classloader to use to create the runner.
065: * @return the test runner.
066: */
067: JUnitTestRunnerMirror newJUnitTestRunner(JUnitTest test,
068: boolean haltOnError, boolean filterTrace,
069: boolean haltOnFailure, boolean showOutput,
070: boolean logTestListenerEvents, AntClassLoader classLoader);
071:
072: /**
073: * Create a summary result formatter.
074: * @return the created formatter.
075: */
076: SummaryJUnitResultFormatterMirror newSummaryJUnitResultFormatter();
077:
078: /** The interface that JUnitResultFormatter extends. */
079: public interface JUnitResultFormatterMirror {
080: /**
081: * Set the output stream.
082: * @param outputStream the stream to use.
083: */
084: void setOutput(OutputStream outputStream);
085: }
086:
087: /** The interface that SummaryJUnitResultFormatter extends. */
088: public interface SummaryJUnitResultFormatterMirror extends
089: JUnitResultFormatterMirror {
090:
091: /**
092: * Set where standard out and standard error should be included.
093: * @param value if true include the outputs in the summary.
094: */
095: void setWithOutAndErr(boolean value);
096: }
097:
098: /** Interface that test runners implement. */
099: public interface JUnitTestRunnerMirror {
100:
101: /**
102: * Used in formatter arguments as a placeholder for the basename
103: * of the output file (which gets replaced by a test specific
104: * output file name later).
105: *
106: * @since Ant 1.6.3
107: */
108: String IGNORED_FILE_NAME = "IGNORETHIS";
109:
110: /**
111: * No problems with this test.
112: */
113: int SUCCESS = 0;
114:
115: /**
116: * Some tests failed.
117: */
118: int FAILURES = 1;
119:
120: /**
121: * An error occurred.
122: */
123: int ERRORS = 2;
124:
125: /**
126: * Permissions for the test run.
127: * @param perm the permissions to use.
128: */
129: void setPermissions(Permissions perm);
130:
131: /** Run the test. */
132: void run();
133:
134: /**
135: * Add a formatter to the test.
136: * @param formatter the formatter to use.
137: */
138: void addFormatter(JUnitResultFormatterMirror formatter);
139:
140: /**
141: * Returns what System.exit() would return in the standalone version.
142: *
143: * @return 2 if errors occurred, 1 if tests failed else 0.
144: */
145: int getRetCode();
146:
147: /**
148: * Handle output sent to System.err.
149: *
150: * @param output coming from System.err
151: */
152: void handleErrorFlush(String output);
153:
154: /**
155: * Handle output sent to System.err.
156: *
157: * @param output output for System.err
158: */
159: void handleErrorOutput(String output);
160:
161: /**
162: * Handle output sent to System.out.
163: *
164: * @param output output for System.out.
165: */
166: void handleOutput(String output);
167:
168: /**
169: * Handle an input request.
170: *
171: * @param buffer the buffer into which data is to be read.
172: * @param offset the offset into the buffer at which data is stored.
173: * @param length the amount of data to read.
174: *
175: * @return the number of bytes read.
176: *
177: * @exception IOException if the data cannot be read.
178: */
179: int handleInput(byte[] buffer, int offset, int length)
180: throws IOException;
181:
182: /**
183: * Handle output sent to System.out.
184: *
185: * @param output output for System.out.
186: */
187: void handleFlush(String output);
188:
189: }
190: }
|