snip
write unit tests using the snip framework
от teknopaul★ 17 звёзд на GitHub
Установить snip в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Where possible, C code should be unit tested with the snip framework.
Snip tests are a cut-and-paste tests that extract code to test from .c and .h files.
A snip test is a xxx.c.snip file and an executable xxx.c.make file.xxx.c.make is a bash script that has apre-processor, then compiles the test and runs the test.xxx.c.make should be chmod +x.
Typical snip xxx.c.make is as follows...
#!/bin/bash
set -euo pipefail
cd $(dirname $0)
snip_test=xxx
musl-gcc -Wall -Werror -Wno-unused-function -g -O0 \
$snip_test.c \
-o $snip_test \
-lm \
&& ./$snip_test \
&& rm -f ./$snip_test ./${snip_test}.c
for snip tsting io_uring code test/snip/jsonlog/jsonlog_uring_write.c.make has examples for the make stage.
C code that is to be snip tested has pairs of identical comments in the form //SNIP_xxx.
sniprun's preprocessor will find these markers and insert the content into a temporary .c file (using awk).
e.g.
//SNIP_FILE SNIP_json_h ../../../src/nginx_mods/ngx_json_module/ngx_json.h
//SNIP_FILE SNIP_json_c ../../../src/nginx_mods/ngx_json_module/ngx_json.c
SNIP markers are added below any include headers. So SNIP_FILE will only pull in C code, but not any headers.
//SNIP_xxx markers can cover whole files (excluding headers) or just specific functions if the function has no dependencies.
Commons mocks, stub, and asserts for snip tests are in test/snip/include.
c.snip files define their own headers that replace <ngx_*.h> to use mocks & stubs for nginx features.
e.g.
#include "../include/ngx_config.h"
#include "../include/ngx_core.h"
#include "../include/ngx_http.h"
#include "../asserts.h"
Assertions
Snip has common assertions code in
#include "../asserts.h"
c.snip main() functions should use assertions from this header to integration failed and passed counts to the framework.
each c.snip should end
print_results(argv[0]);
... anny cleanup code
return 0;
This will print test assertion counts, but also ensure targets in make fail when snip tests do.
N.B. you cannot nest assert_require() type macros.
Stub maintenance
Occasionally test/snip/include/ngx_*.h mocks and stubs need to be updated when new code uses features from nginx that previously were not.
e.g. snip test fails with some ngx_xxx symbol not found.
The real headers are in src/nginx/src, snips should not refence the real header,
we should create stubs and re-implementations test/snip/include
Fixtures
Strings, test data, and conf files should generally be loaded from ./fixtures in snip tests so that humans get visibility of test data.
fixtures.h has tools for loading fixture.
Executing snip tests
Individual snip tests are run with ./snip/sniprun .../xxx/c.snip
All snips are run with make test-snip, which prints failures at the end of the run.
snipcat should never be run directly.
sniprun creates temporary xxx.c files (using snipcat) in the same directory as the c.snip file, these are removed after successful test runs.
After failed runs the .c and binary file is left for reference only, (e.g. to validate SNIP_FILE and includes), there is no point editing this file, its regenerated the next run.
References
test/snip/json/json_create.c.snip is a good example of a snip test.
https://tp23.org/snip-testing.html
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
- 01
bash - 02
snip/sniprun - 03
chmod
FAQ
Что делает скилл snip?
write unit tests using the snip framework
Как установить скилл snip?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл snip запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…