Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
silkfire opened this issue Mar 17, 2024 · 4 comments
Open

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

silkfire opened this issue Mar 17, 2024 · 4 comments

Comments

@silkfire
Copy link

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
Copy link
Owner

@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
Copy link
Author

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
Copy link
Owner

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

  • create a class inheriting from DefaultRunnerReporterWithTypes
  • override IsEnvironmentallyEnabled => true
  • override CreateMessageHandler by returning a class inheriting from DefaultRunnerReporterWithTypesMessageHandler
  • in the handler class override LogStackTrace and prepend the call to the base class with Logger.LogImportantMessage(frameInfo, Environment.Newline)

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants