[DO-987] catch recipe (!3)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/3
Reviewed-by: Denis Patrakeev <denis.patrakeev@avroid.team>
Co-authored-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.team>
Co-committed-by: Aleksandr Vodyanov <aleksandr.vodyanov@avroid.team>
This commit is contained in:
Aleksandr Vodyanov
2024-11-21 17:23:08 +03:00
committed by Denis Patrakeev
parent bb6197bed7
commit e3106d807c
27 changed files with 928 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>

View File

@@ -0,0 +1,5 @@
#include <catch2/catch.hpp>
TEST_CASE( "compiles and runs" ) {
REQUIRE( true == !false );
}

View File

@@ -0,0 +1,11 @@
#include <catch2/catch.hpp>
unsigned int Factorial( unsigned int number ) {
return number > 1 ? Factorial(number-1)*number : 1;
}
TEST_CASE( "compiles and runs" ) {
BENCHMARK("factorial 25"){
return Factorial(25);
};
}

View File

@@ -0,0 +1,5 @@
#include <catch2/catch.hpp>
CATCH_TEST_CASE( "compiles and runs" ) {
CATCH_REQUIRE( true == !false );
}

View File

@@ -0,0 +1,11 @@
#include <catch2/catch.hpp>
unsigned int Factorial( unsigned int number ) {
return number > 1 ? Factorial(number-1)*number : 1;
}
TEST_CASE( "compiles and runs" ) {
BENCHMARK("factorial 25"){
return Factorial(25);
};
}

View File

@@ -0,0 +1,31 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES CXX)
enable_testing()
find_package(Catch2 REQUIRED CONFIG)
if(WITH_PREFIX)
set(SRC_STANDALONE 300-standalone-with-prefix.cpp)
set(SRC_BENCHMARK 400-benchmark-with-prefix.cpp)
else()
set(SRC_STANDALONE 100-standalone.cpp)
set(SRC_BENCHMARK 200-benchmark.cpp)
endif()
add_executable(standalone 000-CatchMain.cpp ${SRC_STANDALONE})
target_link_libraries(standalone PRIVATE Catch2::Catch2)
target_compile_features(standalone PRIVATE cxx_std_11)
add_test(NAME standalone COMMAND standalone)
if(WITH_MAIN)
add_executable(standalone_with_main ${SRC_STANDALONE})
target_link_libraries(standalone_with_main PRIVATE Catch2::Catch2WithMain)
target_compile_features(standalone_with_main PRIVATE cxx_std_11)
add_test(NAME standalone_with_main COMMAND standalone_with_main)
endif()
if(WITH_BENCHMARK)
add_executable(benchmark ${SRC_BENCHMARK})
target_link_libraries(benchmark PRIVATE Catch2::Catch2WithMain)
target_compile_features(benchmark PRIVATE cxx_std_11)
add_test(NAME benchmark COMMAND benchmark)
endif()

View File

@@ -0,0 +1,33 @@
from conan import ConanFile
from conan.tools.build import build_jobs, can_run
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import chdir
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["WITH_MAIN"] = self.dependencies["catch2"].options.with_main
tc.variables["WITH_BENCHMARK"] = self.dependencies["catch2"].options.get_safe("with_benchmark", False)
tc.variables["WITH_PREFIX"] = self.dependencies["catch2"].options.with_prefix
tc.generate()
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
with chdir(self, self.build_folder):
self.run(f"ctest --output-on-failure -C {self.settings.build_type} -j {build_jobs(self)}", env="conanrun")