Skip to content

Commit

Permalink
done; this disables the progress bar monitor when the terminal is not…
Browse files Browse the repository at this point in the history
… an active console
  • Loading branch information
jurgenvinju committed Apr 3, 2024
1 parent f26a445 commit e50a9ab
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 2 additions & 0 deletions src/org/rascalmpl/repl/TerminalProgressBarMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public TerminalProgressBarMonitor(OutputStream out, Terminal tm) {
PrintWriter theWriter = new PrintWriter(out, true, Charset.forName(encoding));
this.writer = debug ? new PrintWriter(new AlwaysFlushAlwaysShowCursor(theWriter)) : theWriter;
this.lineWidth = tm.getWidth();

Check warning on line 64 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L62-L64

Added lines #L62 - L64 were not covered by tests

assert System.console() != null: "interactive progress bar needs a terminal, and we should not print this into a file anyway.";
}

Check warning on line 67 in src/org/rascalmpl/repl/TerminalProgressBarMonitor.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/repl/TerminalProgressBarMonitor.java#L67

Added line #L67 was not covered by tests

/**
Expand Down
4 changes: 2 additions & 2 deletions src/org/rascalmpl/shell/RascalShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ public static void main(String[] args) throws IOException {
}

IRascalMonitor monitor
= term.isAnsiSupported()
= System.console() != null
? new TerminalProgressBarMonitor(System.out, term)
: new ConsoleRascalMonitor();

Check warning on line 74 in src/org/rascalmpl/shell/RascalShell.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/shell/RascalShell.java#L73-L74

Added lines #L73 - L74 were not covered by tests

IDEServices services = new BasicIDEServices(new PrintWriter(System.err), monitor);

Check warning on line 76 in src/org/rascalmpl/shell/RascalShell.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/shell/RascalShell.java#L76

Added line #L76 was not covered by tests
runner = new REPLRunner(System.in, System.err, term.isAnsiSupported() ? (OutputStream) monitor : System.out, term, services);
runner = new REPLRunner(System.in, System.err, System.console() != null ? (OutputStream) monitor : System.out, term, services);
}
runner.run(args);

Expand Down
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.OutputStream;
import java.io.PrintWriter;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
Expand All @@ -30,6 +31,7 @@
import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.interpreter.Evaluator;
import org.rascalmpl.interpreter.ITestResultListener;
import org.rascalmpl.interpreter.NullRascalMonitor;
Expand All @@ -55,7 +57,10 @@
*
*/
public class RascalJUnitParallelRecursiveTestRunner extends Runner {
private final static TerminalProgressBarMonitor monitor = new TerminalProgressBarMonitor(System.out, TerminalFactory.get());
private final static IRascalMonitor monitor = System.console() != null
? new TerminalProgressBarMonitor(System.out, TerminalFactory.get())

Check warning on line 61 in src/org/rascalmpl/test/infrastructure/RascalJUnitParallelRecursiveTestRunner.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/test/infrastructure/RascalJUnitParallelRecursiveTestRunner.java#L61

Added line #L61 was not covered by tests
: new NullRascalMonitor();

private final int numberOfWorkers;
private final Semaphore importsCompleted = new Semaphore(0);
private final Semaphore waitForRunning = new Semaphore(0);
Expand Down Expand Up @@ -302,7 +307,8 @@ private void initializeEvaluator() {
heap = new GlobalEnvironment();
root = heap.addModule(new ModuleEnvironment("___junit_test___", heap));

evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, monitor, root, heap);
var outStream = System.console() != null ? (TerminalProgressBarMonitor) monitor : System.out;
evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, outStream, root, heap);
evaluator.setMonitor(monitor);
evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
evaluator.getConfiguration().setErrors(true);
Expand Down
13 changes: 10 additions & 3 deletions src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.runner.Runner;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.interpreter.Evaluator;
import org.rascalmpl.interpreter.ITestResultListener;
import org.rascalmpl.interpreter.NullRascalMonitor;
Expand Down Expand Up @@ -66,10 +67,16 @@ public class RascalJUnitTestRunner extends Runner {
root = heap.addModule(new ModuleEnvironment("___junit_test___", heap));

Terminal tm = TerminalFactory.get();
TerminalProgressBarMonitor monitor = new TerminalProgressBarMonitor(System.out, tm);
IRascalMonitor monitor = System.console() != null
? new TerminalProgressBarMonitor(System.out, tm)

Check warning on line 71 in src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java#L71

Added line #L71 was not covered by tests
: new NullRascalMonitor();

evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, monitor, root, heap);
evaluator.setMonitor(monitor);
var outStream = System.console() != null
? (TerminalProgressBarMonitor) monitor

Check warning on line 75 in src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/test/infrastructure/RascalJUnitTestRunner.java#L75

Added line #L75 was not covered by tests
: System.out;

evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, outStream, root, heap);
evaluator.setMonitor(System.console() != null ? monitor : new NullRascalMonitor());
evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
evaluator.getConfiguration().setErrors(true);
}
Expand Down
14 changes: 10 additions & 4 deletions src/org/rascalmpl/test/infrastructure/TestFramework.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
import java.util.Set;

import org.junit.After;
import org.rascalmpl.debug.IRascalMonitor;
import org.rascalmpl.interpreter.ConsoleRascalMonitor;
import org.rascalmpl.interpreter.Evaluator;
import org.rascalmpl.interpreter.NullRascalMonitor;
import org.rascalmpl.interpreter.env.GlobalEnvironment;
import org.rascalmpl.interpreter.env.ModuleEnvironment;
import org.rascalmpl.interpreter.load.StandardLibraryContributor;
Expand All @@ -48,7 +51,10 @@


public class TestFramework {
private final static TerminalProgressBarMonitor monitor = new TerminalProgressBarMonitor(System.out, TerminalFactory.get());
private final static IRascalMonitor monitor = System.console() != null
? new TerminalProgressBarMonitor(System.out, TerminalFactory.get())

Check warning on line 55 in src/org/rascalmpl/test/infrastructure/TestFramework.java

View check run for this annotation

Codecov / codecov/patch

src/org/rascalmpl/test/infrastructure/TestFramework.java#L55

Added line #L55 was not covered by tests
: new NullRascalMonitor();

private final static Evaluator evaluator;
private final static GlobalEnvironment heap;
private final static ModuleEnvironment root;
Expand All @@ -60,9 +66,9 @@ public class TestFramework {
heap = new GlobalEnvironment();
root = heap.addModule(new ModuleEnvironment("___test___", heap));

stderr = new PrintWriter(System.err);
stdout = new PrintWriter(monitor);
evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, monitor, root, heap);
stderr = new PrintWriter(System.err, true);
stdout = System.console() != null ? new PrintWriter((TerminalProgressBarMonitor) monitor) : new PrintWriter(System.out, true);
evaluator = new Evaluator(ValueFactoryFactory.getValueFactory(), System.in, System.err, System.console() != null ? (TerminalProgressBarMonitor) monitor : System.out , root, heap);
evaluator.setMonitor(monitor);

evaluator.addRascalSearchPathContributor(StandardLibraryContributor.getInstance());
Expand Down

0 comments on commit e50a9ab

Please sign in to comment.