[Lldb-commits] [lldb] r306668 - [unittests] Add a helper function for getting an input file
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 29 06:02:11 PDT 2017
Author: labath
Date: Thu Jun 29 06:02:11 2017
New Revision: 306668
URL: http://llvm.org/viewvc/llvm-project?rev=306668&view=rev
Log:
[unittests] Add a helper function for getting an input file
Summary:
Fetching an input file required about five lines of code, and this was
repeated in multiple unit tests, with slight variations. Add a helper
function for doing that into the lldbUtilityMocks module (which I rename
to lldbUtilityHelpers to commemorate the fact it includes more than
mocks)
Reviewers: zturner, eugene
Subscribers: emaste, mgorny, lldb-commits
Differential Revision: https://reviews.llvm.org/D34683
Added:
lldb/trunk/unittests/Utility/Helpers/
lldb/trunk/unittests/Utility/Helpers/CMakeLists.txt
- copied, changed from r306666, lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt
lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.cpp
- copied, changed from r306666, lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp
lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.h
- copied, changed from r306666, lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h
lldb/trunk/unittests/Utility/Helpers/TestUtilities.cpp
lldb/trunk/unittests/Utility/Helpers/TestUtilities.h
Removed:
lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt
lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp
lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h
Modified:
lldb/trunk/unittests/Interpreter/CMakeLists.txt
lldb/trunk/unittests/Interpreter/TestCompletion.cpp
lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt
lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
lldb/trunk/unittests/Process/minidump/CMakeLists.txt
lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp
lldb/trunk/unittests/Symbol/CMakeLists.txt
lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp
lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt
lldb/trunk/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
lldb/trunk/unittests/SymbolFile/PDB/CMakeLists.txt
lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
lldb/trunk/unittests/Target/CMakeLists.txt
lldb/trunk/unittests/Target/ModuleCacheTest.cpp
lldb/trunk/unittests/Utility/CMakeLists.txt
lldb/trunk/unittests/Utility/StructuredDataTest.cpp
lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp
Modified: lldb/trunk/unittests/Interpreter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Interpreter/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -4,7 +4,7 @@ add_lldb_unittest(InterpreterTests
LINK_LIBS
lldbInterpreter
- lldbUtilityMocks
+ lldbUtilityHelpers
)
target_link_libraries(InterpreterTests
Modified: lldb/trunk/unittests/Interpreter/TestCompletion.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestCompletion.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestCompletion.cpp (original)
+++ lldb/trunk/unittests/Interpreter/TestCompletion.cpp Thu Jun 29 06:02:11 2017
@@ -12,13 +12,12 @@
#include "lldb/Utility/StringList.h"
#include "lldb/Utility/TildeExpressionResolver.h"
+#include "unittests/Utility/Helpers/MockTildeExpressionResolver.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
-#include "unittests/Utility/Mocks/MockTildeExpressionResolver.h"
-
namespace fs = llvm::sys::fs;
namespace path = llvm::sys::path;
using namespace llvm;
Modified: lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -6,6 +6,7 @@ add_lldb_unittest(ObjectFileELFTests
lldbPluginObjectFileELF
lldbPluginSymbolVendorELF
lldbCore
+ lldbUtilityHelpers
)
add_dependencies(ObjectFileELFTests yaml2obj)
Modified: lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp (original)
+++ lldb/trunk/unittests/ObjectFile/ELF/TestObjectFileELF.cpp Thu Jun 29 06:02:11 2017
@@ -9,20 +9,18 @@
//===----------------------------------------------------------------------===//
#include "Plugins/ObjectFile/ELF/ObjectFileELF.h"
+#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
#include "lldb/Core/Module.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/Section.h"
#include "lldb/Host/HostInfo.h"
+#include "unittests/Utility/Helpers/TestUtilities.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
-#include "Plugins/SymbolVendor/ELF/SymbolVendorELF.h"
-
-extern const char *TestMainArgv0;
-
using namespace lldb_private;
using namespace lldb;
@@ -32,10 +30,6 @@ public:
HostInfo::Initialize();
ObjectFileELF::Initialize();
SymbolVendorELF::Initialize();
-
- m_inputs_folder = llvm::sys::path::parent_path(TestMainArgv0);
- llvm::sys::path::append(m_inputs_folder, "Inputs");
- llvm::sys::fs::make_absolute(m_inputs_folder);
}
void TearDown() override {
@@ -45,7 +39,6 @@ public:
}
protected:
- llvm::SmallString<128> m_inputs_folder;
};
#define ASSERT_NO_ERROR(x) \
@@ -60,9 +53,8 @@ protected:
}
TEST_F(ObjectFileELFTest, SectionsResolveConsistently) {
- llvm::SmallString<128> yaml = m_inputs_folder;
- llvm::sys::path::append(yaml, "sections-resolve-consistently.yaml");
- llvm::SmallString<128> obj = m_inputs_folder;
+ std::string yaml = GetInputFilePath("sections-resolve-consistently.yaml");
+ llvm::SmallString<128> obj;
ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile(
"sections-resolve-consistently-%%%%%%", "obj", obj));
Modified: lldb/trunk/unittests/Process/minidump/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/minidump/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/minidump/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Process/minidump/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -7,6 +7,7 @@ add_lldb_unittest(LLDBMinidumpTests
lldbTarget
lldbPluginProcessUtility
lldbPluginProcessMinidump
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
)
Modified: lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp (original)
+++ lldb/trunk/unittests/Process/minidump/MinidumpParserTest.cpp Thu Jun 29 06:02:11 2017
@@ -23,7 +23,7 @@
#include "lldb/Utility/DataBufferLLVM.h"
#include "lldb/Utility/DataExtractor.h"
#include "lldb/Utility/FileSpec.h"
-
+#include "unittests/Utility/Helpers/TestUtilities.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/FileSystem.h"
@@ -35,24 +35,14 @@
// C++ includes
#include <memory>
-extern const char *TestMainArgv0;
-
using namespace lldb_private;
using namespace minidump;
class MinidumpParserTest : public testing::Test {
public:
- void SetUp() override {
- llvm::StringRef dmp_folder = llvm::sys::path::parent_path(TestMainArgv0);
- inputs_folder = dmp_folder;
- llvm::sys::path::append(inputs_folder, "Inputs");
- }
-
void SetUpData(const char *minidump_filename,
uint64_t load_size = UINT64_MAX) {
- llvm::SmallString<128> filename = inputs_folder;
- llvm::sys::path::append(filename, minidump_filename);
-
+ std::string filename = GetInputFilePath(minidump_filename);
auto BufferPtr = DataBufferLLVM::CreateSliceFromPath(filename, load_size, 0);
llvm::Optional<MinidumpParser> optional_parser =
@@ -62,7 +52,6 @@ public:
ASSERT_GT(parser->GetData().size(), 0UL);
}
- llvm::SmallString<128> inputs_folder;
std::unique_ptr<MinidumpParser> parser;
};
Modified: lldb/trunk/unittests/Symbol/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Symbol/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Symbol/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Symbol/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -6,6 +6,7 @@ add_lldb_unittest(SymbolTests
LINK_LIBS
lldbHost
lldbSymbol
+ lldbUtilityHelpers
)
add_dependencies(SymbolTests yaml2obj)
Modified: lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp (original)
+++ lldb/trunk/unittests/Symbol/TestDWARFCallFrameInfo.cpp Thu Jun 29 06:02:11 2017
@@ -16,14 +16,13 @@
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/DWARFCallFrameInfo.h"
#include "lldb/Utility/StreamString.h"
+#include "unittests/Utility/Helpers/TestUtilities.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
-extern const char *TestMainArgv0;
-
using namespace lldb_private;
using namespace lldb;
@@ -32,10 +31,6 @@ public:
void SetUp() override {
HostInfo::Initialize();
ObjectFileELF::Initialize();
-
- m_inputs_folder = llvm::sys::path::parent_path(TestMainArgv0);
- llvm::sys::path::append(m_inputs_folder, "Inputs");
- llvm::sys::fs::make_absolute(m_inputs_folder);
}
void TearDown() override {
@@ -44,8 +39,6 @@ public:
}
protected:
- llvm::SmallString<128> m_inputs_folder;
-
void TestBasic(DWARFCallFrameInfo::Type type, llvm::StringRef symbol);
};
@@ -96,9 +89,8 @@ static UnwindPlan::Row GetExpectedRow2()
void DWARFCallFrameInfoTest::TestBasic(DWARFCallFrameInfo::Type type,
llvm::StringRef symbol) {
- llvm::SmallString<128> yaml = m_inputs_folder;
- llvm::sys::path::append(yaml, "basic-call-frame-info.yaml");
- llvm::SmallString<128> obj = m_inputs_folder;
+ std::string yaml = GetInputFilePath("basic-call-frame-info.yaml");
+ llvm::SmallString<128> obj;
ASSERT_NO_ERROR(llvm::sys::fs::createTemporaryFile(
"basic-call-frame-info-%%%%%%", "obj", obj));
Modified: lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt (original)
+++ lldb/trunk/unittests/SymbolFile/DWARF/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -8,6 +8,7 @@ add_lldb_unittest(SymbolFileDWARFTests
lldbPluginObjectFilePECOFF
lldbPluginSymbolFileDWARF
lldbPluginSymbolFilePDB
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
DebugInfoPDB
Modified: lldb/trunk/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp (original)
+++ lldb/trunk/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp Thu Jun 29 06:02:11 2017
@@ -15,6 +15,9 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Module.h"
@@ -25,12 +28,7 @@
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Utility/FileSpec.h"
-
-#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
-#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
-
-extern const char *TestMainArgv0;
+#include "unittests/Utility/Helpers/TestUtilities.h"
using namespace lldb_private;
@@ -46,12 +44,7 @@ public:
ClangASTContext::Initialize();
SymbolFilePDB::Initialize();
- llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
- llvm::SmallString<128> inputs_folder = exe_folder;
- llvm::sys::path::append(inputs_folder, "Inputs");
-
- m_dwarf_test_exe = inputs_folder;
- llvm::sys::path::append(m_dwarf_test_exe, "test-dwarf.exe");
+ m_dwarf_test_exe = GetInputFilePath("test-dwarf.exe");
}
void TearDown() override {
@@ -63,12 +56,12 @@ public:
}
protected:
- llvm::SmallString<128> m_dwarf_test_exe;
+ std::string m_dwarf_test_exe;
};
TEST_F(SymbolFileDWARFTests, TestAbilitiesForDWARF) {
// Test that when we have Dwarf debug info, SymbolFileDWARF is used.
- FileSpec fspec(m_dwarf_test_exe.c_str(), false);
+ FileSpec fspec(m_dwarf_test_exe, false);
ArchSpec aspec("i686-pc-windows");
lldb::ModuleSP module = std::make_shared<Module>(fspec, aspec);
Modified: lldb/trunk/unittests/SymbolFile/PDB/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/PDB/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/SymbolFile/PDB/CMakeLists.txt (original)
+++ lldb/trunk/unittests/SymbolFile/PDB/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -8,6 +8,7 @@ add_lldb_unittest(SymbolFilePDBTests
lldbPluginObjectFilePECOFF
lldbPluginSymbolFileDWARF
lldbPluginSymbolFilePDB
+ lldbUtiltyHelpers
LINK_COMPONENTS
Support
DebugInfoPDB
Modified: lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp (original)
+++ lldb/trunk/unittests/SymbolFile/PDB/SymbolFilePDBTests.cpp Thu Jun 29 06:02:11 2017
@@ -15,6 +15,9 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
+#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
+#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
#include "lldb/Core/Address.h"
#include "lldb/Core/ArchSpec.h"
#include "lldb/Core/Module.h"
@@ -25,10 +28,7 @@
#include "lldb/Symbol/LineTable.h"
#include "lldb/Symbol/SymbolVendor.h"
#include "lldb/Utility/FileSpec.h"
-
-#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
-#include "Plugins/SymbolFile/PDB/SymbolFilePDB.h"
+#include "unittests/Utility/Helpers/TestUtilities.h"
#if defined(_MSC_VER)
#include "lldb/Host/windows/windows.h"
@@ -37,8 +37,6 @@
#include <algorithm>
-extern const char *TestMainArgv0;
-
using namespace lldb_private;
class SymbolFilePDBTests : public testing::Test {
@@ -61,10 +59,8 @@ public:
llvm::SmallString<128> inputs_folder = exe_folder;
llvm::sys::path::append(inputs_folder, "Inputs");
- m_pdb_test_exe = inputs_folder;
- m_types_test_exe = inputs_folder;
- llvm::sys::path::append(m_pdb_test_exe, "test-pdb.exe");
- llvm::sys::path::append(m_types_test_exe, "test-pdb-types.exe");
+ m_pdb_test_exe = GetInputFile("test-pdb.exe");
+ m_types_test_exe = GetInputFile("test-pdb-types.exe");
}
void TearDown() override {
@@ -80,8 +76,8 @@ public:
}
protected:
- llvm::SmallString<128> m_pdb_test_exe;
- llvm::SmallString<128> m_types_test_exe;
+ std::string m_pdb_test_exe;
+ std::string m_types_test_exe;
bool FileSpecMatchesAsBaseOrFull(const FileSpec &left,
const FileSpec &right) const {
Modified: lldb/trunk/unittests/Target/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Target/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Target/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -8,6 +8,7 @@ add_lldb_unittest(TargetTests
lldbSymbol
lldbUtility
lldbPluginObjectFileELF
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
)
Modified: lldb/trunk/unittests/Target/ModuleCacheTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Target/ModuleCacheTest.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Target/ModuleCacheTest.cpp (original)
+++ lldb/trunk/unittests/Target/ModuleCacheTest.cpp Thu Jun 29 06:02:11 2017
@@ -10,8 +10,7 @@
#include "lldb/Host/HostInfo.h"
#include "lldb/Symbol/SymbolContext.h"
#include "lldb/Target/ModuleCache.h"
-
-extern const char *TestMainArgv0;
+#include "unittests/Utility/Helpers/TestUtilities.h"
using namespace lldb_private;
using namespace lldb;
@@ -26,7 +25,7 @@ public:
protected:
static FileSpec s_cache_dir;
- static llvm::SmallString<128> s_test_executable;
+ static std::string s_test_executable;
void TryGetAndPut(const FileSpec &cache_dir, const char *hostname,
bool expect_download);
@@ -34,7 +33,7 @@ protected:
}
FileSpec ModuleCacheTest::s_cache_dir;
-llvm::SmallString<128> ModuleCacheTest::s_test_executable;
+std::string ModuleCacheTest::s_test_executable;
static const char dummy_hostname[] = "dummy_hostname";
static const char dummy_remote_dir[] = "bin";
@@ -71,10 +70,7 @@ void ModuleCacheTest::SetUpTestCase() {
FileSpec tmpdir_spec;
HostInfo::GetLLDBPath(lldb::ePathTypeLLDBTempSystemDir, s_cache_dir);
-
- llvm::StringRef exe_folder = llvm::sys::path::parent_path(TestMainArgv0);
- s_test_executable = exe_folder;
- llvm::sys::path::append(s_test_executable, "Inputs", module_name);
+ s_test_executable = GetInputFilePath(module_name);
}
void ModuleCacheTest::TearDownTestCase() {
Modified: lldb/trunk/unittests/Utility/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/CMakeLists.txt?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Utility/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -1,4 +1,4 @@
-add_subdirectory(Mocks)
+add_subdirectory(Helpers)
add_lldb_unittest(UtilityTests
ConstStringTest.cpp
@@ -15,7 +15,7 @@ add_lldb_unittest(UtilityTests
LINK_LIBS
lldbUtility
- lldbUtilityMocks
+ lldbUtilityHelpers
LINK_COMPONENTS
Support
)
Copied: lldb/trunk/unittests/Utility/Helpers/CMakeLists.txt (from r306666, lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt)
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Helpers/CMakeLists.txt?p2=lldb/trunk/unittests/Utility/Helpers/CMakeLists.txt&p1=lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt&r1=306666&r2=306668&rev=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Utility/Helpers/CMakeLists.txt Thu Jun 29 06:02:11 2017
@@ -1,5 +1,7 @@
-add_lldb_library(lldbUtilityMocks
+set(EXCLUDE_FROM_ALL ON)
+add_lldb_library(lldbUtilityHelpers
MockTildeExpressionResolver.cpp
+ TestUtilities.cpp
LINK_LIBS
lldbUtility
Copied: lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.cpp (from r306666, lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp)
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.cpp?p2=lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.cpp&p1=lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp&r1=306666&r2=306668&rev=306668&view=diff
==============================================================================
(empty)
Copied: lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.h (from r306666, lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h)
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.h?p2=lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.h&p1=lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h&r1=306666&r2=306668&rev=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h (original)
+++ lldb/trunk/unittests/Utility/Helpers/MockTildeExpressionResolver.h Thu Jun 29 06:02:11 2017
@@ -32,6 +32,6 @@ public:
llvm::SmallVectorImpl<char> &Output) override;
bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override;
};
-}
+} // namespace lldb_private
#endif
Added: lldb/trunk/unittests/Utility/Helpers/TestUtilities.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Helpers/TestUtilities.cpp?rev=306668&view=auto
==============================================================================
--- lldb/trunk/unittests/Utility/Helpers/TestUtilities.cpp (added)
+++ lldb/trunk/unittests/Utility/Helpers/TestUtilities.cpp Thu Jun 29 06:02:11 2017
@@ -0,0 +1,22 @@
+//===- TestUtilities.cpp ----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "TestUtilities.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+extern const char *TestMainArgv0;
+
+std::string lldb_private::GetInputFilePath(const llvm::Twine &name) {
+ llvm::SmallString<128> result = llvm::sys::path::parent_path(TestMainArgv0);
+ llvm::sys::fs::make_absolute(result);
+ llvm::sys::path::append(result, "Inputs", name);
+ return result.str();
+}
Added: lldb/trunk/unittests/Utility/Helpers/TestUtilities.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Helpers/TestUtilities.h?rev=306668&view=auto
==============================================================================
--- lldb/trunk/unittests/Utility/Helpers/TestUtilities.h (added)
+++ lldb/trunk/unittests/Utility/Helpers/TestUtilities.h Thu Jun 29 06:02:11 2017
@@ -0,0 +1,20 @@
+//===- TestUtilities.h ------------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLDB_UNITTESTS_UTILITY_HELPERS_TESTUTILITIES_H
+#define LLDB_UNITTESTS_UTILITY_HELPERS_TESTUTILITIES_H
+
+#include "llvm/ADT/Twine.h"
+#include <string>
+
+namespace lldb_private {
+std::string GetInputFilePath(const llvm::Twine &name);
+}
+
+#endif
Removed: lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt?rev=306667&view=auto
==============================================================================
--- lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Utility/Mocks/CMakeLists.txt (removed)
@@ -1,9 +0,0 @@
-add_lldb_library(lldbUtilityMocks
- MockTildeExpressionResolver.cpp
-
- LINK_LIBS
- lldbUtility
-
- LINK_COMPONENTS
- Support
- )
Removed: lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp?rev=306667&view=auto
==============================================================================
--- lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp (original)
+++ lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.cpp (removed)
@@ -1,80 +0,0 @@
-//===----------------- MockTildeExpressionResolver.cpp ----------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "MockTildeExpressionResolver.h"
-#include "llvm/Support/Path.h"
-
-using namespace lldb_private;
-using namespace llvm;
-
-MockTildeExpressionResolver::MockTildeExpressionResolver(StringRef CurrentUser,
- StringRef HomeDir)
- : CurrentUser(CurrentUser) {
- UserDirectories.insert(std::make_pair(CurrentUser, HomeDir));
-}
-
-void MockTildeExpressionResolver::AddKnownUser(StringRef User,
- StringRef HomeDir) {
- assert(UserDirectories.find(User) == UserDirectories.end());
- UserDirectories.insert(std::make_pair(User, HomeDir));
-}
-
-void MockTildeExpressionResolver::Clear() {
- CurrentUser = StringRef();
- UserDirectories.clear();
-}
-
-void MockTildeExpressionResolver::SetCurrentUser(StringRef User) {
- assert(UserDirectories.find(User) != UserDirectories.end());
- CurrentUser = User;
-}
-
-bool MockTildeExpressionResolver::ResolveExact(StringRef Expr,
- SmallVectorImpl<char> &Output) {
- Output.clear();
-
- assert(!llvm::any_of(
- Expr, [](char c) { return llvm::sys::path::is_separator(c); }));
- assert(Expr.empty() || Expr[0] == '~');
- Expr = Expr.drop_front();
- if (Expr.empty()) {
- auto Dir = UserDirectories[CurrentUser];
- Output.append(Dir.begin(), Dir.end());
- return true;
- }
-
- for (const auto &User : UserDirectories) {
- if (User.getKey() != Expr)
- continue;
- Output.append(User.getValue().begin(), User.getValue().end());
- return true;
- }
- return false;
-}
-
-bool MockTildeExpressionResolver::ResolvePartial(StringRef Expr,
- StringSet<> &Output) {
- Output.clear();
-
- assert(!llvm::any_of(
- Expr, [](char c) { return llvm::sys::path::is_separator(c); }));
- assert(Expr.empty() || Expr[0] == '~');
- Expr = Expr.drop_front();
-
- SmallString<16> QualifiedName("~");
- for (const auto &User : UserDirectories) {
- if (!User.getKey().startswith(Expr))
- continue;
- QualifiedName.resize(1);
- QualifiedName.append(User.getKey().begin(), User.getKey().end());
- Output.insert(QualifiedName);
- }
-
- return !Output.empty();
-}
Removed: lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h?rev=306667&view=auto
==============================================================================
--- lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h (original)
+++ lldb/trunk/unittests/Utility/Mocks/MockTildeExpressionResolver.h (removed)
@@ -1,37 +0,0 @@
-//===--------------------- TildeExpressionResolver.h ------------*- C++ -*-===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLDB_UNITTESTS_UTILITY_MOCKS_MOCK_TILDE_EXPRESSION_RESOLVER_H
-#define LLDB_UNITTESTS_UTILITY_MOCKS_MOCK_TILDE_EXPRESSION_RESOLVER_H
-
-#include "lldb/Utility/TildeExpressionResolver.h"
-
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringMap.h"
-
-namespace lldb_private {
-class MockTildeExpressionResolver : public TildeExpressionResolver {
- llvm::StringRef CurrentUser;
- llvm::StringMap<llvm::StringRef> UserDirectories;
-
-public:
- MockTildeExpressionResolver(llvm::StringRef CurrentUser,
- llvm::StringRef HomeDir);
-
- void AddKnownUser(llvm::StringRef User, llvm::StringRef HomeDir);
- void Clear();
- void SetCurrentUser(llvm::StringRef User);
-
- bool ResolveExact(llvm::StringRef Expr,
- llvm::SmallVectorImpl<char> &Output) override;
- bool ResolvePartial(llvm::StringRef Expr, llvm::StringSet<> &Output) override;
-};
-}
-
-#endif
Modified: lldb/trunk/unittests/Utility/StructuredDataTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/StructuredDataTest.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/StructuredDataTest.cpp (original)
+++ lldb/trunk/unittests/Utility/StructuredDataTest.cpp Thu Jun 29 06:02:11 2017
@@ -9,33 +9,16 @@
#include "gtest/gtest.h"
+#include "Helpers/TestUtilities.h"
#include "lldb/Utility/Status.h"
#include "lldb/Utility/StreamString.h"
#include "lldb/Utility/StructuredData.h"
#include "llvm/Support/Path.h"
-extern const char *TestMainArgv0;
-
using namespace lldb;
using namespace lldb_private;
-namespace {
-
-class StructuredDataTest : public testing::Test {
-public:
- static void SetUpTestCase() {
- s_inputs_folder = llvm::sys::path::parent_path(TestMainArgv0);
- llvm::sys::path::append(s_inputs_folder, "Inputs");
- }
-
-protected:
- static llvm::SmallString<128> s_inputs_folder;
-};
-} // namespace
-
-llvm::SmallString<128> StructuredDataTest::s_inputs_folder;
-
-TEST_F(StructuredDataTest, StringDump) {
+TEST(StructuredDataTest, StringDump) {
std::pair<llvm::StringRef, llvm::StringRef> TestCases[] = {
{R"(asdfg)", R"("asdfg")"},
{R"(as"df)", R"("as\"df")"},
@@ -49,14 +32,13 @@ TEST_F(StructuredDataTest, StringDump) {
}
}
-TEST_F(StructuredDataTest, ParseJSONFromFile) {
+TEST(StructuredDataTest, ParseJSONFromFile) {
Status status;
auto object_sp = StructuredData::ParseJSONFromFile(
FileSpec("non-existing-file.json", false), status);
EXPECT_EQ(nullptr, object_sp);
- llvm::SmallString<128> input = s_inputs_folder;
- llvm::sys::path::append(input, "StructuredData-basic.json");
+ std::string input = GetInputFilePath("StructuredData-basic.json");
object_sp = StructuredData::ParseJSONFromFile(FileSpec(input, false), status);
ASSERT_NE(nullptr, object_sp);
Modified: lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp?rev=306668&r1=306667&r2=306668&view=diff
==============================================================================
--- lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp (original)
+++ lldb/trunk/unittests/Utility/TildeExpressionResolverTest.cpp Thu Jun 29 06:02:11 2017
@@ -1,6 +1,6 @@
#include "gtest/gtest.h"
-#include "Mocks/MockTildeExpressionResolver.h"
+#include "Helpers/MockTildeExpressionResolver.h"
#include "lldb/Utility/TildeExpressionResolver.h"
#include "llvm/ADT/SmallString.h"
More information about the lldb-commits
mailing list