How to configure exception log color background style for failed tests #4069
-
I'm running unit tests and would like to stop the build process if they fail. This seems to work fine by throwing an exception, but it results in the error text being renderer with a red background and a very low contrast font color in my IDE and Terminal: I saw that there's a feature request for configuring the color palette, but in my case I wonder if there's a way to simply disable the background color styling for this type of message. I'd rather have no backgrounds, but red text instead. If there's no builtin feature yet, is this something I can overwrite by creating my own module? I'm not sure which class to replace though. I tried looking through the source code and stumbled over ICakeLog, IConsole and IConsoleRenderer, but I'm not seeing where the red background color is actually set caused by the exception, so I wouldn't know where to insert my changes. Also, is this the usual way to report test failures? It feels a little weird to throw an exception and then read "An error occurred" in the log rather than something like "Tests failed, build aborted". I tried to find an option to set the task status (Succeeded, Failed, Skipped), but didn't see it. Maybe it would be a better idea to add a Criterion to follow-up build tasks to skip them when the test fails, but not throw an exception, and instead run to the end to handle test reporting as part of a custom reporter? Sorry for being a Cake noob and thanks for any answers! I love the work being done here; would be happy to invest some time as well, when I get to a point where I understand Cake. :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
For Reference: Color-related issues are #1461, #2976, #3138, #3245 @chrisyarbrough It seems that is not possible, currently. However, simply ignoring all colors should be fairly easy to do in a module: The Alternative solution with custom colorsWhile the cake/src/Cake.Core/Diagnostics/CakeBuildLog.cs Lines 19 to 41 in 9828d7b So, if you want to define your own colors, you'd need to supply a custom version of As to the other question:
Normally, I'd use a unit test project and have that run using some console runner for the given unit test framework of my choosing. Then again, I've never written things for Unitiy. So, I wouldn't know. Sorry. |
Beta Was this translation helpful? Give feedback.
For Reference: Color-related issues are #1461, #2976, #3138, #3245
@chrisyarbrough It seems that is not possible, currently. However, simply ignoring all colors should be fairly easy to do in a module:
The
IConsole
has the ability to change the color - if you supply a version ofIConsole
that simply "ignores" changes toForegroundColor
andBackgroundColor
you'll get output completely without color changes.Alternative solution with custom colors
While the
IConsoleRenderer
decides which color to use to render logs, supplying a version ofIConsoleRenderer
would not change much, since theICakeLog
decides on its own whichIConsoleRenderer
to use:cake/src/Cake.Core/Diagnostics/CakeBuildLo…