Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,13 @@ Any single folder can be copied out and still work standalone.
npm test # bats --recursive . (every */test.bats)
bats validate-json/test.bats # a single script's tests
```

Each `test.bats` is a behavioral suite, not just a syntax check: it exercises
the script's documented options and arguments, `-h`/help output, error paths
(missing/invalid arguments, running outside a git repo where relevant), and
success paths against a throwaway git repo or temp directory created in
`setup()`/`teardown()` (via `tests/helpers.bash`). Suites are hermetic — no
network access and no writes outside a temp dir — except where a script's own
purpose requires reaching a real tool (e.g. `zz_npx`/`zz_update` fall back to
a local fixture and assert no network call is made). 417 tests currently pass
across all 53 script folders.
8 changes: 8 additions & 0 deletions configure-feature/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ Declared via `zz_use` at the top of `run.sh` and resolved on demand
```sh
bats test.bats
```

- help/usage output and exit code
- errors without a feature argument, or when source doesn't exist
- copies a new plain-text stub, merges a json stub into an existing file
- reconciles a text fragment additively into an existing file
- strips leading `_` prefix and `.gitignore`s `#`-prefixed stub destinations
- preserves executable bits and symlinks stub targets
- runs `configure-*.sh` scripts only from the repo top level
132 changes: 132 additions & 0 deletions configure-feature/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,145 @@ load ../tests/helpers.bash

setup() {
setup_scripts_path
WORK_DIR=$(mktemp -d)
cd "$WORK_DIR" || exit 1
git init -q
git config user.email "test@example.com"
git config user.name "Test"
git config commit.gpgsign false
git commit -q --allow-empty -m "init"
}

teardown() {
cd /
rm -rf "$WORK_DIR"
teardown_scripts_path
}

@test "configure-feature is installed on PATH and syntactically valid" {
command -v configure-feature
run sh -n "$BATS_TEST_DIRNAME/run.sh"
[ "$status" -eq 0 ]
}

@test "configure-feature -h prints usage and exits non-zero" {
run configure-feature -h
[ "$status" -ne 0 ]
[[ "$output" == *"Usage:"* ]]
}

@test "configure-feature errors without a feature argument" {
run configure-feature
[ "$status" -ne 0 ]
}

@test "configure-feature errors when the source directory does not exist" {
run configure-feature -s "$WORK_DIR/nonexistent" myfeature
[ "$status" -ne 0 ]
[[ "$output" == *"does not exist"* ]]
}

@test "configure-feature copies a new plain-text stub file into the cwd" {
mkdir -p src/stubs
echo "line1" >src/stubs/plain.txt
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ -f "$WORK_DIR/plain.txt" ]
grep -q line1 "$WORK_DIR/plain.txt"
}

@test "configure-feature merges a json stub into an existing json file" {
mkdir -p src/stubs
echo '{"b":2}' >src/stubs/config.json
echo '{"a":1}' >config.json
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
result=$(cat config.json)
[[ "$result" == *'"a"'* ]]
[[ "$result" == *'"b"'* ]]
}

@test "configure-feature copies a json stub as-is when destination doesn't exist" {
mkdir -p src/stubs
echo '{"a":1}' >src/stubs/newfile.json
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ -f newfile.json ]
grep -q '"a"' newfile.json
}

@test "configure-feature reconciles a fragment additively into an existing plain-text file" {
mkdir -p src/stubs
printf 'line1\nline2\n' >src/stubs/frag.txt
printf 'existing1\n' >frag.txt

run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
grep -q existing1 frag.txt
grep -q line1 frag.txt
grep -q line2 frag.txt
}

@test "configure-feature strips a leading underscore prefix from stub filenames" {
mkdir -p src/stubs
echo "content" >src/stubs/_prefix.actual.txt
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ -f actual.txt ]
[ ! -f _prefix.actual.txt ]
}

@test "configure-feature adds hash-prefixed stub destinations to .gitignore" {
mkdir -p src/stubs
echo "secretcontent" >'src/stubs/#ignored.txt'
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ -f ignored.txt ]
grep -qxF "./ignored.txt" .gitignore
}

