ChristophHornung / xunitmessages

Apache License 2.0
3 stars 0 forks source link

Add option to always add a newline to custom message #2

Open silkfire opened 5 months ago

silkfire commented 5 months ago

I absolutely love this library, but one thing that has been bothering me is that the output is always attached with the stack trace in the output window, something I don't really like. To remedy this, I have to append a newline (\n) to all my custom messages.

It'd be nice if there was a configuration or perhaps a global static configuration that would allow me to append the newline (or other custom text) to all custom messages.

image

Something along the lines of:

AssertM.CustomMessageSuffix = "\n";
ChristophHornung commented 5 months ago

@silkfire The formatting of message + stacktrace is something that is done directly in the XUnit runner afaik, the only way I see to modify it directly is to add an extra newline to the message itself as XUnit does not support such a behaviour in its formatting. That sounds a bit clunky.

One of the features that wasn't trivial to implement was filtering the XUnitMessages parts of the stacktrace (just like XUnit does with its own stacktrace parts), I might take another look to see if there is a way to get this to work. This might be an opportunity to add such a feature.

Any specific reason you want to have the newline?

silkfire commented 5 months ago

It's more of a personal preference of mine. I like when the main message is separated from the rest visually.

I thought this library was in control of the custom message, meaning that it would be easy to add an option for this, although you had to edit a lot of methods to get it to work.

Would be exciting if you could find a working solution for this :)

ChristophHornung commented 5 months ago

@silkfire Looking at xUnit, the easiest way to implement what you need in the meantime would probably be:

This will modify the reporter to prepend newlines before reporting the stacktrace. Beware that depending on your environment (TeamCity, ReShaper, etc...) another IRunnerReporter might be active and that approach would not work. Should work in the case of running tests from the console though.

silkfire commented 5 months ago

I'm running my tests in ReSharper while developing so that's probably not an option then.