compat.catch2
#includeA modern, C++-native test framework for unit-tests, TDD and BDD
#include <catch2/catch_all.hpp>
mcpp add compat.catch2@3.15.2
用法
來自本倉庫自己的測試專案 —— CI 真的編譯並執行過,不是為了網站寫的。
// compat.catch2 v3, `main` FEATURE: no main() here on purpose — the entry
// point comes from the package's generated TU. Catch2 prints the assertion
// count on exit, so an empty binary cannot pass quietly.
#include <catch2/catch_all.hpp>
static unsigned int factorial(unsigned int n) {
return n <= 1 ? 1 : n * factorial(n - 1);
}
TEST_CASE("factorial of 5 is 120", "[math]") {
REQUIRE(factorial(5) == 120);
}
TEST_CASE("factorial of 0 is 1", "[math]") {
REQUIRE(factorial(0) == 1);
}
tests/examples/catch2-main/tests/main.cpp · 專案 tests/examples/catch2-main
建置
- targets
catch2 (lib)- language
c++23- C standard
c11- import std
- no
- include dirs
mcpp_generated, */single_include, */src
功能
| 功能 | 宣告了 |
|---|---|
| main | sources |
原始檔 (3)
mcpp_generated/catch2_anchor.c*/src/catch2/**/*.cpp!*/src/catch2/internal/catch_main.cpp
產生的檔案
mcpp_generated/catch2/catch.hppmcpp_generated/catch2_main.cppmcpp_generated/catch2_anchor.cmcpp_generated/catch2/catch_user_config.hpp