[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7F1QNZG43T95MNTHNPZCENQ":3,"skill-same:01M7F1QNZG43T95MNTHNPZCENQ":53},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":14,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":31,"updatedAt":32,"install":33,"resources":46},"01M7F1QNZG43T95MNTHNPZCENQ","bats-testing-patterns",null,"Test shell scripts with bats-core - installation, file layout, run\u002Fstatus\u002Foutput, bats-assert helpers, per-test temp directories, skips, setup_file and CI. Use when writing or fixing tests for a Bash or sh script, adding shell tests to CI, or doing test-first development of a shell utility.","shotcowboystyle\u002Fag-skills","shotcowboystyle","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F62471?v=4","01M7EZTCFCZJ6K3MYW8BPM4X6R","Curtis Blanton","01M7EZTCG1S5M04J90A931X9BX",0,"MIT","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fshell-scripting\u002Fskills\u002Fbats-testing-patterns\u002FSKILL.md",[],[],"2026-11-16 10:05:34",false,"---\nname: bats-testing-patterns\ndescription: Test shell scripts with bats-core - installation, file layout, run\u002Fstatus\u002Foutput, bats-assert helpers, per-test temp directories, skips, setup_file and CI. Use when writing or fixing tests for a Bash or sh script, adding shell tests to CI, or doing test-first development of a shell utility.\nlast_verified: 2026-10-27\n---\n\n# Bats Testing Patterns\n\n[bats-core](https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-core) runs `@test` blocks written in Bash and\nreports results in TAP. Each test runs in its own subshell; a test fails when any command in\nit fails.\n\n## When to Use This Skill\n\n- Writing tests for a shell script or function library\n- Adding shell tests to CI\n- Reproducing a shell bug with a failing test before fixing it\n\n## Install\n\nVendor bats and its helper libraries as git submodules, so every machine and CI runner uses\nthe same versions:\n\n```bash\ngit submodule add https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-core.git test\u002Fbats\ngit submodule add https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-support.git test\u002Ftest_helper\u002Fbats-support\ngit submodule add https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-assert.git test\u002Ftest_helper\u002Fbats-assert\n```\n\nOr install system-wide: `brew install bats-core` or `npm install -g bats`. Either way, the\nhelper libraries are separate.\n\n## Layout\n\n```\nproject\u002F\n├── src\u002F\n│   └── greet.sh\n└── test\u002F\n    ├── bats\u002F                     # submodule\n    ├── test_helper\u002F\n    │   ├── bats-support\u002F         # submodule\n    │   ├── bats-assert\u002F          # submodule\n    │   └── common-setup.bash\n    └── greet.bats\n```\n\n## A Complete Test File\n\n`src\u002Fgreet.sh` under test:\n\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\ngreet() {\n  [[ $# -eq 1 && -n $1 ]] || { printf 'usage: greet NAME\\n' >&2; return 2; }\n  printf 'Hello, %s!\\n' \"$1\"\n}\nif [[ ${BASH_SOURCE[0]} == \"$0\" ]]; then greet \"$@\"; fi\n```\n\nThe last line runs `greet` only when the file is executed, not when a test sources it.\nMake it executable (`chmod +x src\u002Fgreet.sh`) for the \"works as an executable\" test.\n\n`test\u002Ftest_helper\u002Fcommon-setup.bash`:\n\n```bash\n_common_setup() {\n  load 'test_helper\u002Fbats-support\u002Fload'\n  load 'test_helper\u002Fbats-assert\u002Fload'\n  PROJECT_ROOT=\"$(cd \"$BATS_TEST_DIRNAME\u002F..\" && pwd)\"\n  PATH=\"$PROJECT_ROOT\u002Fsrc:$PATH\"\n}\n```\n\n`test\u002Fgreet.bats`:\n\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bats\n\nbats_require_minimum_version 1.5.0\n\nsetup() {\n  load 'test_helper\u002Fcommon-setup'\n  _common_setup\n  source \"$PROJECT_ROOT\u002Fsrc\u002Fgreet.sh\"\n}\n\n@test \"greets by name\" {\n  run greet \"Ada\"\n  assert_success\n  assert_output \"Hello, Ada!\"\n}\n\n@test \"rejects a missing name with exit code 2\" {\n  run -2 --separate-stderr greet\n  assert_output \"\"\n  [[ $stderr == *\"usage: greet NAME\"* ]]\n}\n\n@test \"works as an executable\" {\n  run greet.sh \"Grace\"\n  assert_success\n  assert_line --index 0 \"Hello, Grace!\"\n}\n\n@test \"writes a file in the per-test temp dir\" {\n  greet \"Linus\" >\"$BATS_TEST_TMPDIR\u002Fout.txt\"\n  run cat \"$BATS_TEST_TMPDIR\u002Fout.txt\"\n  assert_output --partial \"Linus\"\n}\n\n@test \"formats JSON when jq is installed\" {\n  command -v jq >\u002Fdev\u002Fnull || skip \"jq not installed\"\n  run jq -n --arg n \"$(greet Ada)\" '$n'\n  assert_success\n}\n```\n\nRun it with `test\u002Fbats\u002Fbin\u002Fbats test\u002F` (or `bats test\u002F` with a system install).\n\n## Core Rules\n\n- **`run` captures, it never fails the test.** After `run cmd`, check `$status`, `$output`\n  and `${lines[@]}` yourself, or with `assert_success`, `assert_failure`, `assert_output`,\n  `assert_line` and `refute_output` from bats-assert.\n- **`run -N cmd`** asserts the exit code is `N`; `run ! cmd` asserts it is non-zero. Both\n  need `bats_require_minimum_version 1.5.0` at the top of the file.\n- **`--separate-stderr`** puts stderr in `$stderr` instead of mixing it into `$output`.\n- **Commands outside `run`** fail the test on a non-zero exit, so plain `[ … ]` and `[[ … ]]`\n  lines are assertions. On Bash older than 4.1 a failing `[[ … ]]` or `(( … ))` in the\n  middle of a test does not fail it; use `[ … ]` or the `assert_*` helpers when that matters.\n- **Temp files go in `$BATS_TEST_TMPDIR`**, a fresh directory per test that bats deletes\n  afterwards. `$BATS_FILE_TMPDIR` is shared by the tests in one file. Do not reassign\n  `TMPDIR`: the code under test and `mktemp` read it.\n- **Skip with `skip \"reason\"`**, inside a test or `setup`. Bats has no conditional-skip helper; write the\n  condition yourself: `command -v jq >\u002Fdev\u002Fnull || skip \"jq not installed\"`.\n- **`setup`\u002F`teardown` run around every test; `setup_file`\u002F`teardown_file` once per file.**\n  Variables from `setup_file` reach tests only if exported.\n- **Pipes need a wrapper**: `run bash -c \"producer | consumer\"`, or `run` a function that\n  contains the pipe. `run producer | consumer` pipes `run`'s own (empty) output.\n\n## Running\n\n```bash\nbats test\u002F                         # every .bats file in the directory\nbats -r test\u002F                      # recurse into subdirectories\nbats --filter 'rejects' test\u002F      # tests whose name matches a regex\nbats --formatter tap test\u002F         # TAP for CI tools\nbats --jobs 4 test\u002F                # parallel; needs GNU parallel installed\nbats --print-output-on-failure test\u002F\n```\n\n## More Patterns\n\n`references\u002Fdetails.md` covers output and file assertions, fixtures, command stubs on\n`PATH`, testing error paths and multiple shells, and CI workflows.\n","# Bats Testing Patterns\n\n[bats-core](https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-core) runs `@test` blocks written in Bash and\nreports results in TAP. Each test runs in its own subshell; a test fails when any command in\nit fails.\n\n## When to Use This Skill\n\n- Writing tests for a shell script or function library\n- Adding shell tests to CI\n- Reproducing a shell bug with a failing test before fixing it\n\n## Install\n\nVendor bats and its helper libraries as git submodules, so every machine and CI runner uses\nthe same versions:\n\n```bash\ngit submodule add https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-core.git test\u002Fbats\ngit submodule add https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-support.git test\u002Ftest_helper\u002Fbats-support\ngit submodule add https:\u002F\u002Fgithub.com\u002Fbats-core\u002Fbats-assert.git test\u002Ftest_helper\u002Fbats-assert\n```\n\nOr install system-wide: `brew install bats-core` or `npm install -g bats`. Either way, the\nhelper libraries are separate.\n\n## Layout\n\n```\nproject\u002F\n├── src\u002F\n│   └── greet.sh\n└── test\u002F\n    ├── bats\u002F                     # submodule\n    ├── test_helper\u002F\n    │   ├── bats-support\u002F         # submodule\n    │   ├── bats-assert\u002F          # submodule\n    │   └── common-setup.bash\n    └── greet.bats\n```\n\n## A Complete Test File\n\n`src\u002Fgreet.sh` under test:\n\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\ngreet() {\n  [[ $# -eq 1 && -n $1 ]] || { printf 'usage: greet NAME\\n' >&2; return 2; }\n  printf 'Hello, %s!\\n' \"$1\"\n}\nif [[ ${BASH_SOURCE[0]} == \"$0\" ]]; then greet \"$@\"; fi\n```\n\nThe last line runs `greet` only when the file is executed, not when a test sources it.\nMake it executable (`chmod +x src\u002Fgreet.sh`) for the \"works as an executable\" test.\n\n`test\u002Ftest_helper\u002Fcommon-setup.bash`:\n\n```bash\n_common_setup() {\n  load 'test_helper\u002Fbats-support\u002Fload'\n  load 'test_helper\u002Fbats-assert\u002Fload'\n  PROJECT_ROOT=\"$(cd \"$BATS_TEST_DIRNAME\u002F..\" && pwd)\"\n  PATH=\"$PROJECT_ROOT\u002Fsrc:$PATH\"\n}\n```\n\n`test\u002Fgreet.bats`:\n\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bats\n\nbats_require_minimum_version 1.5.0\n\nsetup() {\n  load 'test_helper\u002Fcommon-setup'\n  _common_setup\n  source \"$PROJECT_ROOT\u002Fsrc\u002Fgreet.sh\"\n}\n\n@test \"greets by name\" {\n  run greet \"Ada\"\n  assert_success\n  assert_output \"Hello, Ada!\"\n}\n\n@test \"rejects a missing name with exit code 2\" {\n  run -2 --separate-stderr greet\n  assert_output \"\"\n  [[ $stderr == *\"usage: greet NAME\"* ]]\n}\n\n@test \"works as an executable\" {\n  run greet.sh \"Grace\"\n  assert_success\n  assert_line --index 0 \"Hello, Grace!\"\n}\n\n@test \"writes a file in the per-test temp dir\" {\n  greet \"Linus\" >\"$BATS_TEST_TMPDIR\u002Fout.txt\"\n  run cat \"$BATS_TEST_TMPDIR\u002Fout.txt\"\n  assert_output --partial \"Linus\"\n}\n\n@test \"formats JSON when jq is installed\" {\n  command -v jq >\u002Fdev\u002Fnull || skip \"jq not installed\"\n  run jq -n --arg n \"$(greet Ada)\" '$n'\n  assert_success\n}\n```\n\nRun it with `test\u002Fbats\u002Fbin\u002Fbats test\u002F` (or `bats test\u002F` with a system install).\n\n## Core Rules\n\n- **`run` captures, it never fails the test.** After `run cmd`, check `$status`, `$output`\n  and `${lines[@]}` yourself, or with `assert_success`, `assert_failure`, `assert_output`,\n  `assert_line` and `refute_output` from bats-assert.\n- **`run -N cmd`** asserts the exit code is `N`; `run ! cmd` asserts it is non-zero. Both\n  need `bats_require_minimum_version 1.5.0` at the top of the file.\n- **`--separate-stderr`** puts stderr in `$stderr` instead of mixing it into `$output`.\n- **Commands outside `run`** fail the test on a non-zero exit, so plain `[ … ]` and `[[ … ]]`\n  lines are assertions. On Bash older than 4.1 a failing `[[ … ]]` or `(( … ))` in the\n  middle of a test does not fail it; use `[ … ]` or the `assert_*` helpers when that matters.\n- **Temp files go in `$BATS_TEST_TMPDIR`**, a fresh directory per test that bats deletes\n  afterwards. `$BATS_FILE_TMPDIR` is shared by the tests in one file. Do not reassign\n  `TMPDIR`: the code under test and `mktemp` read it.\n- **Skip with `skip \"reason\"`**, inside a test or `setup`. Bats has no conditional-skip helper; write the\n  condition yourself: `command -v jq >\u002Fdev\u002Fnull || skip \"jq not installed\"`.\n- **`setup`\u002F`teardown` run around every test; `setup_file`\u002F`teardown_file` once per file.**\n  Variables from `setup_file` reach tests only if exported.\n- **Pipes need a wrapper**: `run bash -c \"producer | consumer\"`, or `run` a function that\n  contains the pipe. `run producer | consumer` pipes `run`'s own (empty) output.\n\n## Running\n\n```bash\nbats test\u002F                         # every .bats file in the directory\nbats -r test\u002F                      # recurse into subdirectories\nbats --filter 'rejects' test\u002F      # tests whose name matches a regex\nbats --formatter tap test\u002F         # TAP for CI tools\nbats --jobs 4 test\u002F                # parallel; needs GNU parallel installed\nbats --print-output-on-failure test\u002F\n```\n\n## More Patterns\n\n`references\u002Fdetails.md` covers output and file assertions, fixtures, command stubs on\n`PATH`, testing error paths and multiple shells, and CI workflows.\n",{"name":5,"description":7,"last_verified":24},1793059200000,"main","f846d9a97082ff30d613b55a085cef425d822473","plugins\u002Fshell-scripting\u002Fskills\u002Fbats-testing-patterns","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle","https:\u002F\u002Fshotcowboystyle.github.io","Building smarter with AI, automation & modern tools. Exploring how far one person can go without a big team using today’s AI.","2026-11-10 04:58:27",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add shotcowboystyle\u002Fag-skills --skill bats-testing-patterns",{"tool":39,"command":40},"bunx","bunx skills add shotcowboystyle\u002Fag-skills --skill bats-testing-patterns",{"tool":42,"command":43},"pnpm","pnpm dlx skills add shotcowboystyle\u002Fag-skills --skill bats-testing-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fshell-scripting\u002Fskills\u002Fbats-testing-patterns\u002FSKILL.md",true,[47],{"path":48,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":51,"sourceHtmlUrl":52},"references\u002Fdetails.md","REFERENCE","参考文档",8106,"https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Fplugins\u002Fshell-scripting\u002Fskills\u002Fbats-testing-patterns\u002Freferences\u002Fdetails.md",[54,60,67,74,81,88],{"skillNo":55,"name":56,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M7F1YRY5S5QRJ1V0BJS130QX","no-description","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fno-description\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M7F1Y9BV2FJNQJ3NB32JS5CM","good-skill","Fixture skill that satisfies every rule.","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fgood-skill\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M7F1XXBQ3NQRXZSS0KAGAR9V","broken-link","Links to a reference file that does not exist.","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fbroken-link\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M7F1XBX4R46NR9W0HXQ7XCDX","Bad_Name","Name violates the kebab-case rule and does not match the directory.","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Ftests\u002Ffixtures\u002Fbad-name\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M7F1WNAF8WNEQ7S5HKT5VK0D","skill-authoring","Write, review, and validate portable agent skills in SKILL.md format. Use when creating a new skill, editing an existing one, or asked whether a skill follows the Agent Skills spec.","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Fskills\u002Fskill-authoring\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":19},"01M7F1W30TC0XFNSF7YBRGETK2","weigh-bags","Record scale readings for each bag — empty (tare), outbound, current, final — and reconcile them against the itemised inventory to find unaccounted weight. Use when the user gives a bag weight, says how heavy something is, weighs their luggage, or asks how close to the limit they are. Appends to bags.yaml and runs scripts\u002Freconcile.py.","https:\u002F\u002Fgithub.com\u002Fshotcowboystyle\u002Fag-skills\u002Fblob\u002Fmain\u002Fplugins\u002Ftravel-packing-assistant\u002Fskills\u002Fweigh-bags\u002FSKILL.md",[],[]]