Repository: conan-io/conan-center-index

Issue:
[request] approval-tests-cpp/7.0.0
### Package Details
  * Package Name/Version: **approval-tests-cpp/7.0.0**
  * Website: **https://github.com/approvals/ApprovalTests.cpp**
  * Source code: **https://github.com/approvals/ApprovalTests.cpp**


### Description Of The Library / Tool
Approval Tests allow you to verify a chunk of output (such as a file) in one operation as opposed to writing test assertions for each element.


Discussion:
CC @claremacrae

Resolving patch:
diff --git a/recipes/approvaltests.cpp/all/conanfile.py b/recipes/approvaltests.cpp/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/approvaltests.cpp/all/conanfile.py
@@ -0,0 +1,56 @@
+import os
+from conans import ConanFile, tools
+
+
+class ApprovalTestsCppConan(ConanFile):
+    name = "approvaltests.cpp"
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "https://github.com/approvals/ApprovalTests.cpp"
+    license = "Apache-2.0"
+    description = "Approval Tests allow you to verify a chunk of output " \
+                  "(such as a file) in one operation as opposed to writing " \
+                  "test assertions for each element."
+    topics = ("conan", "testing", "unit-testing", "header-only")
+    options = {
+        "with_catch2": [True, False],
+        "with_gtest": [True, False],
+        "with_doctest": [True, False]
+    }
+    default_options = {
+        "with_catch2": False,
+        "with_gtest": False,
+        "with_doctest": False
+    }
+    no_copy_source = True
+
+    @property
+    def _header_file(self):
+        return "ApprovalTests.hpp"
+
+    def requirements(self):
+        if self.options.with_catch2:
+            self.requires("catch2/2.11.0")
+        if self.options.with_gtest:
+            self.requires("gtest/1.10.0")
+        if self.options.with_doctest:
+            self.requires("doctest/2.3.6")
+
+    def source(self):
+        for source in self.conan_data["sources"][self.version]:
+            url = source["url"]
+            filename = url[url.rfind("/") + 1:]
+            tools.download(url, filename)
+            tools.check_sha256(filename, source["sha256"])
+        os.rename("ApprovalTests.v.{}.hpp".format(self.version),
+                  self._header_file)
+
+    def package(self):
+        self.copy(self._header_file, dst="include")
+        self.copy("LICENSE", dst="licenses")
+
+    def package_info(self):
+        self.cpp_info.names["cmake_find_package"] = "ApprovalTests"
+        self.cpp_info.names["cmake_find_package_multi"] = "ApprovalTests"
+
+    def package_id(self):
+        self.info.header_only()


Test patch:
diff --git a/recipes/approvaltests.cpp/all/test_package/CMakeLists.txt b/recipes/approvaltests.cpp/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/approvaltests.cpp/all/test_package/CMakeLists.txt
@@ -0,0 +1,22 @@
+cmake_minimum_required(VERSION 2.8)
+PROJECT(test_package)
+
+set(CMAKE_CXX_STANDARD 11)
+set(CMAKE_CXX_STANDARD_REQUIRED ON)
+set(CMAKE_CXX_EXTENSIONS OFF)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+CONAN_BASIC_SETUP()
+
+if(WITH_CATCH)
+    ADD_EXECUTABLE(test_package_catch test_catch.cpp)
+    target_link_libraries(test_package_catch ${CONAN_LIBS})
+endif()
+if(WITH_GTEST)
+    ADD_EXECUTABLE(test_package_gtest test_gtest.cpp)
+    target_link_libraries(test_package_gtest ${CONAN_LIBS})
+endif()
+if(WITH_DOCTEST)
+    ADD_EXECUTABLE(test_package_doctest test_doctest.cpp)
+    target_link_libraries(test_package_doctest ${CONAN_LIBS})
+endif()
diff --git a/recipes/approvaltests.cpp/all/test_package/conanfile.py b/recipes/approvaltests.cpp/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/approvaltests.cpp/all/test_package/conanfile.py
@@ -0,0 +1,39 @@
+import os
+from conans import ConanFile, CMake, tools
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "arch", "build_type"
+    generators = "cmake"
+    default_options = {
+        "approvaltests.cpp:with_catch2": True,
+        "approvaltests.cpp:with_gtest": True,
+        "approvaltests.cpp:with_doctest": True
+    }
+
+
+    def build(self):
+        cmake = CMake(self)
+
+        if self.options["approvaltests.cpp"].with_catch2:
+            cmake.definitions["WITH_CATCH"] = True
+        if self.options["approvaltests.cpp"].with_gtest:
+            cmake.definitions["WITH_GTEST"] = True
+        if self.options["approvaltests.cpp"].with_doctest:
+            cmake.definitions["WITH_DOCTEST"] = True
+
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if tools.cross_building(self.settings):
+            self.output.warn("Skipping run cross built package")
+            return
+
+        bin_path = os.path.join("bin", "test_package")
+        if self.options["approvaltests.cpp"].with_catch2:
+            self.run(bin_path + "_catch", run_environment=True)
+        if self.options["approvaltests.cpp"].with_gtest:
+            self.run(bin_path + "_gtest", run_environment=True)
+        elif self.options["approvaltests.cpp"].with_doctest:
+            self.run(bin_path + "_doctest", run_environment=True)
diff --git a/recipes/approvaltests.cpp/all/test_package/test_catch.cpp b/recipes/approvaltests.cpp/all/test_package/test_catch.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/approvaltests.cpp/all/test_package/test_catch.cpp
@@ -0,0 +1,6 @@
+#define APPROVALS_CATCH
+#include "ApprovalTests.hpp"
+
+TEST_CASE("Package") {
+    REQUIRE(true);
+}
diff --git a/recipes/approvaltests.cpp/all/test_package/test_doctest.cpp b/recipes/approvaltests.cpp/all/test_package/test_doctest.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/approvaltests.cpp/all/test_package/test_doctest.cpp
@@ -0,0 +1,6 @@
+#define APPROVALS_DOCTEST
+#include "ApprovalTests.hpp"
+
+TEST_CASE("Package") {
+    CHECK(true);
+}
diff --git a/recipes/approvaltests.cpp/all/test_package/test_gtest.cpp b/recipes/approvaltests.cpp/all/test_package/test_gtest.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/approvaltests.cpp/all/test_package/test_gtest.cpp
@@ -0,0 +1,6 @@
+#define APPROVALS_GOOGLETEST
+#include "ApprovalTests.hpp"
+
+TEST(Package, GTest) {
+    SUCCEED();
+}