Files
cobol-java-v3/tests/hina/test_gcov_collector.py
T
hangshuo652 bc1d56d1a4 feat: Phase 2 complete — 13 Phases of COBOL type classification and test benchmark
P0.6: gcov infrastructure
P1: extract_structure output expansion (11 new feature fields)
P2: Confusion group rule engine (8 pairs + contradiction + backtrack)
P3: 4-factor confidence calculation + quality gate update
P4: 33+2 COBOL program type test samples (22 files, 7 categories)
P5: parametrized/ test data generation engine
P6: japanese_data.py lookup tables
P7-10: Type-specific test suites (~159 parametrized tests)
P11: Full classification pipeline (classify_program) + orchestrator integration
P12: Documentation (module-interfaces, test-plan v3.0, coverage-matrix)

Architecture decisions:
- classification_pipeline/ merged to hina/pipeline/
- parametrized/ as independent module
- japanese_data.py as root-level file
- hina/__all__ only exports classify_program()

Co-Authored-By: Claude <noreply@anthropic.com>
2026-06-19 23:51:55 +08:00

36 lines
1.3 KiB
Python

"""GC-01~03: gcov_collector — COBOL 覆盖率采集"""
import sys, os, tempfile
from pathlib import Path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))
from hina.gcov_collector import collect_gcov
def test_gcov_not_installed():
"""GC-01: cobc 不在 PATH → available=False"""
# Use a temp dir that won't have .gcda/.gcno files
with tempfile.TemporaryDirectory() as tmp:
work = Path(tmp)
result = collect_gcov(work / "program.cbl", work)
assert isinstance(result, dict)
# available should be False or result has a status field
assert not result.get("available", True) or "reason" in result
def test_gcov_no_data():
"""GC-02: 无 .gcda/.gcno → available=False"""
with tempfile.TemporaryDirectory() as tmp:
cobol_src = Path(tmp) / "test.cbl"
cobol_src.write_text("PROGRAM-ID. TEST.")
result = collect_gcov(cobol_src, Path(tmp))
assert result.get("available") is False
assert "reason" in result
def test_gcov_result_structure():
"""返回的 dict 包含必要字段"""
with tempfile.TemporaryDirectory() as tmp:
result = collect_gcov(Path(tmp) / "nope.cbl", Path(tmp))
assert "available" in result
assert "reason" in result or "line_rate" in result