"""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