@test "configure-feature preserves executable permission bits from stub source" {
mkdir -p src/stubs
printf '#!/bin/sh\necho hi\n' >src/stubs/exec.sh
chmod 755 src/stubs/exec.sh
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ -x exec.sh ]
}

@test "configure-feature deploys stub symlinks when the destination doesn't already exist" {
mkdir -p src/stubs
echo "target-content" >src/stubs/real.txt
ln -s real.txt src/stubs/linked.txt
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ -L linked.txt ]
}

@test "configure-feature runs configure-*.sh scripts from source when at repo top level" {
cat >src-configure.sh <<'EOF'
EOF
mkdir -p src
cat >"src/configure-thing.sh" <<EOF
#!/bin/sh
touch "$WORK_DIR/configure-ran.txt"
EOF
chmod +x src/configure-thing.sh
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ -f "$WORK_DIR/configure-ran.txt" ]
}

@test "configure-feature skips configure-*.sh scripts when not at repo top level" {
mkdir -p src sub
cat >"src/configure-thing.sh" <<EOF
#!/bin/sh
touch "$WORK_DIR/configure-ran-sub.txt"
EOF
chmod +x src/configure-thing.sh
cd sub
run configure-feature -s "$WORK_DIR/src" myfeature
[ "$status" -eq 0 ]
[ ! -f "$WORK_DIR/configure-ran-sub.txt" ]
[[ "$output" == *"Not in top level directory"* ]]
}
8 changes: 8 additions & 0 deletions distribute-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ Declared via `zz_use` at the top of `run.sh` and resolved on demand
```sh
bats test.bats
```

- help/usage output and exit code
- errors without a target, quiet no-op with `-q`
- errors when resolved target directory doesn't exist
- resolves target from `.zz_dist` and from `package.json` config
- no-op success when the source directory doesn't exist
- copies executable `zz_*` files, stripping `_` prefix and `.sh` suffix
- skips non-executable `zz_*` files, makes copies executable in target
81 changes: 81 additions & 0 deletions distribute-utils/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,99 @@ load ../tests/helpers.bash

setup() {
setup_scripts_path
WORK_DIR=$(mktemp -d)
cd "$WORK_DIR" || exit 1
}

teardown() {
cd /
rm -rf "$WORK_DIR"
teardown_scripts_path
}

@test "distribute-utils is installed on PATH and syntactically valid" {
command -v distribute-utils
run sh -n "$BATS_TEST_DIRNAME/run.sh"
[ "$status" -eq 0 ]
}

@test "distribute-utils -h prints usage and exits non-zero" {
run distribute-utils -h
[ "$status" -ne 0 ]
[[ "$output" == *"Usage:"* ]]
}

@test "distribute-utils errors without a target directory" {
run distribute-utils
[ "$status" -ne 0 ]
[[ "$output" == *"No target directory"* ]]
}

@test "distribute-utils exits quietly with -q and no target" {
run distribute-utils -q
[ "$status" -eq 0 ]
}

@test "distribute-utils errors when the resolved target directory doesn't exist" {
run distribute-utils -t "$WORK_DIR/does-not-exist"
[ "$status" -ne 0 ]
[[ "$output" == *"does not exist"* ]]
}

@test "distribute-utils reads target from .zz_dist when -t is not given" {
mkdir -p target src
echo "$WORK_DIR/target" >.zz_dist
touch src/zz_foo.sh && chmod +x src/zz_foo.sh
run distribute-utils -s "$WORK_DIR/src"
[ "$status" -eq 0 ]
[ -f "$WORK_DIR/target/zz_foo.sh" ]
}

@test "distribute-utils reads target from package.json config.zz_dist" {
mkdir -p target src
cat >package.json <<EOF
{"config": {"zz_dist": "$WORK_DIR/target"}}
EOF
touch src/zz_foo.sh && chmod +x src/zz_foo.sh
run distribute-utils -s "$WORK_DIR/src"
[ "$status" -eq 0 ]
[ -f "$WORK_DIR/target/zz_foo.sh" ]
}

@test "distribute-utils succeeds as a no-op when the given source directory does not exist" {
mkdir -p target
run distribute-utils -t "$WORK_DIR/target" -s "$WORK_DIR/nonexistent-source"
[ "$status" -eq 0 ]
[ -z "$(ls -A "$WORK_DIR/target")" ]
}

