diff --git a/.pi/skills/tdd/SKILL.md b/.pi/skills/tdd/SKILL.md index 8271ae4..9f0b2af 100644 --- a/.pi/skills/tdd/SKILL.md +++ b/.pi/skills/tdd/SKILL.md @@ -2,11 +2,14 @@ name: tdd description: Test-driven development with Unity and CMock. Use when adding new modules, writing tests, mocking dependencies, or following Red-Green-Refactor - in this C23 project. + in projects scaffolded from the ctdd template. --- # TDD Skill +> Replace `/` with the project source directory (e.g. `ctdd/`, `src/`). +> Replace `` with the module name (e.g. `counter`, `timer`). + ## Quick Reference | Action | Command | @@ -20,7 +23,7 @@ description: Test-driven development with Unity and CMock. Use when adding new ## Red-Green-Refactor -Every change to `ctdd/` follows this cycle: +Every change to `/` follows this cycle: 1. **RED** — Write a failing test. Confirm it fails. 2. **GREEN** — Write the minimum code to pass. Confirm it passes. @@ -33,7 +36,7 @@ before the implementation was missing. ### 1. Write the header -Create `ctdd/.h` with the public prototype(s). +Create `/.h` with the public prototype(s). ```c #pragma once @@ -50,7 +53,7 @@ Create `tests/test_.c`. Two patterns exist: ```c #include "unity.h" -#include "ctdd/.h" +#include "/.h" void setUp(void) {} void tearDown(void) {} @@ -70,7 +73,7 @@ int main(void) { ```c #include "unity.h" -#include "ctdd/.h" +#include "/.h" #include "Mock.h" void setUp(void) { Mock_Init(); } @@ -97,7 +100,7 @@ Add after existing test targets, before the `check` target: ```cmake add_executable(test_ test_.c) target_include_directories(test_ PRIVATE "${CMAKE_SOURCE_DIR}") -target_link_libraries(test_ PRIVATE ctdd_ Unity::Unity) +target_link_libraries(test_ PRIVATE _ Unity::Unity) target_compile_features(test_ PRIVATE c_std_23) add_test(NAME test_ COMMAND test_) list(APPEND TEST_TARGETS test_) @@ -108,31 +111,31 @@ list(APPEND TEST_TARGETS test_) ```cmake add_executable(test_ test_.c) target_include_directories(test_ PRIVATE "${CMAKE_SOURCE_DIR}") -target_link_libraries(test_ PRIVATE ctdd_ Unity::Unity CMock::CMock) +target_link_libraries(test_ PRIVATE _ Unity::Unity CMock::CMock) target_compile_features(test_ PRIVATE c_std_23) -cmock_generate_mock(test_ "${CMAKE_SOURCE_DIR}/ctdd/.h") +cmock_generate_mock(test_ "${CMAKE_SOURCE_DIR}//.h") add_test(NAME test_ COMMAND test_) list(APPEND TEST_TARGETS test_) ``` ### 4. Stub the implementation -Create `ctdd/.c` with a dummy return: +Create `/.c` with a dummy return: ```c -#include "ctdd/.h" +#include "/.h" auto fn_name(int arg) -> int { return 0; } ``` -Register the library in `ctdd/CMakeLists.txt`: +Register the library in `/CMakeLists.txt`: ```cmake -add_library(ctdd_ .c) -target_include_directories(ctdd_ PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") -target_compile_features(ctdd_ PRIVATE c_std_23) +add_library(_ .c) +target_include_directories(_ PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}") +target_compile_features(_ PRIVATE c_std_23) ``` ### 5. Confirm RED @@ -215,7 +218,7 @@ Before considering a task done: - [ ] Header declares the public API - [ ] Test covers at least one happy path, one edge case - [ ] Test registered in `tests/CMakeLists.txt` -- [ ] Library registered in `ctdd/CMakeLists.txt` (if new module) +- [ ] Library registered in `/CMakeLists.txt` (if new module) - [ ] `ninja -C build check` passes with zero failures - [ ] No semicolons after closing braces - [ ] Trailing return type on all functions