Skip to content

Commit

Permalink
Fix #311 - don't disable stderr by default
Browse files Browse the repository at this point in the history
  • Loading branch information
atilaneves committed May 1, 2024
1 parent 3bfbfb0 commit f13338d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
16 changes: 15 additions & 1 deletion subpackages/runner/source/unit_threaded/runner/io.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void writelnUt(T...)(auto ref T args) {


private shared(bool) _debugOutput = false; ///print debug msgs?
private shared(bool) _silenceStderr = false; ///print debug msgs?
private shared(bool) _forceEscCodes = false; ///use ANSI escape codes anyway?
package(unit_threaded) immutable bool _useEscCodes;

Expand Down Expand Up @@ -89,6 +90,18 @@ package bool isDebugOutputEnabled() nothrow @trusted {
}
}

package bool isStderrSilenced() @safe nothrow {
synchronized {
return _silenceStderr;
}
}

void disableStderr(bool value = true) @safe nothrow {
synchronized {
_silenceStderr = value;
}
}

package void forceEscCodes() nothrow {
synchronized {
_forceEscCodes = true;
Expand Down Expand Up @@ -272,7 +285,8 @@ void threadWriter(alias OUT, alias ERR)(from!"std.concurrency".Tid tid)

if (!isDebugOutputEnabled()) {
OUT = typeof(OUT)(nullFileName, "w");
ERR = typeof(ERR)(nullFileName, "w");
if(isStderrSilenced)
ERR = typeof(ERR)(nullFileName, "w");
}

void actuallyPrint(in string msg) {
Expand Down
25 changes: 24 additions & 1 deletion tests/unit_threaded/ut/io.d
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@ unittest {
import unit_threaded.should;

enableDebugOutput(false);
disableStderr(false);
resetFakeFiles;

auto tid = spawn(&threadWriter!(gOut, gErr), thisTid);
tid.send(ThreadWait());
receiveOnly!ThreadStarted;

// stdoutshould have been redirected but not stderr
gOut.shouldEqual(shared FakeFile(nullFileName, "w"));
gErr.shouldEqual(shared FakeFile("err", "mode"));

tid.send(ThreadFinish());
receiveOnly!ThreadEnded;
}

unittest {
import std.concurrency: spawn, thisTid, send, receiveOnly;
import unit_threaded.should;

enableDebugOutput(false);
disableStderr(true);
scope(exit) disableStderr(false);
resetFakeFiles;

auto tid = spawn(&threadWriter!(gOut, gErr), thisTid);
Expand All @@ -132,6 +154,7 @@ unittest {
import unit_threaded.should;

enableDebugOutput(true);
disableStderr(false);
scope(exit) enableDebugOutput(false);
resetFakeFiles;

Expand Down Expand Up @@ -454,7 +477,7 @@ unittest {
oops();
writer.output.splitLines.should == [
"OopsTest:",
" " ~ buildPath("tests", "unit_threaded", "ut", "io.d") ~ ":433 - oops",
" " ~ buildPath("tests", "unit_threaded", "ut", "io.d") ~ ":459 - oops",
"",
];
}

0 comments on commit f13338d

Please sign in to comment.