diff --git a/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java b/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java index a5e478c7736aaf083af417671a7aab4d2d38db9f..630461802ead7b62f87804eebb45e9a109bb8888 100644 --- a/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java +++ b/src/main/java/uk/ac/rhul/cs/javatester/CodeTester.java @@ -175,6 +175,20 @@ public class CodeTester { */ public String getLLastCall() { return llastCall; } + /** + * Default constructor + */ + public CodeTester() { } + + /** + * Constructor with timeout convenience + * + * @param timeout timeout in seconds + */ + public CodeTester(int timeout) { + setTimeout(timeout); + } + /** * Convenience method for throwing a FailedTestException with a * message constructed with expand. @@ -1075,7 +1089,8 @@ public class CodeTester { return Utils.runWithTimeout(getTimeout(), () -> { try { - return m.invoke(tis, params); + Object o = m.invoke(tis, params); + return o; } catch (Exception e) { // this will end up at ExecutionException below, // sometimes... diff --git a/src/main/java/uk/ac/rhul/cs/javatester/Utils.java b/src/main/java/uk/ac/rhul/cs/javatester/Utils.java index 7e1c22af0f2433536ef695d031eebc0dab1882ae..1389a4c230812d803fcb42cd92f33837c384bf53 100644 --- a/src/main/java/uk/ac/rhul/cs/javatester/Utils.java +++ b/src/main/java/uk/ac/rhul/cs/javatester/Utils.java @@ -19,6 +19,11 @@ public class Utils { /** * Run the function with a timeout and return the result. * + * TODO: this cannot stop infinite loops in student code as + * Java refuses to kill threads. Really needs to use a + * separate process. Or call System.exit at the end of your program + * (not nice). + * * @param seconds the timeout in seconds, or 0 or less if no timeout * @param f the function to call * @return the return value of the function