Files
Shuery 0df07ad0ae refactor: 迁移至 bashly CLI 与功能域模块结构
- CLI 定义迁移至 src/bashly.yml(bashly 1.4 生成参数解析),入口收敛为 src/root_command.sh
- 源码按功能域重组:config/storage/integrate/media/pipeline,消除扁平散落
- 新增零依赖测试框架 tests/(123 用例)与 CI 流水线(lint + test + build + 产物一致性)
- build.sh 支持版本单一来源注入与 --check 产物校验;新增 lint.sh(bash -n + shellcheck 零容忍)
- 删除旧单文件 media_organizer.sh 与旧扁平模块
2026-08-14 22:41:28 +08:00

88 lines
2.4 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# shellcheck shell=bash
# ============================================================================
# 轻量断言库(tests/run.sh 在每个用例文件的子 shell 中 source)
# 所有断言失败时打印诊断并返回非 0;测试函数应直接调用并以其返回值作为结果。
# ============================================================================
# 断言两值相等。用法:assert_eq <期望值> <实际值> [描述]
assert_eq() {
local expected="$1" actual="$2" msg="${3:-}"
if [[ "$expected" == "$actual" ]]; then
return 0
fi
echo " ✗ assert_eq${msg:+($msg)}" >&2
echo " 期望: [$expected]" >&2
echo " 实际: [$actual]" >&2
return 1
}
# 断言字符串包含子串。用法:assert_contains <字符串> <子串> [描述]
assert_contains() {
local haystack="$1" needle="$2" msg="${3:-}"
if [[ "$haystack" == *"$needle"* ]]; then
return 0
fi
echo " ✗ assert_contains${msg:+($msg)}" >&2
echo " 字符串: [$haystack]" >&2
echo " 子串: [$needle]" >&2
return 1
}
# 断言字符串为空。用法:assert_empty <字符串> [描述]
assert_empty() {
local val="$1" msg="${2:-}"
if [[ -z "$val" ]]; then
return 0
fi
echo " ✗ assert_empty${msg:+($msg)}:实际为 [$val]" >&2
return 1
}
# 断言字符串非空。用法:assert_not_empty <字符串> [描述]
assert_not_empty() {
local val="$1" msg="${2:-}"
if [[ -n "$val" ]]; then
return 0
fi
echo " ✗ assert_not_empty${msg:+($msg)}:实际为空" >&2
return 1
}
# 断言命令成功。用法:assert_success <命令...>
assert_success() {
if "$@"; then
return 0
fi
echo " ✗ assert_success:命令失败:$*" >&2
return 1
}
# 断言命令失败(返回非 0)。用法:assert_failure <命令...>
assert_failure() {
if "$@"; then
echo " ✗ assert_failure:命令意外成功:$*" >&2
return 1
fi
return 0
}
# 断言文件存在。用法:assert_file_exists <路径> [描述]
assert_file_exists() {
local path="$1" msg="${2:-}"
if [[ -f "$path" ]]; then
return 0
fi
echo " ✗ assert_file_exists${msg:+($msg)}:$path 不存在" >&2
return 1
}
# 断言文件不存在。用法:assert_file_absent <路径> [描述]
assert_file_absent() {
local path="$1" msg="${2:-}"
if [[ ! -e "$path" ]]; then
return 0
fi
echo " ✗ assert_file_absent${msg:+($msg)}:$path 意外存在" >&2
return 1
}