Thread overview
Routing of AssertError messages
Jul 31, 2021
DLearner
Jul 31, 2021
jfondren
Jul 31, 2021
Tejas
July 31, 2021

Hi

This may be due to Windows, not DMD.

Please see code below (held in test.d):

void main() {
   import std.stdio;

   writeln("Test");
   assert(false, "TestAssert");
}

dmd -i -run test.d
results in both "Test" and the "TestAssert" string (and trace) being routed to screen.

But
dmd -i -run test.d > op.txt
results in only "Test" going into op.txt, the "TestAssert" string (and trace) being routed to screen as before.

I expected both "Test" and the "TestAssert" string (and trace) to go into op.txt.

The idea was to use op.txt as documentation of a successful test of the "TestAssert" string.

Best regards

July 31, 2021

On Saturday, 31 July 2021 at 12:03:49 UTC, DLearner wrote:

>

Hi

This may be due to Windows, not DMD.

Please see code below (held in test.d):

void main() {
   import std.stdio;

   writeln("Test");
   assert(false, "TestAssert");
}

dmd -i -run test.d
results in both "Test" and the "TestAssert" string (and trace) being routed to screen.

But
dmd -i -run test.d > op.txt
results in only "Test" going into op.txt, the "TestAssert" string (and trace) being routed to screen as before.

I expected both "Test" and the "TestAssert" string (and trace) to go into op.txt.

"Test" is written to the standard out stream; "TestAssert" is written to the standard error stream. > only redirects standard out, so the error stream continues to write to the terminal.

Stream redirection depends on your shell. PowerShell docs appear to be here:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-7.1

July 31, 2021

On Saturday, 31 July 2021 at 12:03:49 UTC, DLearner wrote:

>

Hi

This may be due to Windows, not DMD.

Please see code below (held in test.d):

void main() {
   import std.stdio;

   writeln("Test");
   assert(false, "TestAssert");
}

dmd -i -run test.d
results in both "Test" and the "TestAssert" string (and trace) being routed to screen.

But
dmd -i -run test.d > op.txt
results in only "Test" going into op.txt, the "TestAssert" string (and trace) being routed to screen as before.

I expected both "Test" and the "TestAssert" string (and trace) to go into op.txt.

The idea was to use op.txt as documentation of a successful test of the "TestAssert" string.

Best regards

Please read the docs that jfronden referred to.

If you want a quick hack, use this:
    const(char)[] falseAssertMsg(string s){
        writeln(s);
        return "";
    }
    void main() {
       import std.stdio;

       writeln("Test");
       assert(false, falseAssertMsg("TestAssert failed in main()"));
    }

There should be a better way of doing this though.