Skip to content

Commit

Permalink
tests that fail with unexpected exceptions, and have random parameter…
Browse files Browse the repository at this point in the history
…s, are now properly reported on
  • Loading branch information
jurgenvinju committed Jan 15, 2024
1 parent 6723e30 commit d962e8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
14 changes: 1 addition & 13 deletions src/org/rascalmpl/interpreter/DefaultTestResultListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,7 @@ else if (t != null) {
err.println();
}
err.println("error: " + test + " @ " + ReplTextWriter.valueToString(loc));
err.println("\t" + t.getMessage());

if (t instanceof Throw) {
try {
((Throw) t).getTrace().prettyPrintedString(err, new StandardTextWriter(true));
}
catch (IOException e) {
// should not happen
}
}
else {
t.printStackTrace(err);
}
err.println(message);
}
else {
failures++;
Expand Down
6 changes: 5 additions & 1 deletion src/org/rascalmpl/interpreter/TestEvaluator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.rascalmpl.interpreter.env.ModuleEnvironment;
import org.rascalmpl.interpreter.result.AbstractFunction;
import org.rascalmpl.test.infrastructure.QuickCheck;
import org.rascalmpl.test.infrastructure.QuickCheck.TestResult;
import org.rascalmpl.test.infrastructure.QuickCheck.UnExpectedExceptionThrownResult;

import io.usethesource.vallang.IBool;
import io.usethesource.vallang.IString;
Expand Down Expand Up @@ -117,7 +119,8 @@ private void runTests(ModuleEnvironment env, List<AbstractFunction> tests) {
}
}
catch (Throwable e) {
return new TestResult(false, e);
// TODO: add bound type parameters
return new UnExpectedExceptionThrownResult(test.getEnv().getName() + "::" + test.getName(), actuals, Map.of(), args, e);
}
}, env.getRoot().getStore(), tries, maxDepth, maxWidth);

Expand All @@ -137,6 +140,7 @@ private void runTests(ModuleEnvironment env, List<AbstractFunction> tests) {
catch(Throwable e){
testResultListener.report(false, test.getName(), test.getAst().getLocation(), e.getMessage(), e);
}

eval.getOutPrinter().flush();
eval.getErrorPrinter().flush();
}
Expand Down
15 changes: 11 additions & 4 deletions src/org/rascalmpl/test/infrastructure/QuickCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/
package org.rascalmpl.test.infrastructure;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -25,6 +26,7 @@
import io.usethesource.vallang.IString;
import io.usethesource.vallang.IValue;
import io.usethesource.vallang.IValueFactory;
import io.usethesource.vallang.io.StandardTextWriter;
import io.usethesource.vallang.type.Type;
import io.usethesource.vallang.type.TypeStore;

Expand Down Expand Up @@ -196,7 +198,7 @@ public void writeMessage(PrintWriter out) {
}
}

public class UnExpectedExceptionThrownResult extends TestFailedResult {
public static class UnExpectedExceptionThrownResult extends TestFailedResult {

public UnExpectedExceptionThrownResult(String functionName, Type[] actualTypes,
Map<Type, Type> tpbindings, IValue[] values, Throwable thrownException) {
Expand All @@ -210,16 +212,21 @@ public void writeMessage(PrintWriter out) {
out.println("Exception:");
if (thrownException instanceof Throw) {
out.println(((Throw)thrownException).getMessage());
try {
((Throw) thrownException).getTrace().prettyPrintedString(out, new StandardTextWriter(true));
}
catch (IOException e) {
// should not happen
}
}
else {
out.println(thrownException.toString());
// out.println(thrownException.toString());
thrownException.printStackTrace(out);
}
}

}

public class ExceptionNotThrownResult extends TestFailedResult {
public static class ExceptionNotThrownResult extends TestFailedResult {
public ExceptionNotThrownResult(String functionName, Type[] actualTypes,
Map<Type, Type> tpbindings, IValue[] values, String expected) {
super(functionName, "test did not throw '" + expected + "' exception", actualTypes, tpbindings, values);
Expand Down

0 comments on commit d962e8e

Please sign in to comment.