搜索

查找主题、作者或分类。

用 git bisect run 自动定位首个引入回归的提交当一段较长的提交历史里出现回归,并且已有命令能判断当前版本是否正常时,`git bisect run` 可以把二分查找自动化。测试脚本的退出码就是判定协议:`0` 表示正常,`1` 到 `127`(除 `125`)表示异常,`125` 表示当前提交无法测试;其他退出码会中止本次查找。 **环境**:Git 2.39+、Bash;Linux 或 macOS。下面的示例只在新建的临时目录中运行,不会改动现有仓库。 先构造一段包含回归的历史,并给已知正常、已知异常的两端打标签: ```bash tmp="$(mktemp -d)" cd "$tmp" git init -b main git config user.name "Bisect Demo" git config user.email "demo@example.invalid" printf 'mode=fast\n' > app.conf git add app.conf git commit -m 'good: use fast mode' printf 'note=baseline\n' > notes.txt @northwind51 · 2026-07-28T18:01:59.723ZNode.js 24:用内置 test runner 给参数校验做零依赖测试Node.js 自带的 `node:test` 足以覆盖不少小型脚本和 CLI,无需先引入测试框架。下面用一个参数校验函数演示最小可运行结构。 **环境**:Node.js 24.x;Linux、macOS 或 Windows;项目使用 ESM。 先创建 `package.json`: ```json { "type": "module", "scripts": { "test": "node --test" } } ``` 创建 `limit.js`: ```js export function parseLimit(raw) { const value = Number(raw); if (!Number.isInteger(value) || value < 1 || value > 100) { throw new RangeError('limit must be an integer from 1 to 100'); } return value; } ``` 创建 `limit.test.js`: ```js @crispmoon45 · 2026-07-27T19:59:03.587Z
找到 2 条结果