From b972a0f1a0d2a22b2987afa18bdc74615c36602d Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Fri, 15 Jul 2016 01:53:39 +0000 Subject: [PATCH] [llvm-cov] Improve error messages While we're at it, extend an existing test to make sure that error messages look reasonable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@275520 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-cov/double_dots.c | 5 +++++ tools/llvm-cov/CodeCoverage.cpp | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/test/tools/llvm-cov/double_dots.c b/test/tools/llvm-cov/double_dots.c index 47224bf9ade..adfd9f7f353 100644 --- a/test/tools/llvm-cov/double_dots.c +++ b/test/tools/llvm-cov/double_dots.c @@ -15,3 +15,8 @@ int main() {} // RUN: FileCheck -check-prefix=REL-INDEX -input-file %t.dir/index.txt %s // REL-INDEX-NOT: %t.dir + +// Check that we get the right error when writing to an invalid path: + +// RUN: not llvm-cov show %S/Inputs/double_dots.covmapping -instr-profile=%t.profdata -o /dev/null 2>&1 | FileCheck %s -check-prefix=ERROR-MESSAGE +// ERROR-MESSAGE: error: Not a directory: Could not create index file! diff --git a/tools/llvm-cov/CodeCoverage.cpp b/tools/llvm-cov/CodeCoverage.cpp index 621f8d7825a..ed48c28c0fc 100644 --- a/tools/llvm-cov/CodeCoverage.cpp +++ b/tools/llvm-cov/CodeCoverage.cpp @@ -117,7 +117,7 @@ static std::string getErrorString(const Twine &Message, StringRef Whence, std::string Str = (Warning ? "warning" : "error"); Str += ": "; if (!Whence.empty()) - Str += Whence; + Str += Whence.str() + ": "; Str += Message.str() + "\n"; return Str; } @@ -504,7 +504,7 @@ int CodeCoverageTool::show(int argc, const char **argv, if (!Filters.empty()) { auto OSOrErr = Printer->createViewFile("functions", /*InToplevel=*/true); if (Error E = OSOrErr.takeError()) { - error(toString(std::move(E))); + error("Could not create view file!", toString(std::move(E))); return 1; } auto OS = std::move(OSOrErr.get()); @@ -540,7 +540,7 @@ int CodeCoverageTool::show(int argc, const char **argv, // Create an index out of the source files. if (ViewOpts.hasOutputDirectory()) { if (Error E = Printer->createIndexFile(SourceFiles)) { - error(toString(std::move(E))); + error("Could not create index file!", toString(std::move(E))); return 1; } } @@ -561,7 +561,7 @@ int CodeCoverageTool::show(int argc, const char **argv, auto OSOrErr = Printer->createViewFile(SourceFile, /*InToplevel=*/false); if (Error E = OSOrErr.takeError()) { - deferError(toString(std::move(E))); + deferError("Could not create view file!", toString(std::move(E))); return; } auto OS = std::move(OSOrErr.get()); -- 2.11.0