{"id":50394168,"url":"https://github.com/skywind3000/codecheck","last_synced_at":"2026-05-30T20:01:24.690Z","repository":{"id":360889813,"uuid":"1252078803","full_name":"skywind3000/codecheck","owner":"skywind3000","description":"注释驱动测试工具：从 C/C++/Python/Pascal 代码注释里解出 @input/@output/@timeout 测试数据并验证程序期望输出（纯手工打造）","archived":false,"fork":false,"pushed_at":"2026-05-28T08:57:10.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-05-28T10:25:05.688Z","etag":null,"topics":["cpp","online-judge","online-judge-tools","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skywind3000.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-28T07:02:55.000Z","updated_at":"2026-05-28T10:07:26.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/skywind3000/codecheck","commit_stats":null,"previous_names":["skywind3000/codecheck"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/skywind3000/codecheck","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywind3000%2Fcodecheck","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywind3000%2Fcodecheck/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywind3000%2Fcodecheck/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywind3000%2Fcodecheck/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skywind3000","download_url":"https://codeload.github.com/skywind3000/codecheck/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skywind3000%2Fcodecheck/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33707328,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-30T02:00:06.278Z","response_time":92,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cpp","online-judge","online-judge-tools","python"],"created_at":"2026-05-30T20:01:24.016Z","updated_at":"2026-05-30T20:01:24.684Z","avatar_url":"https://github.com/skywind3000.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CodeCheck — 注释驱动的本地单元测试工具\n\n![Python](https://img.shields.io/badge/Python-3.x-blue)\n![License](https://img.shields.io/badge/License-MIT-green)\n![Languages](https://img.shields.io/badge/Supports-C%20%7C%20C++%20%7C%20Python-orange)\n\n\u003e 测试数据随代码，告别反复复制粘贴\n\n做 Online Judge 题目时，你是否也在反复做这些事？\n\n- 复制粘贴测试数据到 stdin\n- 手动维护 `input.txt` / `output.txt`\n- 每次改完代码再跑一遍，逐个核对输出\n\nCodeCheck 让测试数据直接写在源代码注释里，一键编译 + 验证，零额外文件。\n\n## 为什么用 CodeCheck？\n\n| 方式 | 操作步骤 | 数据管理 |\n|------|---------|---------|\n| 手动复制粘贴 | 每次运行都复制 | 分散，容易丢 |\n| input.txt 重定向 | 需额外维护文件 | 数据和代码分离 |\n| **CodeCheck** | **一条命令** | **数据就在代码里** |\n\n## Quick Start\n\n安装：\n\n```bash\n# 无需安装，直接运行\npython codecheck.py hello.c\n```\n\n编写一个带嵌入式测试的 C 程序：\n\n```c\n#include \u003cstdio.h\u003e\n\nint main() {\n    int a, b;\n    scanf(\"%d%d\", \u0026a, \u0026b);\n    printf(\"%d\\n\", a + b);\n    return 0;\n}\n\n// @input: test1\n// 10 20\n// @output:\n// 30\n\n// @input: test2\n// 5 7\n// @output:\n// 12\n```\n\n运行和验证：\n\n```bash\n# 编译并运行（默认模式，不比对输出）\npython codecheck.py hello.c\n\n# 验证所有测试用例\npython codecheck.py -c hello.c\n\n# 只验证第1个测试用例\npython codecheck.py -c -1 hello.c\n\n# 调试模式：用 @input 作为 stdin 运行，直接显示输出而不比对\npython codecheck.py -d hello.c\n\n# 调试第2个测试用例\npython codecheck.py -d -2 hello.c\n```\n\n样例输出：\n\n```\nCompiling hello.c ...\n[1/2] Running unit test: test1 ... PASS\n[2/2] Running unit test: test2 ... PASS\n[result] All 2 unit tests passed!\n```\n\n这是 `-c` 命令的运行结果，首先检测是否需要编译（源代码比可执行新），然后用多组测试数据来验证程序是否输出满足预期。\n\n## 运行模式\n\n| 模式 | 选项 | 说明 |\n|------|------|------|\n| **start** | （默认） | 编译并运行，不做测试验证 |\n| **debug** | `-d` | 用 `@input` 作为 stdin 运行，直接显示输出内容而不对比 |\n| **check** | `-c` | 逐个运行测试用例，比对实际输出与 `@output` |\n\n## 测试指令\n\n在源代码注释中嵌入以下指令：\n\n### `@input` — 定义标准输入\n\n指定测试名称及输入数据，后续连续注释行作为 stdin 内容：\n\n```c\n// @input: test1\n// 10 20\n```\n\nPython 中使用 `#` 注释：\n\n```python\n# @input: test1\n# 10 20\n```\n\n也可以不给名称，自动命名为 `test1`、`test2` ...：\n\n```c\n// @input:\n// 10 20\n```\n\n### `@output` — 定义预期输出\n\n紧接 `@input` 后的连续注释行作为预期输出：\n\n```c\n// @input: test1\n// 10 20\n// @output:\n// 30\n```\n\n### `@args` — 定义命令行参数\n\n为程序指定命令行参数：\n\n```c\n// @args: --verbose --count=10\n```\n\n使用 `-a` 选项运行：\n\n```bash\npython codecheck.py -a hello.c\n```\n\n### `@timeout` — 设置超时（秒）\n\n```c\n// @input: slow_test timeout=5\n// 100000\n// @output:\n// done\n// @timeout: 5\n```\n\n也支持在 `@input` 名称后用 `key=value` 指定：\n\n```c\n// @input: slow_test timeout=5\n```\n\n## 支持的语言\n\n| 语言 | 扩展名 | 处理方式 | 注释格式 |\n|------|--------|----------|----------|\n| C | `.c` | 编译后运行 | `//` 和 `/* */` |\n| C++ | `.cpp`, `.cc`, `.cxx` | 编译后运行 | `//` 和 `/* */` |\n| Python | `.py`, `.pyw` | 直接运行 | `#` 和 `\"\"\"` |\n\n## IDE 集成\n\n### Dev-C++ 一键运行\n\n1. 打开 Dev-C++，菜单 **工具 → 配置工具**\n2. 添加一个新工具：\n   - **标题**：CodeCheck 验证\n   - **程序**：`python`（或 `python3`）\n   - **参数**：`codecheck.py -c \"$(FILENAME)\"`\n   - **工作目录**：`$(DIRECTORY)`\n3. 保存后即可在 Dev-C++ 中一键运行验证\n\n\u003e 提示：将 `codecheck.py` 放到 PATH 环境变量中，或填写完整路径。\n\n## 完整示例\n\n### C 语言\n\n```c\n#include \u003cstdio.h\u003e\n\n// @input: add_two_numbers\n// 10 20\n// @output:\n// 30\n\n// @input: another_case\n// 5 7\n// @output:\n// 12\n\nint main() {\n    int a, b;\n    scanf(\"%d%d\", \u0026a, \u0026b);\n    printf(\"%d\\n\", a + b);\n    return 0;\n}\n```\n\n### Python\n\n```python\n# @input: add_two_numbers\n# 10 20\n# @output:\n# 30\n\n# @input: another_case\n# 5 7\n# @output:\n# 12\n\na, b = map(int, input().split())\nprint(a + b)\n```\n\n### 多行注释中的测试（C/C++）\n\n```c\n/*\n@input: block_test\n5 7\n\n@output:\n12\n*/\n```\n\n## 命令行选项\n\n```\nUsage: python codecheck.py [options] \u003csource-file\u003e\n\n  -h, --help     显示帮助信息\n  -c, --check    验证嵌入式单元测试的输出\n  -d, --debug    调试模式运行（不比对输出）\n  -a, --args     使用 @args 指定的命令行参数运行\n  -{num}         选择指定测试用例（1-based，配合 -c/-d 使用）\n```\n\n## 注释提取细节\n\n- C/C++：正确识别 `//` 单行注释和 `/* */` 多行注释，忽略字符串内的注释符号\n- Python：正确识别 `#` 注释，忽略字符串（包括三引号字符串、raw string、f-string、byte string）内的 `#` 符号\n- 测试数据必须连续排列在指令后面，中间如果有其他注释或代码行则会中断数据收集\n\n## 配置文件\n\n配置文件路径：`~/.config/codecheck.ini`\n\n```ini\n[default]\ncc = /usr/bin/gcc          # C/C++ 编译器路径\npython = /usr/bin/python3  # Python 解释器路径\nflags = -O2 -g -Wall       # 默认编译选项\ncflags = ...               # C 专用编译选项\ncxxflags = ...             # C++ 专用编译选项\nldflags = ...              # 链接选项\ntimeout = 10               # 默认超时时间（秒）\n```\n\n如果不指定 `flags`，编译时默认使用 `-O2 -g -Wall -lm`。\n\n编译时会自动定义宏 `_CODECHECK=1`，可用于区分本地调试和正式提交：\n\n```c\n#ifdef _CODECHECK\n    // 本地调试专用代码\n#endif\n```\n\n## 许可证\n\n[MIT License](LICENSE) © skywind3000","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskywind3000%2Fcodecheck","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskywind3000%2Fcodecheck","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskywind3000%2Fcodecheck/lists"}