This is an automated email from the ASF dual-hosted git repository. bneradt pushed a commit to branch errata-note-severity in repository https://gitbox.apache.org/repos/asf/trafficserver-libswoc.git
commit e541322e4a48253dff31f6a97d39020241728ef3 Author: Alan M. Carroll <[email protected]> AuthorDate: Mon Jan 10 14:05:00 2022 -0600 Errata - fix issues with stream output different from BWF output. --- code/src/Errata.cc | 38 ++++++++++---------------------------- unit_tests/test_Errata.cc | 31 ++++++++++++++++++++++--------- 2 files changed, 32 insertions(+), 37 deletions(-) diff --git a/code/src/Errata.cc b/code/src/Errata.cc index 81bf463..2b7b0da 100644 --- a/code/src/Errata.cc +++ b/code/src/Errata.cc @@ -126,32 +126,6 @@ Errata::register_sink(Sink::Handle const& s) { Sink_List.push_back(s); } -std::ostream& -Errata::write(std::ostream& out) const { - string_view lead; - - auto level = this->severity(); - if (level < Errata::SEVERITY_NAMES.size()) { - out << Errata::SEVERITY_NAMES[level]; - } else { - out << unsigned(level._raw); - } - - out << ": "; - - if (this->code()) { - out << this->code().message() << " [" << this->code().value() << "] - "; - } - - for (auto& m : *this) { - out << lead << m._text << std::endl; - if (0 == lead.size()) { - lead = " "_sv; - } - } - return out; -} - BufferWriter& bwformat(BufferWriter& bw, bwf::Spec const& spec, Errata::Severity level) { if (level < Errata::SEVERITY_NAMES.size()) { @@ -165,7 +139,7 @@ bwformat(BufferWriter& bw, bwf::Spec const& spec, Errata::Severity level) { BufferWriter& bwformat(BufferWriter& bw, bwf::Spec const&, Errata const& errata) { - bw.print("{} ", errata.severity()); + bw.print("{}: ", errata.severity()); if (errata.code()) { bw.print("[{0:s} {0:d}] ", errata.code()); @@ -175,13 +149,21 @@ bwformat(BufferWriter& bw, bwf::Spec const&, Errata const& errata) { if (note.text()) { bw.print("{}{}{}\n" , swoc::bwf::Pattern{int(note.level()), " "} - , swoc::bwf::If(note.has_severity(), "{} ", note.severity()) + , swoc::bwf::If(note.has_severity(), "{}: ", note.severity()) , note.text()); } } return bw; } +std::ostream& +Errata::write(std::ostream& out) const { + std::string tmp; + tmp.reserve(1024); + bwprint(tmp, "{}", *this); + return out << tmp; +} + std::ostream& operator<<(std::ostream& os, Errata const& err) { return err.write(os); diff --git a/unit_tests/test_Errata.cc b/unit_tests/test_Errata.cc index 98de648..d23a148 100644 --- a/unit_tests/test_Errata.cc +++ b/unit_tests/test_Errata.cc @@ -214,18 +214,31 @@ TEST_CASE("Errata example", "[libswoc][Errata]") { Errata errata{ec, ERRATA_ERROR, R"(Failed to open file "{}")", path}; w.print("{}", errata); REQUIRE(w.size() > 0); - REQUIRE(w.view().starts_with("Error [enoent") == true); + REQUIRE(w.view().starts_with("Error: [enoent") == true); REQUIRE(w.view().find("enoent") != swoc::TextView::npos); } TEST_CASE("Errata local severity", "[libswoc][Errata]") { std::string s; - Errata errata{ERRATA_ERROR, "Nominal failure"}; - NoteInfo(errata, "Some"); - errata.note(ERRATA_DIAG, "error code {}", std::error_code(EPERM, std::system_category())); - swoc::bwprint(s, "{}", errata); - REQUIRE(s.size() > 0); - REQUIRE(std::string::npos != s.find("Error Nominal")); - REQUIRE(std::string::npos != s.find("Info Some")); - REQUIRE(std::string::npos != s.find("Diag error")); + { + Errata errata{ERRATA_ERROR, "Nominal failure"}; + NoteInfo(errata, "Some"); + errata.note(ERRATA_DIAG, "error code {}", std::error_code(EPERM, std::system_category())); + swoc::bwprint(s, "{}", errata); + REQUIRE(s.size() > 0); + REQUIRE(std::string::npos != s.find("Error: Nominal")); + REQUIRE(std::string::npos != s.find("Info: Some")); + REQUIRE(std::string::npos != s.find("Diag: error")); + } + Errata::FILTER_SEVERITY = ERRATA_INFO; // diag is lesser serverity, shouldn't show up. + { + Errata errata{ERRATA_ERROR, "Nominal failure"}; + NoteInfo(errata, "Some"); + errata.note(ERRATA_DIAG, "error code {}", std::error_code(EPERM, std::system_category())); + swoc::bwprint(s, "{}", errata); + REQUIRE(s.size() > 0); + REQUIRE(std::string::npos != s.find("Error: Nominal")); + REQUIRE(std::string::npos != s.find("Info: Some")); + REQUIRE(std::string::npos == s.find("Diag: error")); + } }
