From cd8fe1dbcb7dd36f700681ced34b41993e844239 Mon Sep 17 00:00:00 2001 From: MaggieYingYi <29144504+MaggieYingYi@users.noreply.github.com> Date: Wed, 6 Sep 2023 15:02:31 +0100 Subject: [llvm-cov] - Output better error message when the error kind is `coveragemap_error::malforme`. (#65264) The current llvm-cov error message for kind `coveragemap_error::malforme`, just gives the issue kind without any reason for what caused the issue. This patch is aimed at improving the llvm-cov error message to help identify what caused the issue. Reviewed By: MaskRay Close: https://github.com/llvm/llvm-project/pull/65264 --- llvm/unittests/ProfileData/CoverageMappingTest.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp') diff --git a/llvm/unittests/ProfileData/CoverageMappingTest.cpp b/llvm/unittests/ProfileData/CoverageMappingTest.cpp index 884a76c..873bc05 100644 --- a/llvm/unittests/ProfileData/CoverageMappingTest.cpp +++ b/llvm/unittests/ProfileData/CoverageMappingTest.cpp @@ -23,14 +23,17 @@ using namespace llvm; using namespace coverage; [[nodiscard]] static ::testing::AssertionResult -ErrorEquals(coveragemap_error Expected, Error E) { +ErrorEquals(Error E, coveragemap_error Expected_Err, + const std::string &Expected_Msg = std::string()) { coveragemap_error Found; + std::string Msg; std::string FoundMsg; handleAllErrors(std::move(E), [&](const CoverageMapError &CME) { Found = CME.get(); + Msg = CME.getMessage(); FoundMsg = CME.message(); }); - if (Expected == Found) + if (Expected_Err == Found && Msg == Expected_Msg) return ::testing::AssertionSuccess(); return ::testing::AssertionFailure() << "error: " << FoundMsg << "\n"; } @@ -342,7 +345,8 @@ TEST_P(CoverageMappingTest, load_coverage_with_bogus_function_name) { ProfileWriter.addRecord({"", 0x1234, {10}}, Err); startFunction("", 0x1234); addCMR(Counter::getCounter(0), "foo", 1, 1, 5, 5); - EXPECT_TRUE(ErrorEquals(coveragemap_error::malformed, loadCoverageMapping())); + EXPECT_TRUE(ErrorEquals(loadCoverageMapping(), coveragemap_error::malformed, + "record function name is empty")); } TEST_P(CoverageMappingTest, load_coverage_for_several_functions) { -- cgit v1.1