用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ComeOnOliver/skillshub --skill doctest-cmake命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | doctest-cmake |
| description | Set up doctest testing framework in CMake C++ projects and write tests colocated with implementation code |
Guide setup and usage of the doctest single-header C++17 testing framework in CMake projects, with tests written directly in source files alongside the code they test.
Ensure the doctest header is present (e.g. in the below example, it's at third-party/doctest/doctest.h). This file must already exist in the repository.
Create test_main.cpp at project root:
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include "doctest/doctest.h"
This file provides doctest's main() function for the test executable.
Add a test executable target alongside your main target:
# Main application (unchanged)
add_executable(your_app
main.cpp
your_source.cpp
)
# Disable doctest in main application
target_compile_definitions(your_app PRIVATE DOCTEST_CONFIG_DISABLE)
# Test executable
add_executable(tests
test_main.cpp
your_source.cpp # Same sources as main app
)
target_include_directories(tests PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/third-party
)
Key points:
doctest.h is, so #include "doctest/doctest.h" resolvesDOCTEST_CONFIG_DISABLE on the main app to strip out all test codeWrite tests in the .cpp file where the code is defined (the implementation file), not in headers where code is declared.
Add tests at the bottom of source files:
// your_source.cpp
#include "your_source.h"
// Implementation code here
int add(int a, int b) {
return a + b;
}
// Tests - automatically disabled in main app via DOCTEST_CONFIG_DISABLE
#include "doctest/doctest.h"
TEST_CASE("add function") {
CHECK(add(2, 3) == 5);
CHECK(add(-1, 1) == 0);
CHECK(add(0, 0) == 0);
}
DOCTEST_CONFIG_DISABLE in the main app target strips out all test code automaticallycmake -B build
cmake --build build
./build/your_app # Run application
./build/tests # Run tests