LCOV - code coverage report
Current view: top level - lib/Testing/Support - SupportHelpers.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 15 18 83.3 %
Date: 2018-10-20 13:21:21 Functions: 2 2 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : 
       2             : #include "llvm/Testing/Support/SupportHelpers.h"
       3             : 
       4             : #include "llvm/ADT/SmallString.h"
       5             : #include "llvm/ADT/Twine.h"
       6             : #include "llvm/Support/Error.h"
       7             : #include "llvm/Support/FileSystem.h"
       8             : #include "llvm/Support/MemoryBuffer.h"
       9             : #include "llvm/Support/Path.h"
      10             : 
      11             : #include "gtest/gtest.h"
      12             : 
      13             : using namespace llvm;
      14             : using namespace llvm::unittest;
      15             : 
      16           3 : static std::pair<bool, SmallString<128>> findSrcDirMap(StringRef Argv0) {
      17           3 :   SmallString<128> BaseDir = llvm::sys::path::parent_path(Argv0);
      18             : 
      19           3 :   llvm::sys::fs::make_absolute(BaseDir);
      20             : 
      21             :   SmallString<128> PathInSameDir = BaseDir;
      22           3 :   llvm::sys::path::append(PathInSameDir, "llvm.srcdir.txt");
      23             : 
      24           3 :   if (llvm::sys::fs::is_regular_file(PathInSameDir))
      25             :     return std::make_pair(true, std::move(PathInSameDir));
      26             : 
      27           0 :   SmallString<128> PathInParentDir = llvm::sys::path::parent_path(BaseDir);
      28             : 
      29           0 :   llvm::sys::path::append(PathInParentDir, "llvm.srcdir.txt");
      30           0 :   if (llvm::sys::fs::is_regular_file(PathInParentDir))
      31             :     return std::make_pair(true, std::move(PathInParentDir));
      32             : 
      33             :   return std::pair<bool, SmallString<128>>(false, {});
      34             : }
      35             : 
      36           3 : SmallString<128> llvm::unittest::getInputFileDirectory(const char *Argv0) {
      37             :   bool Found = false;
      38             :   SmallString<128> InputFilePath;
      39           6 :   std::tie(Found, InputFilePath) = findSrcDirMap(Argv0);
      40             : 
      41           3 :   EXPECT_TRUE(Found) << "Unit test source directory file does not exist.";
      42             : 
      43           6 :   auto File = MemoryBuffer::getFile(InputFilePath);
      44             : 
      45           3 :   EXPECT_TRUE(static_cast<bool>(File))
      46           3 :       << "Could not open unit test source directory file.";
      47             : 
      48             :   InputFilePath.clear();
      49           6 :   InputFilePath.append((*File)->getBuffer().trim());
      50           3 :   llvm::sys::path::append(InputFilePath, "Inputs");
      51           3 :   llvm::sys::path::native(InputFilePath);
      52           3 :   return InputFilePath;
      53             : }

Generated by: LCOV version 1.13