View Javadoc
1 /* TestExec.java */ 2 3 package org.quilt.frontend.ant; 4 5 import org.apache.tools.ant.BuildException; 6 import org.apache.tools.ant.Project; 7 import org.apache.tools.ant.Task; 8 import org.apache.tools.ant.taskdefs.ExecuteWatchdog; // need 9 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 * Run an individual test, in a separate JVM if appropriate. 27 * 28 * @see CallTest 29 * @see ForkTest 30 * @param arg Descriptor for the test to be run. 31 * @param tc Task control descriptor. 32 */ 33 protected void execute(QuiltTest arg, TaskControl tc) { 34 QuiltTest test = (QuiltTest) arg.clone(); 35 this.tc = tc; 36 task = tc.getTask(); 37 project = task.getProject(); 38 39 // THIS SHOULD BE DONE BEFORE THE INDIVIDUAL TESTS ARE CLONED; 40 // MOVE INTO QuiltTask <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 41 if (test.getTodir() == null) { 42 test.setTodir(project.resolveFile(".")); 43 } 44 if (test.getOutfile() == null) { 45 test.setOutfile("TEST-" + test.getName()); 46 } 47 // END SETTING DEFAULTS 48 49 // execute the test and get the return code 50 int exitValue = Runner.ERRORS; 51 boolean timedOut = false; 52 if (!test.getFork()) { 53 CallTest ct = new CallTest(); 54 exitValue = ct.execTest(test, tc); 55 } else { 56 ForkTest ft = new ForkTest(); 57 ExecuteWatchdog watchdog = tc.createWatchdog(); 58 exitValue = ft.execTest(test, tc, watchdog); 59 if (watchdog != null) { 60 timedOut = watchdog.killedProcess(); 61 } 62 } 63 boolean errorOccurredHere 64 = exitValue == Runner.ERRORS; 65 // errors are also failures 66 boolean failureOccurredHere 67 = exitValue != Runner.SUCCESS; 68 // ... so this includes errors 69 if (failureOccurredHere) { 70 if ( (errorOccurredHere && test.getHaltOnError ()) 71 || (failureOccurredHere && test.getHaltOnFailure()) ) { 72 throw new BuildException( 73 "Test " + test.getName() + " failed" 74 + (timedOut ? " (timeout)" : ""), task.getLocation()); 75 } else { 76 task.log("TEST " + test.getName() + " FAILED" 77 + (timedOut ? " (timeout)" : ""), 78 Project.MSG_ERR); 79 if (errorOccurredHere 80 && test.getErrorProperty() != null) { 81 project.setNewProperty( 82 test.getErrorProperty(), "true"); 83 } 84 if (failureOccurredHere 85 && test.getFailureProperty() != null) { 86 project.setNewProperty( 87 test.getFailureProperty(), "true"); 88 } 89 } 90 } 91 } 92 }

This page was automatically generated by Maven