Skip to content

Commit

Permalink
Remove unecessary dependency on unit test frameworks and make package…
Browse files Browse the repository at this point in the history
… testing more elegant
  • Loading branch information
Daniel Heater committed Jan 29, 2020
1 parent 8b6169e commit ec535b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
10 changes: 0 additions & 10 deletions recipes/approvaltests.cpp/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,12 @@ class ApprovalTestsCppConan(ConanFile):
"(such as a file) in one operation as opposed to writing " \
"test assertions for each element."
topics = ("conan", "testing", "unit-testing", "header-only")
options = {"test_framework": ["catch2", "gtest", "doctest"]}
default_options = {"test_framework": "catch2"}
no_copy_source = True

@property
def _header_file(self):
return "ApprovalTests.hpp"

def requirements(self):
if self.options.test_framework == "catch2":
self.requires("catch2/2.11.0")
elif self.options.test_framework == "gtest":
self.requires("gtest/1.10.0")
elif self.options.test_framework == "doctest":
self.requires("doctest/2.3.5")

def source(self):
for source in self.conan_data["sources"][self.version]:
url = source["url"]
Expand Down
17 changes: 7 additions & 10 deletions recipes/approvaltests.cpp/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ set(CMAKE_CXX_EXTENSIONS OFF)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
CONAN_BASIC_SETUP()

if(WITH_CATCH)
ADD_EXECUTABLE(test_package test_catch.cpp)
endif()
if(WITH_GTEST)
ADD_EXECUTABLE(test_package test_gtest.cpp)
endif()
if(WITH_DOCTEST)
ADD_EXECUTABLE(test_package test_doctest.cpp)
endif()
ADD_EXECUTABLE(test_package_catch test_catch.cpp)
target_link_libraries(test_package_catch ${CONAN_LIBS})

target_link_libraries(test_package ${CONAN_LIBS})
ADD_EXECUTABLE(test_package_gtest test_gtest.cpp)
target_link_libraries(test_package_gtest ${CONAN_LIBS})

ADD_EXECUTABLE(test_package_doctest test_doctest.cpp)
target_link_libraries(test_package_doctest ${CONAN_LIBS})
17 changes: 8 additions & 9 deletions recipes/approvaltests.cpp/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
class TestPackageConan(ConanFile):
settings = "os", "compiler", "arch", "build_type"
generators = "cmake"
requires = [
"catch2/2.11.0",
"gtest/1.10.0",
"doctest/2.3.5"
]

def build(self):
cmake = CMake(self)

if self.options["approvaltests.cpp"].test_framework == "catch2":
cmake.definitions["WITH_CATCH"] = True
elif self.options["approvaltests.cpp"].test_framework == "gtest":
cmake.definitions["WITH_GTEST"] = True
elif self.options["approvaltests.cpp"].test_framework == "doctest":
cmake.definitions["WITH_DOCTEST"] = True

cmake.configure()
cmake.build()

Expand All @@ -25,4 +22,6 @@ def test(self):
return

bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
self.run(bin_path + "_catch", run_environment=True)
self.run(bin_path + "_gtest", run_environment=True)
self.run(bin_path + "_doctest", run_environment=True)

0 comments on commit ec535b2

Please sign in to comment.