Add diag::Formatter::Style::print_newline_at_end

Automatically prints a newline at the end of the last diagnostic in a list. Defaults to true.

Disabled for many tests that assume no newline at end of string.

Change-Id: Id1c2f7771f03f22d926fafc2bebebcef056ac5e8
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37260
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2021-01-11 21:09:22 +00:00
committed by Commit Bot service account
parent 4a0b9f77ef
commit d221738e20
10 changed files with 57 additions and 29 deletions

View File

@@ -121,6 +121,9 @@ void Formatter::format(const List& list, Printer* printer) const {
format(diag, state);
first = false;
}
if (style_.print_newline_at_end) {
state.newline();
}
}
void Formatter::format(const Diagnostic& diag, State& state) const {

View File

@@ -36,6 +36,8 @@ class Formatter {
bool print_severity = true;
/// include the source line(s) for the diagnostic
bool print_line = true;
/// print a newline at the end of a diagnostic list
bool print_newline_at_end = true;
};
/// Constructor for the formatter using a default style.

View File

@@ -45,7 +45,7 @@ class DiagFormatterTest : public testing::Test {
};
TEST_F(DiagFormatterTest, Simple) {
Formatter fmt{{false, false, false}};
Formatter fmt{{false, false, false, false}};
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
auto* expect = R"(1:14: purr
2:14: grrr
@@ -54,8 +54,19 @@ TEST_F(DiagFormatterTest, Simple) {
ASSERT_EQ(expect, got);
}
TEST_F(DiagFormatterTest, SimpleNewlineAtEnd) {
Formatter fmt{{false, false, false, true}};
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
auto* expect = R"(1:14: purr
2:14: grrr
3:16 abc123: hiss
4:16: nothing
)";
ASSERT_EQ(expect, got);
}
TEST_F(DiagFormatterTest, SimpleNoSource) {
Formatter fmt{{false, false, false}};
Formatter fmt{{false, false, false, false}};
Diagnostic diag{Severity::Info, Source{}, "no source!"};
auto got = fmt.format(List{diag});
auto* expect = "no source!";
@@ -63,7 +74,7 @@ TEST_F(DiagFormatterTest, SimpleNoSource) {
}
TEST_F(DiagFormatterTest, WithFile) {
Formatter fmt{{true, false, false}};
Formatter fmt{{true, false, false, false}};
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
auto* expect = R"(file.name:1:14: purr
file.name:2:14: grrr
@@ -73,7 +84,7 @@ file.name:4:16: nothing)";
}
TEST_F(DiagFormatterTest, WithSeverity) {
Formatter fmt{{false, true, false}};
Formatter fmt{{false, true, false, false}};
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
auto* expect = R"(1:14 info: purr
2:14 warning: grrr
@@ -83,7 +94,7 @@ TEST_F(DiagFormatterTest, WithSeverity) {
}
TEST_F(DiagFormatterTest, WithLine) {
Formatter fmt{{false, false, true}};
Formatter fmt{{false, false, true, false}};
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
auto* expect = R"(1:14: purr
the cat says meow
@@ -105,7 +116,7 @@ the snail says ???
}
TEST_F(DiagFormatterTest, BasicWithFileSeverityLine) {
Formatter fmt{{true, true, true}};
Formatter fmt{{true, true, true, false}};
auto got = fmt.format(List{diag_info, diag_warn, diag_err, diag_fatal});
auto* expect = R"(file.name:1:14 info: purr
the cat says meow
@@ -130,7 +141,7 @@ TEST_F(DiagFormatterTest, BasicWithMultiLine) {
Diagnostic multiline{Severity::Warning,
Source{Source::Range{{2, 9}, {4, 15}}, &file},
"multiline"};
Formatter fmt{{false, false, true}};
Formatter fmt{{false, false, true, false}};
auto got = fmt.format(List{multiline});
auto* expect = R"(2:9: multiline
the dog says woof