diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/tests/statusline-command.bats | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/tests/statusline-command.bats b/scripts/tests/statusline-command.bats new file mode 100644 index 0000000..6a8725a --- /dev/null +++ b/scripts/tests/statusline-command.bats @@ -0,0 +1,51 @@ +#!/usr/bin/env bats +# .claude/statusline-command.sh — Claude Code status line mirroring the zsh +# prompt: [yy-mm-dd HH:MM:SS] user host:~/path on <branch> + +setup() { + REPO_ROOT="$(cd "$(dirname "$BATS_TEST_FILENAME")/../.." && pwd)" + SCRIPT="$REPO_ROOT/.claude/statusline-command.sh" + TMPDIR_T="$(mktemp -d)" +} + +teardown() { + rm -rf "$TMPDIR_T" +} + +run_statusline() { + printf '{"cwd":"%s"}' "$1" | sh "$SCRIPT" +} + +@test "statusline renders date, user, host, and tilde-abbreviated cwd" { + dir="$HOME/.cache" + run run_statusline "$dir" + [ "$status" -eq 0 ] + host="$(uname -n)" + user="$(whoami)" + [[ "$output" =~ ^\[[0-9]{2}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}\]\ $user\ $host:~/\.cache$ ]] +} + +@test "statusline appends the git branch inside a repo" { + git -C "$TMPDIR_T" init -q -b trunk + run run_statusline "$TMPDIR_T" + [ "$status" -eq 0 ] + [[ "$output" == *" on trunk" ]] +} + +@test "statusline omits the branch part outside a git repo" { + mkdir -p "$TMPDIR_T/plain" + run run_statusline "$TMPDIR_T/plain" + [ "$status" -eq 0 ] + [[ "$output" != *" on "* ]] +} + +@test "statusline leaves a cwd outside HOME unabbreviated" { + run run_statusline "/tmp" + [ "$status" -eq 0 ] + [[ "$output" == *":/tmp" ]] +} + +@test "statusline emits no stderr noise" { + err="$(printf '{"cwd":"%s"}' "$HOME" | sh "$SCRIPT" 2>&1 >/dev/null)" + [ -z "$err" ] +} |
