www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Routing of AssertError messages

reply DLearner <bmqazwsx123 gmail.com> writes:
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
Jul 31 2021
next sibling parent jfondren <julian.fondren gmail.com> writes:
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
Jul 31 2021
prev sibling parent Tejas <notrealemail gmail.com> writes:
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: ```d 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.
Jul 31 2021