Files
CleanMM/tests/cli.bats

53 lines
1.3 KiB
Plaintext
Raw Normal View History

2025-10-12 14:17:40 +08:00
#!/usr/bin/env bats
setup_file() {
2025-10-12 20:49:10 +08:00
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
export PROJECT_ROOT
2025-10-12 14:17:40 +08:00
2025-10-12 20:49:10 +08:00
ORIGINAL_HOME="${HOME:-}"
export ORIGINAL_HOME
2025-10-12 14:17:40 +08:00
2025-10-12 20:49:10 +08:00
HOME="$(mktemp -d "${BATS_TEST_DIRNAME}/tmp-cli-home.XXXXXX")"
export HOME
2025-10-12 14:17:40 +08:00
2025-10-12 20:49:10 +08:00
mkdir -p "$HOME"
2025-10-12 14:17:40 +08:00
}
teardown_file() {
2025-10-12 20:49:10 +08:00
rm -rf "$HOME"
if [[ -n "${ORIGINAL_HOME:-}" ]]; then
export HOME="$ORIGINAL_HOME"
fi
2025-10-12 14:17:40 +08:00
}
setup() {
2025-10-12 20:49:10 +08:00
rm -rf "$HOME/.config"
mkdir -p "$HOME"
2025-10-12 14:17:40 +08:00
}
@test "mole --help prints command overview" {
2025-10-12 20:49:10 +08:00
run env HOME="$HOME" "$PROJECT_ROOT/mole" --help
[ "$status" -eq 0 ]
[[ "$output" == *"mo clean"* ]]
[[ "$output" == *"mo analyze"* ]]
2025-10-12 14:17:40 +08:00
}
@test "mole --version reports script version" {
2025-10-12 20:49:10 +08:00
expected_version="$(grep '^VERSION=' "$PROJECT_ROOT/mole" | head -1 | sed 's/VERSION=\"\(.*\)\"/\1/')"
run env HOME="$HOME" "$PROJECT_ROOT/mole" --version
[ "$status" -eq 0 ]
[[ "$output" == *"$expected_version"* ]]
2025-10-12 14:17:40 +08:00
}
@test "mole unknown command returns error" {
2025-10-12 20:49:10 +08:00
run env HOME="$HOME" "$PROJECT_ROOT/mole" unknown-command
[ "$status" -ne 0 ]
[[ "$output" == *"Unknown command: unknown-command"* ]]
2025-10-12 14:17:40 +08:00
}
@test "touchid status reports current configuration" {
2025-10-12 20:49:10 +08:00
run env HOME="$HOME" "$PROJECT_ROOT/mole" touchid status
[ "$status" -eq 0 ]
[[ "$output" == *"Touch ID"* ]]
2025-10-12 14:17:40 +08:00
}