diff options
author | Zachary Turner <zturner@google.com> | 2017-06-14 16:41:50 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2017-06-14 16:41:50 +0000 |
commit | cb30e705d8006b5bb7671ab2b364e8c38b6c0232 (patch) | |
tree | 6a8d9510060208e357745338b9d910d4329c6984 /llvm/lib | |
parent | b6567b18c72b3a4370002d689fda50eeee827d5b (diff) | |
download | bcm5719-llvm-cb30e705d8006b5bb7671ab2b364e8c38b6c0232.tar.gz bcm5719-llvm-cb30e705d8006b5bb7671ab2b364e8c38b6c0232.zip |
[gtest] Create a shared include directory for gtest utilities.
Many times unit tests for different libraries would like to use
the same helper functions for checking common types of errors.
This patch adds a common library with helpers for testing things
in Support, and introduces helpers in here for integrating the
llvm::Error and llvm::Expected<T> classes with gtest and gmock.
Normally, we would just be able to write:
EXPECT_THAT(someFunction(), succeeded());
but due to some quirks in llvm::Error's move semantics, gmock
doesn't make this easy, so two macros EXPECT_THAT_ERROR() and
EXPECT_THAT_EXPECTED() are introduced to gloss over the difficulties.
Consider this an exception, and possibly only temporary as we
look for ways to improve this.
Differential Revision: https://reviews.llvm.org/D33059
llvm-svn: 305395
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/LLVMBuild.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Testing/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Testing/LLVMBuild.txt | 19 | ||||
-rw-r--r-- | llvm/lib/Testing/Support/CMakeLists.txt | 12 | ||||
-rw-r--r-- | llvm/lib/Testing/Support/Error.cpp | 22 | ||||
-rw-r--r-- | llvm/lib/Testing/Support/LLVMBuild.txt | 22 |
7 files changed, 78 insertions, 0 deletions
diff --git a/llvm/lib/CMakeLists.txt b/llvm/lib/CMakeLists.txt index f7c09be15fb..946067e6358 100644 --- a/llvm/lib/CMakeLists.txt +++ b/llvm/lib/CMakeLists.txt @@ -24,3 +24,4 @@ add_subdirectory(Fuzzer) add_subdirectory(Passes) add_subdirectory(ToolDrivers) add_subdirectory(XRay) +add_subdirectory(Testing) diff --git a/llvm/lib/LLVMBuild.txt b/llvm/lib/LLVMBuild.txt index 9e586465025..1d22c2a11f1 100644 --- a/llvm/lib/LLVMBuild.txt +++ b/llvm/lib/LLVMBuild.txt @@ -39,6 +39,7 @@ subdirectories = Support TableGen Target + Testing ToolDrivers Transforms diff --git a/llvm/lib/Testing/CMakeLists.txt b/llvm/lib/Testing/CMakeLists.txt new file mode 100644 index 00000000000..fc23e64eeb7 --- /dev/null +++ b/llvm/lib/Testing/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(Support) diff --git a/llvm/lib/Testing/LLVMBuild.txt b/llvm/lib/Testing/LLVMBuild.txt new file mode 100644 index 00000000000..cdf83736298 --- /dev/null +++ b/llvm/lib/Testing/LLVMBuild.txt @@ -0,0 +1,19 @@ +;===- ./lib/Testing/LLVMBuild.txt ------------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[common] +subdirectories = Support diff --git a/llvm/lib/Testing/Support/CMakeLists.txt b/llvm/lib/Testing/Support/CMakeLists.txt new file mode 100644 index 00000000000..fa8dfe59c8b --- /dev/null +++ b/llvm/lib/Testing/Support/CMakeLists.txt @@ -0,0 +1,12 @@ +add_llvm_library(LLVMTestingSupport + Error.cpp + + BUILDTREE_ONLY + + ADDITIONAL_HEADER_DIRS + ${LLVM_MAIN_INCLUDE_DIR}/llvm/Testing/Support + ) + +include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googletest/include) +include_directories(${LLVM_MAIN_SRC_DIR}/utils/unittest/googlemock/include) +target_link_libraries(LLVMTestingSupport PRIVATE gtest)
\ No newline at end of file diff --git a/llvm/lib/Testing/Support/Error.cpp b/llvm/lib/Testing/Support/Error.cpp new file mode 100644 index 00000000000..ce0da44da40 --- /dev/null +++ b/llvm/lib/Testing/Support/Error.cpp @@ -0,0 +1,22 @@ +//===- llvm/Testing/Support/Error.cpp -------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Testing/Support/Error.h" + +#include "llvm/ADT/StringRef.h" + +using namespace llvm; + +llvm::detail::ErrorHolder llvm::detail::TakeError(llvm::Error Err) { + bool Succeeded = !static_cast<bool>(Err); + std::string Message; + if (!Succeeded) + Message = toString(std::move(Err)); + return {Succeeded, Message}; +} diff --git a/llvm/lib/Testing/Support/LLVMBuild.txt b/llvm/lib/Testing/Support/LLVMBuild.txt new file mode 100644 index 00000000000..40853e8172d --- /dev/null +++ b/llvm/lib/Testing/Support/LLVMBuild.txt @@ -0,0 +1,22 @@ +;===- ./Testing/Support/LLVMBuild.txt --------------------------*- Conf -*--===; +; +; The LLVM Compiler Infrastructure +; +; This file is distributed under the University of Illinois Open Source +; License. See LICENSE.TXT for details. +; +;===------------------------------------------------------------------------===; +; +; This is an LLVMBuild description file for the components in this subdirectory. +; +; For more information on the LLVMBuild system, please see: +; +; http://llvm.org/docs/LLVMBuild.html +; +;===------------------------------------------------------------------------===; + +[component_0] +type = Library +name = TestingSupport +parent = Libraries +required_libraries = Support |