Отдельные документы о тестировании

This commit is contained in:
2026-05-28 18:07:46 +03:00
parent 32c579e0c0
commit f7023380b3
23 changed files with 141922 additions and 71 deletions

View File

@@ -50,6 +50,19 @@ def should_skip(path: Path, parts: tuple[str, ...], cfg: dict) -> bool:
return False
def is_test_source(path: Path, cfg: dict) -> bool:
if not cfg.get("only_test_filenames"):
return True
return path.name.endswith("Test.kt") or path.name == "YandexTestCredentials.kt"
def matches_path_filter(rel_posix: str, cfg: dict) -> bool:
needles = cfg.get("only_path_substrings")
if not needles:
return True
return any(n in rel_posix for n in needles)
def collect_files(scan_root: Path, cfg: dict) -> list[Path]:
ext_map: dict = cfg.get("include_extensions", {})
name_map: dict = cfg.get("include_filenames", {})
@@ -64,6 +77,11 @@ def collect_files(scan_root: Path, cfg: dict) -> list[Path]:
if should_skip(p, rel_parts, cfg):
continue
if p.name in allowed_names or p.suffix.lower() in allowed_suffixes:
rel_posix = p.relative_to(scan_root).as_posix()
if not matches_path_filter(rel_posix, cfg):
continue
if not is_test_source(p, cfg):
continue
files.append(p)
return sorted(files, key=lambda x: x.as_posix())
@@ -109,6 +127,8 @@ def write_listing(
caption: str,
label: str,
lang: str,
*,
pagebreak_after: bool,
) -> None:
rel_typ = typst_escape_path(rel_from_report)
content = (
@@ -119,11 +139,22 @@ def write_listing(
f" ],\n"
f" supplement: [Листинг],\n"
f") <lst-{label}>\n"
f"#pagebreak(weak: true)\n\n"
)
if pagebreak_after:
content += "#pagebreak(weak: true)\n"
content += "\n"
out_path.write_text(content, encoding="utf-8")
def module_heading(mod: str, cfg: dict) -> str:
if mod == "root":
return "Система сборки"
for entry in cfg.get("module_titles", []):
if entry.get("id") == mod:
return entry["title"]
return f"Модуль :{mod}"
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("--dry-run", action="store_true")
@@ -136,7 +167,10 @@ def main() -> int:
cfg = load_config(config_path)
scan_root = (report_dir / cfg.get("scan_root", "..")).resolve()
generated = report_dir / "listings" / "generated"
generated = report_dir / "listings" / cfg.get("generated_subdir", "generated")
appendix_name = cfg.get("appendix_filename", "appendix-a.typ")
caption_prefix = cfg.get("caption_prefix", "Исходный файл ")
pagebreak_after = cfg.get("pagebreak_after_listing", True)
ext_map: dict = cfg.get("include_extensions", {})
name_map: dict = cfg.get("include_filenames", {})
@@ -162,17 +196,24 @@ def main() -> int:
rel_report_str = rel_report.as_posix()
hid = path_hash(rel_repo)
label = hid
cap = f"Исходный файл {typst_escape_caption(rel_repo)}"
cap = f"{caption_prefix}{typst_escape_caption(rel_repo)}"
lang = lang_for(f, ext_map, name_map)
listing_name = f"listing-{hid}.typ"
listing_path = generated / listing_name
write_listing(listing_path, rel_report_str, cap, label, lang)
write_listing(
listing_path,
rel_report_str,
cap,
label,
lang,
pagebreak_after=pagebreak_after,
)
mod_listings.append(listing_name)
listing_paths.append(listing_name)
mod_file = generated / f"module-{mod}.typ"
with mod_file.open("w", encoding="utf-8") as mf:
title = "Система сборки" if mod == "root" else f"Модуль :{mod}"
title = module_heading(mod, cfg)
mf.write(f"== {title}\n\n")
if cfg.get("pagebreak_per_module") and mod != "root":
mf.write("#pagebreak(weak: true)\n\n")
@@ -184,7 +225,7 @@ def main() -> int:
with index.open("w", encoding="utf-8") as ix:
ix.write(f"// Generated listings: {len(files)} files\n\n")
appendix = generated / "appendix-a.typ"
appendix = generated / appendix_name
styles_path = report_dir / "includes" / "listings-appendix.typ"
styles = styles_path.read_text(encoding="utf-8")
with appendix.open("w", encoding="utf-8") as ap:
@@ -195,7 +236,7 @@ def main() -> int:
for mi in module_includes:
ap.write(f'#include "{mi}"\n')
print(f"Generated {len(files)} listings in {generated}", file=sys.stderr)
print(f"Generated {len(files)} listings {appendix}", file=sys.stderr)
return 0