Skip to content

Implement syntax highlighting.

gitlab-qa-bot requested to merge add-terminal-syntax-highlighting into master

Created by: myronmarston

This PR adds support for syntax highlighting the printed failure snippet when the coderay gem is available. Here's how it looks:

screen shot 2015-11-08 at 6 23 17 pm screen shot 2015-11-08 at 6 23 57 pm

The implementation is pretty straightforward but there is one hacky part about it: to work properly for the single-line case, where the snippet goes after Failure/Error, we have to insert an ANSI reset code (\e[0m) at the start of the lines -- otherwise there was "leakage" of color changes. What I dislike about the solution is that the syntax highlighter assumes the exception presenter is going to put the snippet at the end of the line. With that assumption, the reset code solution works OK because there isn't any additional text from the presenter later in the line that should be colored a certain way that we are screwing up. But if the snippet was interpolated in the middle of a colored string, our current implementation would lead to some weirdness.

I'm not sure what to do about it if anything, but thought it was worth noting.

Merge request reports