@test "distribute-utils copies executable zz_* files, stripping the leading underscore and .sh suffix from _zz_*.sh files" {
mkdir -p target src
echo '#!/bin/sh' >src/zz_plain.sh
chmod +x src/zz_plain.sh
echo '#!/bin/sh' >src/_zz_hidden.sh
chmod +x src/_zz_hidden.sh
run distribute-utils -t "$WORK_DIR/target" -s "$WORK_DIR/src"
[ "$status" -eq 0 ]
[ -f "$WORK_DIR/target/zz_plain.sh" ]
[ -f "$WORK_DIR/target/zz_hidden" ]
[ ! -f "$WORK_DIR/target/_zz_hidden.sh" ]
}

@test "distribute-utils skips non-executable zz_* files" {
mkdir -p target src
echo '#!/bin/sh' >src/zz_noexec.sh
chmod -x src/zz_noexec.sh
run distribute-utils -t "$WORK_DIR/target" -s "$WORK_DIR/src"
[ "$status" -eq 0 ]
[ ! -f "$WORK_DIR/target/zz_noexec.sh" ]
}

@test "distribute-utils makes copied files executable in the target" {
mkdir -p target src
echo '#!/bin/sh' >src/zz_exec.sh
chmod +x src/zz_exec.sh
run distribute-utils -t "$WORK_DIR/target" -s "$WORK_DIR/src"
[ "$status" -eq 0 ]
[ -x "$WORK_DIR/target/zz_exec.sh" ]
}
5 changes: 5 additions & 0 deletions edit-script/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ Declared via `zz_use` at the top of `run.sh` and resolved on demand
```sh
bats test.bats
```

- help/usage output and exit code
- errors without a script argument
- fails when the script isn't installed in `/usr/local/bin`
- copies an installed script locally, makes it executable, and opens it
46 changes: 46 additions & 0 deletions edit-script/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,59 @@ load ../tests/helpers.bash

setup() {
setup_scripts_path
WORK_DIR=$(mktemp -d)
cd "$WORK_DIR" || exit 1
}

teardown() {
cd /
rm -rf "$WORK_DIR"
teardown_scripts_path
}

@test "edit-script is installed on PATH and syntactically valid" {
command -v edit-script
run sh -n "$BATS_TEST_DIRNAME/run.sh"
[ "$status" -eq 0 ]
}

@test "edit-script -h prints usage and exits non-zero" {
run edit-script -h
[ "$status" -ne 0 ]
[[ "$output" == *"Usage:"* ]]
}

@test "edit-script errors without a script argument" {
run edit-script
[ "$status" -ne 0 ]
}

@test "edit-script fails when the script isn't installed in /usr/local/bin" {
run edit-script definitely-not-installed-xyz
[ "$status" -ne 0 ]
[[ "$output" == *"not defined"* ]]
}

@test "edit-script copies an installed script locally, makes it executable, and opens it" {
if [ ! -w /usr/local/bin ]; then
skip "/usr/local/bin not writable in this environment"
fi
fake=/usr/local/bin/zz_test_edit_script_$$
printf '#!/bin/sh\necho hi\n' >"$fake"
chmod +x "$fake"

# stub `code` (the editor invoked at the end of run.sh) so it's a no-op
stub_dir=$(mktemp -d)
printf '#!/bin/sh\nexit 0\n' >"$stub_dir/code"
chmod +x "$stub_dir/code"

name=$(basename "$fake")
run env PATH="$stub_dir:$PATH" edit-script "$name"

rm -f "$fake"
rm -rf "$stub_dir"

[ "$status" -eq 0 ]
[ -f "$WORK_DIR/$name" ]
[ -x "$WORK_DIR/$name" ]
}
6 changes: 6 additions & 0 deletions git-align/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ Declared via `zz_use` at the top of `run.sh` and resolved on demand
```sh
bats test.bats
```

- fails cleanly outside a git repository
- with no remote configured, logs a failure and leaves branch/history intact
- aligns the current branch to a newer remote commit, restoring stashed local edits
- preserves the branch name and leaves no leftover temp/stash branch
- aligns cleanly when there are no uncommitted changes to stash/pop
Loading
Loading