Skip to content

Commit d4f5503

Browse files
committed
CommonSyntaxTest: Fix info messages being colored as errors
1 parent 2e8e1f3 commit d4f5503

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

libsolutil/AnsiColorized.h

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ static constexpr char const* BLUE_BACKGROUND = "\033[44m";
5252
static constexpr char const* MAGENTA_BACKGROUND = "\033[45m";
5353
static constexpr char const* CYAN_BACKGROUND = "\033[46m";
5454
static constexpr char const* WHITE_BACKGROUND = "\033[47m";
55+
static constexpr char const* GRAY_BACKGROUND = "\033[100m";
5556

5657
// 256-bit-colors (incomplete set)
5758
static constexpr char const* RED_BACKGROUND_256 = "\033[48;5;160m";

test/CommonSyntaxTest.cpp

+14-3
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,18 @@ void CommonSyntaxTest::printSource(ostream& _stream, string const& _linePrefix,
115115
{
116116
assert(static_cast<size_t>(error.locationStart) <= source.length());
117117
assert(static_cast<size_t>(error.locationEnd) <= source.length());
118-
bool isWarning = (error.type == Error::Type::Warning);
119118
for (int i = error.locationStart; i < error.locationEnd; i++)
120-
if (isWarning)
119+
if (error.type == Error::Type::Info)
121120
{
122121
if (sourceFormatting[static_cast<size_t>(i)] == util::formatting::RESET)
122+
sourceFormatting[static_cast<size_t>(i)] = util::formatting::GRAY_BACKGROUND;
123+
}
124+
else if (error.type == Error::Type::Warning)
125+
{
126+
if (
127+
sourceFormatting[static_cast<size_t>(i)] == util::formatting::RESET ||
128+
sourceFormatting[static_cast<size_t>(i)] == util::formatting::GRAY_BACKGROUND
129+
)
123130
sourceFormatting[static_cast<size_t>(i)] = util::formatting::ORANGE_BACKGROUND_256;
124131
}
125132
else
@@ -190,7 +197,11 @@ void CommonSyntaxTest::printErrorList(
190197
for (auto const& error: _errorList)
191198
{
192199
{
193-
util::AnsiColorized scope(_stream, _formatted, {BOLD, (error.type == Error::Type::Warning) ? YELLOW : RED});
200+
util::AnsiColorized scope(
201+
_stream,
202+
_formatted,
203+
{BOLD, error.type == Error::Type::Info ? WHITE : (error.type == Error::Type::Warning ? YELLOW : RED)}
204+
);
194205
_stream << _linePrefix << Error::formatErrorType(error.type);
195206
if (error.errorId.has_value())
196207
_stream << ' ' << error.errorId->error;

0 commit comments

Comments
 (0)