diff options
author | MaggieYingYi <29144504+MaggieYingYi@users.noreply.github.com> | 2023-09-06 15:02:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-06 15:02:31 +0100 |
commit | cd8fe1dbcb7dd36f700681ced34b41993e844239 (patch) | |
tree | 1cf9fb3a828c34675abc6234508b83e606ef5739 /llvm/unittests/ProfileData/CoverageMappingTest.cpp | |
parent | 6258912880876edd44944e130aef01b33480168b (diff) | |
download | llvm-cd8fe1dbcb7dd36f700681ced34b41993e844239.zip llvm-cd8fe1dbcb7dd36f700681ced34b41993e844239.tar.gz llvm-cd8fe1dbcb7dd36f700681ced34b41993e844239.tar.bz2 |
[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
Diffstat (limited to 'llvm/unittests/ProfileData/CoverageMappingTest.cpp')
-rw-r--r-- | llvm/unittests/ProfileData/CoverageMappingTest.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
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) { |