arm-ka-docs/scripts/test_sync_statements.sh

105 lines
4.6 KiB
Bash
Executable File
Raw 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.

#!/usr/bin/env bash
# Тест sync-statements.sh на синтетических репозиториях (bare origin + клон), без tea и сети.
# Разделы: помощник statements_check.py; дальше — сценарии самого скрипта (дописываются по задачам плана).
# Запуск: make test-sync-statements (или напрямую из корня docs; интерпретатор — STATEMENTS_PY, по умолчанию python3).
set -euo pipefail
HERE="$(cd "$(dirname "$0")" && pwd)"
PY=${STATEMENTS_PY:-python3}
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
export GIT_AUTHOR_NAME=t GIT_AUTHOR_EMAIL=t@t GIT_COMMITTER_NAME=t GIT_COMMITTER_EMAIL=t@t
if ! "$PY" -c 'import tomllib, yaml' 2>/dev/null; then
echo "нужен Python >= 3.11 с PyYAML: выполните make venv (или задайте STATEMENTS_PY)" >&2
exit 1
fi
fail=0
check() { if [ "$1" = 0 ]; then echo "ok: $2"; else echo "FAIL: $2" >&2; fail=1; fi; }
put() { mkdir -p "$(dirname "$1")"; printf '%s\n' "${2:-x}" > "$1"; }
# shellcheck disable=SC2317
commit_push() { git -C "$1" add -A; git -C "$1" commit -qm "$2"; git -C "$1" push -q origin "HEAD:$3" 2>/dev/null; git -C "$1" fetch -q origin; }
# --- помощник statements_check.py ---------------------------------------------------------------------------------
H="$WORK/h"; mkdir -p "$H"
CHK="$HERE/statements_check.py"
# run <rc-ожидаемый> <описание> <аргументы…>: вывод — в $OUT
run() {
local want=$1 desc=$2 rc=0; shift 2
OUT=$("$PY" "$CHK" "$@" 2>&1) || rc=$?
check "$([ "$rc" = "$want" ] && echo 0 || echo 1)" "$desc (rc=$rc, ожидался $want)"
}
has() { grep -q -- "$1" <<<"$OUT"; }
put "$H/pp.toml" $'[project]\ndependencies = ["PyYAML==6.0.3"]'
put "$H/r1.txt" $'aiohttp==3.14.3\nPyYAML==6.0.3'
run 0 "deps: есть" deps "$H/pp.toml" "$H/r1.txt"
check "$([ -z "$OUT" ] && echo 0 || echo 1)" "deps: есть — вывод пустой"
put "$H/r2.txt" $'aiohttp==3.14.3\npyyaml==6.0.3'
run 0 "deps: регистр" deps "$H/pp.toml" "$H/r2.txt"
put "$H/pp_u.toml" $'[project]\ndependencies = ["Py_YAML==6.0.3"]'
put "$H/r2u.txt" $'py-yaml==6.0.3'
run 0 "deps: подчёркивание и дефис равны" deps "$H/pp_u.toml" "$H/r2u.txt"
put "$H/r3.txt" $'aiohttp==3.14.3\n# PyYAML==6.0.3\n-r other.txt'
run 20 "deps: нет" deps "$H/pp.toml" "$H/r3.txt"
check "$(has PyYAML && echo 0 || echo 1)" "deps: нет — в выводе PyYAML"
put "$H/r4.txt" $'PyYAML==6.0.4'
run 0 "deps: другая версия" deps "$H/pp.toml" "$H/r4.txt"
check "$(has 'примечание:' && has 6.0.4 && echo 0 || echo 1)" "deps: другая версия — примечание с 6.0.4"
put "$H/pp_none.toml" $'[tool.ruff]\nline-length = 120'
run 0 "deps: без [project]" deps "$H/pp_none.toml" "$H/r1.txt"
put "$H/pp_jwt.toml" $'[project]\ndependencies = ["PyJWT==2.8.0"]'
put "$H/r5.txt" $'PyJWT[crypto]==2.8.0'
run 0 "deps: экстры хоста" deps "$H/pp_jwt.toml" "$H/r5.txt"
put "$H/orders.yaml" 'version: 1
repeats: {}
editions:
66n:
BALANCE: {full: ["1110", "1100"], simplified: ["1100"]}
INCOME: {full: ["2110"], simplified: ["2110"]}
fsbu4:
BALANCE: {full: ["1110", "1100"], simplified: ["1100"]}
INCOME: {full: ["2110"], simplified: ["2110"]}'
put "$H/lines.yaml" 'editions:
- id: 66n
forms:
BALANCE:
- {code: "1110", name: "Основные средства"}
- {code: "1100", name: "Итого"}
- id: fsbu4
forms:
BALANCE:
- {code: "1110", name: "Основные средства"}'
run 0 "lines: все коды есть" lines "$H/lines.yaml" "$H/orders.yaml"
put "$H/lines_x.yaml" 'editions:
- id: 66n
forms:
BALANCE:
- {code: "1110", name: "а"}
- id: fsbu4
forms:
BALANCE:
- {code: "1110", name: "а"}
- {code: "1120", name: "б"}'
run 20 "lines: код вне перечня" lines "$H/lines_x.yaml" "$H/orders.yaml"
check "$(has 1120 && has fsbu4 && echo 0 || echo 1)" "lines: код вне перечня — в выводе 1120 и fsbu4"
put "$H/orders_s.yaml" 'version: 1
editions:
fsbu4:
BALANCE: {full: ["1110"], simplified: ["1100"]}'
put "$H/lines_s.yaml" 'editions:
- id: fsbu4
forms:
BALANCE:
- {code: "1100", name: "а"}'
run 0 "lines: код только в simplified" lines "$H/lines_s.yaml" "$H/orders_s.yaml"
put "$H/bad.yaml" 'editions: ['
run 1 "битый YAML" lines "$H/bad.yaml" "$H/orders.yaml"
run 2 "аргументы"
[ "$fail" = 0 ] || exit 1
echo "ok: sync-statements.sh — все сценарии пройдены"