cmake_minimum_required(VERSION 3.5)
project(untitled4_model_test LANGUAGES CXX)
# 引入 FetchContent 模块
include(FetchContent)
# 声明 Catch2 依赖项
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://gitee.com/oss-mirror-github/Catch2.git
GIT_TAG v3.3.2
)
# 使 Catch2 可用
FetchContent_MakeAvailable(Catch2)
message("Catch2 source directory: ${Catch2_SOURCE_DIR}/src/catch2")
# 添加可执行文件
add_executable(untitled4_model_test main.cpp)
target_include_directories(untitled4_model_test PRIVATE ${Catch2_SOURCE_DIR})
# 链接 Catch2 库
target_link_libraries(untitled4_model_test PRIVATE Catch2::Catch2WithMain)
#define CATCH_CONFIG_MAIN
#include "catch2/catch_test_macros.hpp"
int add(int a, int b) {
return a + b;
}
int subtract(int a, int b) {
return a - b;
}
TEST_CASE("Addition test", "[math]") {
REQUIRE(add(2, 3) == 5);
REQUIRE(add(-1, 1) == 0);
}
TEST_CASE("Subtraction test", "[math]") {
REQUIRE(subtract(5, 3) == 2);
REQUIRE(subtract(0, 0) == 0);
}