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
16 changes: 16 additions & 0 deletions tests/clean-branches.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ setup() {
# feature/keep: current branch (also no upstream, but we must not delete it).
git -C "$LOCAL_DIR" checkout -q -b feature/keep

# build/1.0: pushed to origin so -T can delete it from both sides.
git -C "$LOCAL_DIR" tag build/1.0
git -C "$LOCAL_DIR" push -q origin build/1.0

# v0.1.0: local-only tag that -T must leave untouched.
git -C "$LOCAL_DIR" tag v0.1.0

export ORIGIN_DIR LOCAL_DIR CLEAN
}

Expand Down Expand Up @@ -65,3 +72,12 @@ teardown() {
[[ "$branches" != *"feature/gone"* ]]
[[ "$branches" != *"feature/no-upstream"* ]]
}

@test "-T flag deletes build/* tags and preserves non-build tags" {
run "$CLEAN" -d "$LOCAL_DIR" -T -v -v
[ "$status" -eq 0 ]
build_tags=$(git -C "$LOCAL_DIR" tag -l 'build/*')
[ -z "$build_tags" ]
v_tags=$(git -C "$LOCAL_DIR" tag -l 'v0.1.0')
[ "$v_tags" = "v0.1.0" ]
}
66 changes: 66 additions & 0 deletions tests/exec.bats
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,69 @@ setup() {
")
[[ "$out" == "OK" ]]
}

@test "exec::hide swallows stdout" {
out=$(bash -c "
LOGFILE_DISABLE=true
source '$REPO_ROOT/bash/includer.sh'
@include exec
exec::hide bash -c 'echo stdout-hidden'
echo visible
")
[[ "$out" == "visible" ]]
[[ "$out" != *"stdout-hidden"* ]]
}

@test "exec::hide swallows stderr" {
out=$(bash -c "
LOGFILE_DISABLE=true
source '$REPO_ROOT/bash/includer.sh'
@include exec
exec::hide bash -c 'echo stderr-hidden >&2'
echo visible
" 2>&1)
[[ "$out" == "visible" ]]
[[ "$out" != *"stderr-hidden"* ]]
}

@test "exec::hide preserves zero exit code" {
run bash -c "
LOGFILE_DISABLE=true
source '$REPO_ROOT/bash/includer.sh'
@include exec
exec::hide true
"
[ "$status" -eq 0 ]
}

@test "exec::hide preserves non-zero exit code" {
run bash -c "
LOGFILE_DISABLE=true
source '$REPO_ROOT/bash/includer.sh'
@include exec
exec::hide bash -c 'exit 7'
"
[ "$status" -eq 7 ]
}

@test "exec_and_hide delegates stdout suppression to exec::hide" {
out=$(bash -c "
LOGFILE_DISABLE=true
source '$REPO_ROOT/bash/includer.sh'
@include exec
exec_and_hide bash -c 'echo stdout-hidden'
echo visible
" 2>/dev/null)
[[ "$out" == "visible" ]]
[[ "$out" != *"stdout-hidden"* ]]
}

@test "exec_and_capture delegates exit code preservation to exec::capture" {
run bash -c "
LOGFILE_DISABLE=true
source '$REPO_ROOT/bash/includer.sh'
@include exec
exec_and_capture bash -c 'exit 3' >/dev/null
"
[ "$status" -eq 3 ]
}
35 changes: 35 additions & 0 deletions tests/git-check.bats
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,38 @@ init_repo() {
echo "$clean" | grep -E 'orgA/repoA[[:space:]].*[[:space:]]branchA[[:space:]]'
echo "$clean" | grep -E 'orgB/repoB[[:space:]].*[[:space:]]branchB[[:space:]]'
}

@test "git-check buckets a repo with uncommitted changes as UNCOMMITTED" {
mkdir -p "$HOME/git/uchk/org"
helpers::make_fixture_repo "$HOME/git/uchk/org/repo" --tagged
# Unstaged modification causes --dirty to append the -dirty suffix.
echo "dirty" >>"$HOME/git/uchk/org/repo/README"

run bash -c "'$GIT_CHECK' -b uchk 2>/dev/null"
clean=$(printf '%s\n' "$output" | sed -E $'s/\x1B\\[[0-9;]*[A-Za-z]//g')
echo "$clean" | grep -E 'org/repo'
echo "$clean" | grep '\-dirty'
}

@test "git-check buckets a clean repo at a tag as RELEASABLE" {
mkdir -p "$HOME/git/rchk/org"
helpers::make_fixture_repo "$HOME/git/rchk/org/repo" --tagged

run bash -c "'$GIT_CHECK' -b rchk 2>/dev/null"
clean=$(printf '%s\n' "$output" | sed -E $'s/\x1B\\[[0-9;]*[A-Za-z]//g')
echo "$clean" | grep -E 'org/repo'
echo "$clean" | grep -E 'v0\.3\.0[[:space:]]'
}

@test "git-check buckets a clean repo ahead of a tag as DEVELOPMENT" {
mkdir -p "$HOME/git/dchk/org"
helpers::make_fixture_repo "$HOME/git/dchk/org/repo" --tagged
echo "extra" >>"$HOME/git/dchk/org/repo/README"
git -C "$HOME/git/dchk/org/repo" add README
git -C "$HOME/git/dchk/org/repo" -c commit.gpgsign=false commit -q -m "feat: extra"

run bash -c "'$GIT_CHECK' -b dchk 2>/dev/null"
clean=$(printf '%s\n' "$output" | sed -E $'s/\x1B\\[[0-9;]*[A-Za-z]//g')
echo "$clean" | grep -E 'org/repo'
echo "$clean" | grep -E 'v0\.3\.0-[0-9]+-g'
}
Loading