01: /* TestExec.java */
02:
03: package org.quilt.frontend.ant;
04:
05: import org.apache.tools.ant.BuildException;
06: import org.apache.tools.ant.Project;
07: import org.apache.tools.ant.Task;
08: import org.apache.tools.ant.taskdefs.ExecuteWatchdog; // need
09:
10: import org.quilt.framework.*;
11: import org.quilt.runner.*;
12:
13: /**
14: * Manage the running of a single test suite.
15: */
16: public class TestExec {
17: private Project project = null;
18: private Task task = null;
19: private TaskControl tc = null;
20: private QuiltTest qt = null;
21:
22: /** No-arg constructor */
23: public TestExec() {
24: }
25:
26: /**
27: * Run an individual test, in a separate JVM if appropriate.
28: *
29: * @see CallTest
30: * @see ForkTest
31: * @param arg Descriptor for the test to be run.
32: * @param tc Task control descriptor.
33: */
34: protected void execute(QuiltTest arg, TaskControl tc) {
35: QuiltTest test = (QuiltTest) arg.clone();
36: this .tc = tc;
37: task = tc.getTask();
38: project = task.getProject();
39:
40: // THIS SHOULD BE DONE BEFORE THE INDIVIDUAL TESTS ARE CLONED;
41: // MOVE INTO QuiltTask <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
42: if (test.getTodir() == null) {
43: test.setTodir(project.resolveFile("."));
44: }
45: if (test.getOutfile() == null) {
46: test.setOutfile("TEST-" + test.getName());
47: }
48: // END SETTING DEFAULTS
49:
50: // execute the test and get the return code
51: int exitValue = Runner.ERRORS;
52: boolean timedOut = false;
53: if (!test.getFork()) {
54: CallTest ct = new CallTest();
55: exitValue = ct.execTest(test, tc);
56: } else {
57: ForkTest ft = new ForkTest();
58: ExecuteWatchdog watchdog = tc.createWatchdog();
59: exitValue = ft.execTest(test, tc, watchdog);
60: if (watchdog != null) {
61: timedOut = watchdog.killedProcess();
62: }
63: }
64: boolean errorOccurredHere = exitValue == Runner.ERRORS;
65: // errors are also failures
66: boolean failureOccurredHere = exitValue != Runner.SUCCESS;
67: // ... so this includes errors
68: if (failureOccurredHere) {
69: if ((errorOccurredHere && test.getHaltOnError())
70: || (failureOccurredHere && test.getHaltOnFailure())) {
71: throw new BuildException("Test " + test.getName()
72: + " failed" + (timedOut ? " (timeout)" : ""),
73: task.getLocation());
74: } else {
75: task.log("TEST " + test.getName() + " FAILED"
76: + (timedOut ? " (timeout)" : ""),
77: Project.MSG_ERR);
78: if (errorOccurredHere
79: && test.getErrorProperty() != null) {
80: project.setNewProperty(test.getErrorProperty(),
81: "true");
82: }
83: if (failureOccurredHere
84: && test.getFailureProperty() != null) {
85: project.setNewProperty(test.getFailureProperty(),
86: "true");
87: }
88: }
89: }
90: }
91: }
|