diff --git a/recipes/catch2/2.x.x/conandata.yml b/recipes/catch2/2.x.x/conandata.yml new file mode 100644 index 0000000000000..a5b9f89c040f7 --- /dev/null +++ b/recipes/catch2/2.x.x/conandata.yml @@ -0,0 +1,4 @@ +sources: + 2.9.2: + url: https://github.com/catchorg/Catch2/archive/v2.9.2.tar.gz + sha256: 54BEA6D80A388A80F895CD0E2343FCA72B0D9093A776AF40904AEFCE49C13BDA diff --git a/recipes/catch2/2.x.x/conanfile.py b/recipes/catch2/2.x.x/conanfile.py new file mode 100644 index 0000000000000..2c2bd5ec0d856 --- /dev/null +++ b/recipes/catch2/2.x.x/conanfile.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +import os + +from conans import ConanFile, CMake, tools + + +class ConanRecipe(ConanFile): + name = "catch2" + description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD" + topics = ("conan", "catch2", "header-only", "unit-test", "tdd", "bdd") + homepage = "https://github.com/catchorg/Catch2" + url = "https://github.com/conan-io/conan-center-index" + license = "BSL-1.0" + + settings = "os", "compiler", "build_type", "arch" + + generators = "cmake" + + _source_subfolder = "source_subfolder" + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + extracted_dir = "Catch2-" + self.version + os.rename(extracted_dir, self._source_subfolder) + + _build_subfolder = "build_subfolder" + + def _configure_cmake(self): + cmake = CMake(self) + cmake.definitions["BUILD_TESTING"] = "OFF" + cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF" + cmake.definitions["CATCH_INSTALL_HELPERS"] = "ON" + cmake.configure( + source_folder=self._source_subfolder, + build_folder=self._build_subfolder + ) + return cmake + + def build(self): + cmake = self._configure_cmake() + cmake.build() + + def package(self): + self.copy(pattern="LICENSE.txt", dst="licenses", + src=self._source_subfolder) + + cmake = self._configure_cmake() + cmake.install() + + tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + tools.rmdir(os.path.join(self.package_folder, "share")) + + def package_id(self): + self.info.header_only() diff --git a/recipes/catch2/2.x.x/test_package/000-CatchMain.cpp b/recipes/catch2/2.x.x/test_package/000-CatchMain.cpp new file mode 100644 index 0000000000000..5a04b2d54f627 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/000-CatchMain.cpp @@ -0,0 +1,15 @@ +// 000-CatchMain.cpp + +// In a Catch project with multiple files, dedicate one file to compile the +// source code of Catch itself and reuse the resulting object file for linking. + +// Let Catch provide main(): +#define CATCH_CONFIG_MAIN + +#include + +// That's it + +// Compile implementation of Catch for use with files that do contain tests: +// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -c 000-CatchMain.cpp +// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% -c 000-CatchMain.cpp \ No newline at end of file diff --git a/recipes/catch2/2.x.x/test_package/100-Fix-Section.cpp b/recipes/catch2/2.x.x/test_package/100-Fix-Section.cpp new file mode 100644 index 0000000000000..8bc2a7839d550 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/100-Fix-Section.cpp @@ -0,0 +1,69 @@ +// 100-Fix-Section.cpp + +// Catch has two ways to express fixtures: +// - Sections (this file) +// - Traditional class-based fixtures + +// main() provided in 000-CatchMain.cpp + +#include + +TEST_CASE( "vectors can be sized and resized", "[vector]" ) { + + // For each section, vector v is anew: + + std::vector v( 5 ); + + REQUIRE( v.size() == 5 ); + REQUIRE( v.capacity() >= 5 ); + + SECTION( "resizing bigger changes size and capacity" ) { + v.resize( 10 ); + + REQUIRE( v.size() == 10 ); + REQUIRE( v.capacity() >= 10 ); + } + SECTION( "resizing smaller changes size but not capacity" ) { + v.resize( 0 ); + + REQUIRE( v.size() == 0 ); + REQUIRE( v.capacity() >= 5 ); + } + SECTION( "reserving bigger changes capacity but not size" ) { + v.reserve( 10 ); + + REQUIRE( v.size() == 5 ); + REQUIRE( v.capacity() >= 10 ); + } + SECTION( "reserving smaller does not change size or capacity" ) { + v.reserve( 0 ); + + REQUIRE( v.size() == 5 ); + REQUIRE( v.capacity() >= 5 ); + } +} + +// Compile & run: +// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 100-Fix-Section 100-Fix-Section.cpp 000-CatchMain.o && 100-Fix-Section --success +// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 100-Fix-Section.cpp 000-CatchMain.obj && 100-Fix-Section --success + +// Expected compact output (all assertions): +// +// prompt> 100-Fix-Section.exe --reporter compact --success +// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5 +// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5 +// 100-Fix-Section.cpp:23: passed: v.size() == 10 for: 10 == 10 +// 100-Fix-Section.cpp:24: passed: v.capacity() >= 10 for: 10 >= 10 +// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5 +// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5 +// 100-Fix-Section.cpp:29: passed: v.size() == 0 for: 0 == 0 +// 100-Fix-Section.cpp:30: passed: v.capacity() >= 5 for: 5 >= 5 +// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5 +// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5 +// 100-Fix-Section.cpp:35: passed: v.size() == 5 for: 5 == 5 +// 100-Fix-Section.cpp:36: passed: v.capacity() >= 10 for: 10 >= 10 +// 100-Fix-Section.cpp:17: passed: v.size() == 5 for: 5 == 5 +// 100-Fix-Section.cpp:18: passed: v.capacity() >= 5 for: 5 >= 5 +// 100-Fix-Section.cpp:41: passed: v.size() == 5 for: 5 == 5 +// 100-Fix-Section.cpp:42: passed: v.capacity() >= 5 for: 5 >= 5 +// Passed 1 test case with 16 assertions. \ No newline at end of file diff --git a/recipes/catch2/2.x.x/test_package/CMakeLists.txt b/recipes/catch2/2.x.x/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..3e5d7823a0b5c --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.5) +project(test_package) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_VERBOSE_MAKEFILE TRUE) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(${PROJECT_NAME} 000-CatchMain.cpp 100-Fix-Section.cpp) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/catch2/2.x.x/test_package/conanfile.py b/recipes/catch2/2.x.x/test_package/conanfile.py new file mode 100644 index 0000000000000..bd7165a553cf4 --- /dev/null +++ b/recipes/catch2/2.x.x/test_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/catch2/config.yml b/recipes/catch2/config.yml new file mode 100644 index 0000000000000..e0983c98b3e02 --- /dev/null +++ b/recipes/catch2/config.yml @@ -0,0 +1,3 @@ +versions: + 2.9.2: + folder: 2.x.x