Skip to content

Commit

Permalink
remove --no-stderr and -q options
Browse files Browse the repository at this point in the history
These are unfixably broken for parallel execution which is the default in sbt.
Addresses point 1) in scalameta#399, see that ticket for more details.
  • Loading branch information
jenshalm committed Aug 10, 2021
1 parent 61da011 commit 833c6a4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.io.IOException;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.stream.Collectors;

import org.junit.runner.Description;
import org.junit.runner.Result;
Expand All @@ -30,7 +27,6 @@ final class EventDispatcher extends RunListener
private final Fingerprint fingerprint;
private final String taskInfo;
private final RunStatistics runStatistics;
private OutputCapture capture;

private final static Description TEST_RUN = Description.createTestDescription("Test", "run");

Expand Down Expand Up @@ -71,7 +67,6 @@ private abstract class InfoEvent extends Event {
@Override
public void testAssumptionFailure(final Failure failure)
{
uncapture(true);
postIfFirst(failure.getDescription(), new ErrorEvent(failure, Status.Skipped) {
void logTo(RichLogger logger) {
if (settings.verbose) {
Expand All @@ -96,7 +91,6 @@ public void testFailure(final Failure failure)
// Ignore error.
}
}
uncapture(true);
postIfFirst(failure.getDescription(), new ErrorEvent(failure, Status.Failure) {
void logTo(RichLogger logger) {
logger.error( failure.getDescription(), settings.buildTestResult(Status.Failure) +ansiName+" "+ durationSuffix() + " " + ansiMsg, error);
Expand All @@ -108,7 +102,6 @@ void logTo(RichLogger logger) {
@Override
public void testFinished(Description desc)
{
uncapture(false);
postIfFirst(desc, new InfoEvent(desc, Status.Success) {
void logTo(RichLogger logger) {
logger.info(desc, settings.buildTestResult(Status.Success) + Ansi.c(desc.getMethodName(), SUCCESS1) + durationSuffix());
Expand Down Expand Up @@ -148,7 +141,6 @@ public void testStarted(Description desc)
if (settings.verbose) {
logger.info(desc, settings.buildPlainName(desc) + " started");
}
capture();
}

private void recordStartTime(Description description) {
Expand Down Expand Up @@ -217,26 +209,6 @@ void post(AbstractEvent e)
handler.handle(e);
}

private void capture()
{
if(settings.quiet && capture == null)
capture = OutputCapture.start();
}

void uncapture(boolean replay)
{
if(settings.quiet && capture != null)
{
capture.stop();
if(replay)
{
try { capture.replay(); }
catch(IOException ex) { logger.error(TEST_RUN, "Error replaying captured stdio", ex); }
}
capture = null;
}
}


// Removes stack trace elements that reference the reflective invocation in TestLauncher.
private static void trimStackTrace(Throwable ex, String fromClassName, String toClassName, Settings settings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ final class JUnitRunner implements Runner {
this.customRunners = customRunners;
Settings defaults = Settings.defaults();

boolean quiet = false, nocolor = false, decodeScalaNames = false,
boolean nocolor = false, decodeScalaNames = false,
logAssert = true, logExceptionClass = true, useSbtLoggers = false, useBufferedLoggers = true;
boolean verbose = false;
boolean suppressSystemError = false;
boolean trimStackTraces = defaults.trimStackTraces();
RunSettings.Summary summary = RunSettings.Summary.SBT;
HashMap<String, String> sysprops = new HashMap<String, String>();
Expand All @@ -51,8 +50,7 @@ final class JUnitRunner implements Runner {
String ignoreRunners = "org.junit.runners.Suite";
String runListener = null;
for(String s : args) {
if("-q".equals(s)) quiet = true;
else if("-v".equals(s) || "--verbose".equals(s)) verbose = true;
if("-v".equals(s) || "--verbose".equals(s)) verbose = true;
else if(s.startsWith("--summary=")) summary = RunSettings.Summary.values()[Integer.parseInt(s.substring(10))];
else if("-n".equals(s)) nocolor = true;
else if("-s".equals(s)) decodeScalaNames = true;
Expand Down Expand Up @@ -80,18 +78,15 @@ else if(s.startsWith("-D") && s.contains("=")) {
else if(!s.startsWith("-") && !s.startsWith("+")) globPatterns.add(s);
}
for(String s : args) {
if("+q".equals(s)) quiet = false;
else if("+n".equals(s)) nocolor = false;
if("+n".equals(s)) nocolor = false;
else if("+s".equals(s)) decodeScalaNames = false;
else if("+a".equals(s)) logAssert = false;
else if("+c".equals(s)) logExceptionClass = true;
else if("+l".equals(s)) useSbtLoggers = true;
else if("--no-stderr".equals(s)) suppressSystemError = true;
else if("--stderr".equals(s)) suppressSystemError = false;
}
this.settings =
new RunSettings(!nocolor, decodeScalaNames, quiet, verbose, useSbtLoggers, useBufferedLoggers, trimStackTraces, summary, logAssert, ignoreRunners, logExceptionClass,
suppressSystemError, sysprops, globPatterns, includeCategories, excludeCategories, includeTags, excludeTags,
new RunSettings(!nocolor, decodeScalaNames, verbose, useSbtLoggers, useBufferedLoggers, trimStackTraces, summary, logAssert, ignoreRunners, logExceptionClass,
sysprops, globPatterns, includeCategories, excludeCategories, includeTags, excludeTags,
testFilter);
this.runListener = createRunListener(runListener);
this.runStatistics = new RunStatistics(settings);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package munit.internal.junitinterface;

import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.annotation.Annotation;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -55,9 +53,7 @@ public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
if (runner.runListener != null) ju.addListener(runner.runListener);

Map<String, Object> oldprops = settings.overrideSystemProperties();
PrintStream oldSystemError = System.err;
try {
suppressSystemError();
try {
Class<?> cl = runner.testClassLoader.loadClass(testClassName);
boolean isRun = shouldRun(fingerprint, cl, settings);
Expand All @@ -84,23 +80,11 @@ public Task[] execute(EventHandler eventHandler, Logger[] loggers) {
}
} finally {
settings.restoreSystemProperties(oldprops);
System.setErr(oldSystemError);
}
return new Task[0]; // junit tests do not nest
}


private static final PrintStream EMPTY_PRINTSTREAM = new PrintStream(new OutputStream() {
@Override
public void write(int b) {}
});
private void suppressSystemError() {
if (settings.suppressSystemError) {
System.setErr(EMPTY_PRINTSTREAM);
}
}


private boolean shouldRun(Fingerprint fingerprint, Class<?> clazz, RunSettings settings) {
if(JUNIT_FP.equals(fingerprint)) {
// Ignore classes which are matched by the other fingerprints
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,13 @@ class RunSettings implements Settings {
private static final Object NULL = new Object();

final boolean color;
final boolean quiet;
final boolean logAssert;
final boolean logExceptionClass;
final Set<String> includeTags, excludeTags;
final boolean useSbtLoggers;
final boolean useBufferedLoggers;
final boolean trimStackTraces;
final boolean verbose;
final boolean suppressSystemError;
final Summary summary;
final ArrayList<String> globPatterns;
final Set<String> includeCategories, excludeCategories;
Expand All @@ -43,23 +41,21 @@ class RunSettings implements Settings {
private final HashMap<String, String> sysprops;
private final HashSet<String> ignoreRunners = new HashSet<String>();

RunSettings(boolean color, boolean decodeScalaNames, boolean quiet,
RunSettings(boolean color, boolean decodeScalaNames,
boolean verbose, boolean useSbtLoggers, boolean useBufferedLoggers, boolean trimStackTraces,
Summary summary, boolean logAssert, String ignoreRunners,
boolean logExceptionClass,
boolean suppressSystemError, HashMap<String, String> sysprops,
HashMap<String, String> sysprops,
ArrayList<String> globPatterns,
Set<String> includeCategories, Set<String> excludeCategories,
Set<String> includeTags, Set<String> excludeTags,
String testFilter) {
this.color = color;
this.decodeScalaNames = decodeScalaNames;
this.quiet = quiet;
this.verbose = verbose;
this.summary = summary;
this.logAssert = logAssert;
this.logExceptionClass = logExceptionClass;
this.suppressSystemError = suppressSystemError;
this.includeTags = includeTags;
this.excludeTags = excludeTags;
for(String s : ignoreRunners.split(","))
Expand Down

0 comments on commit 833c6a4

Please sign in to comment.