1
0
mirror of https://github.com/tw93/Mole.git synced 2026-02-12 01:49:00 +00:00

feat: overhaul quality checks and expand test suite for clean and optimize features

This commit is contained in:
Tw93
2025-12-31 18:13:37 +08:00
parent 1e8ff30fa1
commit 592f02e6e2
45 changed files with 1506 additions and 910 deletions

View File

@@ -1,6 +1,4 @@
#!/usr/bin/env bats
# Regression tests for previously fixed bugs
# Ensures历史bug不再复现
setup() {
PROJECT_ROOT="$(cd "${BATS_TEST_DIRNAME}/.." && pwd)"
@@ -9,12 +7,8 @@ setup() {
mkdir -p "$HOME/.config/mole"
}
# =================================================================
# 退出问题回归测试 (bb21bb1, 4b6c436, d75c34d)
# =================================================================
@test "find with non-existent directory doesn't cause script exit (pipefail bug)" {
# 这个模式曾导致 lib/clean/user.sh 在 pipefail 模式下意外退出
result=$(bash -c '
set -euo pipefail
find /non/existent/dir -name "*.cache" 2>/dev/null || true
@@ -24,7 +18,6 @@ setup() {
}
@test "browser directory check pattern is safe when directories don't exist" {
# 修复模式:先检查目录是否存在
result=$(bash -c '
set -euo pipefail
search_dirs=()
@@ -44,7 +37,6 @@ setup() {
set -euo pipefail
search_dirs=()
# 这不应该执行且不应该报错
if [[ ${#search_dirs[@]} -gt 0 ]]; then
echo "should not reach here"
fi
@@ -53,9 +45,6 @@ setup() {
[[ "$result" == "survived" ]]
}
# ===============================================================
# 更新检查回归测试 (260254f, b61b3f7, 2a64cae, 7a9c946)
# ===============================================================
@test "version comparison works correctly" {
result=$(bash -c '
@@ -92,7 +81,6 @@ setup() {
}
@test "network timeout prevents hanging (simulated)" {
# curl 超时参数应该生效
# shellcheck disable=SC2016
result=$(timeout 5 bash -c '
result=$(curl -fsSL --connect-timeout 1 --max-time 2 "http://192.0.2.1:12345/test" 2>/dev/null || echo "failed")
@@ -113,9 +101,6 @@ setup() {
[[ "$result" == "handled" ]]
}
# ===============================================================
# Pipefail 模式安全模式测试
# ===============================================================
@test "grep with no match doesn't cause exit in pipefail mode" {
result=$(bash -c '
@@ -145,9 +130,6 @@ setup() {
[[ "$result" == "1" ]]
}
# ===============================================================
# 实际场景回归测试
# ===============================================================
@test "safe_remove pattern doesn't fail on non-existent path" {
result=$(bash -c "