mirror of
https://github.com/dlang/phobos.git
synced 2025-04-28 14:10:30 +03:00
Do the right thing and verify the stderr output
This commit is contained in:
parent
b3f6f26638
commit
a6f17e2bd7
1 changed files with 16 additions and 10 deletions
|
@ -2575,17 +2575,24 @@ unittest
|
||||||
{
|
{
|
||||||
// Temporarily disable output to stderr so as to not spam the build log.
|
// Temporarily disable output to stderr so as to not spam the build log.
|
||||||
import std.stdio : stderr;
|
import std.stdio : stderr;
|
||||||
|
import std.typecons : Tuple;
|
||||||
|
import std.file : readText;
|
||||||
|
Tuple!(int, "status", string, "output") r;
|
||||||
|
auto tmpname = uniqueTempPath;
|
||||||
auto t = stderr;
|
auto t = stderr;
|
||||||
|
// Open a new scope to minimize code ran with stderr redirected.
|
||||||
|
{
|
||||||
|
stderr.open(tmpname, "w");
|
||||||
|
scope(exit) stderr = t;
|
||||||
|
r = executeShell("echo D rox. 1>&2", null, Config.stderrPassThrough);
|
||||||
|
}
|
||||||
|
assert(r.status == 0);
|
||||||
|
assert(r.output.empty);
|
||||||
|
auto witness = readText(tmpname);
|
||||||
version (Posix)
|
version (Posix)
|
||||||
stderr.open("/dev/null", "w");
|
assert(witness == "D rox.\n", "'" ~ witness ~ "'");
|
||||||
else
|
else
|
||||||
stderr.open("nul", "w");
|
assert(witness == "D rox.\r\n", "'" ~ witness ~ "'");
|
||||||
scope(exit) stderr = t;
|
|
||||||
|
|
||||||
auto r4 = executeShell("echo This line should not be visible. 1>&2",
|
|
||||||
null, Config.stderrPassThrough);
|
|
||||||
assert(r4.status == 0);
|
|
||||||
assert(r4.output.empty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@safe unittest
|
@safe unittest
|
||||||
|
@ -2787,8 +2794,7 @@ private struct TestScript
|
||||||
string path;
|
string path;
|
||||||
}
|
}
|
||||||
|
|
||||||
version (unittest)
|
package(std) string uniqueTempPath() @safe
|
||||||
private string uniqueTempPath() @safe
|
|
||||||
{
|
{
|
||||||
import std.file : tempDir;
|
import std.file : tempDir;
|
||||||
import std.path : buildPath;
|
import std.path : buildPath;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue