From c26af311be0d2177f4c4365b3642a4cf5f4a38ff Mon Sep 17 00:00:00 2001 From: "Jurgen J. Vinju" Date: Tue, 2 Apr 2024 19:40:06 +0200 Subject: [PATCH] made the DefaultTestResultListener interact with the progress bar --- .../DefaultTestResultListener.java | 37 ++++++++----------- src/org/rascalmpl/interpreter/Evaluator.java | 2 +- .../interpreter/ITestResultListener.java | 2 +- .../repl/TerminalProgressBarMonitor.java | 2 + src/org/rascalmpl/shell/RascalShell.java | 1 - 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/org/rascalmpl/interpreter/DefaultTestResultListener.java b/src/org/rascalmpl/interpreter/DefaultTestResultListener.java index fab6d6bed70..e1753d20748 100644 --- a/src/org/rascalmpl/interpreter/DefaultTestResultListener.java +++ b/src/org/rascalmpl/interpreter/DefaultTestResultListener.java @@ -15,12 +15,12 @@ import java.io.PrintWriter; +import org.rascalmpl.debug.IRascalMonitor; import org.rascalmpl.repl.ReplTextWriter; import io.usethesource.vallang.ISourceLocation; public class DefaultTestResultListener implements ITestResultListener{ - private PrintWriter err; private int successes; private int failures; private int errors; @@ -28,15 +28,17 @@ public class DefaultTestResultListener implements ITestResultListener{ private int ignored; private String context; private final boolean verbose; - private static char[] roller = new char[] {'|', '/', '-', '\\', '|', '/', '-', '\\', '|'}; + private final IRascalMonitor monitor; + private PrintWriter err; - public DefaultTestResultListener(PrintWriter errorStream){ - this(errorStream, true); + public DefaultTestResultListener(PrintWriter err, IRascalMonitor monitor) { + this(err, monitor, true); } - public DefaultTestResultListener(PrintWriter errorStream, boolean verbose){ + public DefaultTestResultListener(PrintWriter err, IRascalMonitor monitor, boolean verbose){ super(); - this.err = errorStream; + this.err = err; + this.monitor = monitor; this.verbose = verbose; reset(); } @@ -54,6 +56,9 @@ public void setErrorStream(PrintWriter errorStream) { @Override public void ignored(String test, ISourceLocation loc) { + if (verbose) { + monitor.jobStep(context, "Ignored " + test); + } this.ignored++; } @@ -62,22 +67,14 @@ public void start(String context, int count) { this.context = context; reset(); if (count != 0 && verbose) { - err.println("Running tests for " + context); + monitor.jobStart(context, count); } this.count = count; - progress(); } - - private void progress() { - if (count > 0 && verbose) { - err.print(String.format("%s testing %d/%d ", - roller[getNumberOfTests() % roller.length], getNumberOfTests(), count)); - } - } @Override public void done() { - progress(); + monitor.jobEnd(context, errors + failures == 0); if (count > 0) { if (!verbose) { // make sure results are reported on a newline @@ -102,12 +99,10 @@ public void done() { @Override public void report(boolean successful, String test, ISourceLocation loc, String message, Throwable t) { - progress(); - if (successful) { successes++; if (verbose) { - err.print("success \r"); + monitor.jobStep(context, "success: " + test); } } else if (t != null) { @@ -115,6 +110,7 @@ else if (t != null) { if (!verbose) { err.println(); } + monitor.jobStep(context, "error: " + test); err.println("error: " + test + " @ " + ReplTextWriter.valueToString(loc)); err.println(message); } @@ -123,12 +119,11 @@ else if (t != null) { if (!verbose) { err.println(); } + monitor.jobStep(context, "failure: " + test); err.println("failure: " + test + " @ " + ReplTextWriter.valueToString(loc)); err.println(message); } - - err.flush(); } diff --git a/src/org/rascalmpl/interpreter/Evaluator.java b/src/org/rascalmpl/interpreter/Evaluator.java index 7486e26ac57..dc8b1f97fb5 100755 --- a/src/org/rascalmpl/interpreter/Evaluator.java +++ b/src/org/rascalmpl/interpreter/Evaluator.java @@ -1442,7 +1442,7 @@ public boolean runTests(IRascalMonitor monitor) { IRascalMonitor old = setMonitor(monitor); try { final boolean[] allOk = new boolean[] { true }; - final ITestResultListener l = testReporter != null ? testReporter : new DefaultTestResultListener(getOutPrinter()); + final ITestResultListener l = testReporter != null ? testReporter : new DefaultTestResultListener(getOutPrinter(), monitor); new TestEvaluator(this, new ITestResultListener() { diff --git a/src/org/rascalmpl/interpreter/ITestResultListener.java b/src/org/rascalmpl/interpreter/ITestResultListener.java index 2e853d2c03a..ece7dff8ec1 100644 --- a/src/org/rascalmpl/interpreter/ITestResultListener.java +++ b/src/org/rascalmpl/interpreter/ITestResultListener.java @@ -14,7 +14,7 @@ import io.usethesource.vallang.ISourceLocation; -public interface ITestResultListener{ +public interface ITestResultListener { void start(String context, int count); void report(boolean successful, String test, ISourceLocation loc, String message, Throwable exception); void ignored(String test, ISourceLocation loc); diff --git a/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java b/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java index 182ac0f53ea..4d1cce9bd5f 100644 --- a/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java +++ b/src/org/rascalmpl/repl/TerminalProgressBarMonitor.java @@ -309,7 +309,9 @@ public void jobTodo(String name, int work) { @Override public void warning(String message, ISourceLocation src) { + eraseBars(); writer.println(("[WARNING] " + src + ": " + message)); + printBars(); } /** diff --git a/src/org/rascalmpl/shell/RascalShell.java b/src/org/rascalmpl/shell/RascalShell.java index 6cc637b6a0e..e5618e2cc72 100644 --- a/src/org/rascalmpl/shell/RascalShell.java +++ b/src/org/rascalmpl/shell/RascalShell.java @@ -16,7 +16,6 @@ import java.io.IOException; import java.io.OutputStream; -import java.io.PrintStream; import java.io.PrintWriter; import org.rascalmpl.debug.IRascalMonitor;