import subprocess
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def test_production_meter_parser_and_collector(tmp_path):
    executable = tmp_path / "meter_parser_test"
    compile_result = subprocess.run(
        [
            "g++",
            "-std=c++17",
            "-Wall",
            "-Wextra",
            "-Werror",
            f"-I{ROOT / 'include'}",
            str(ROOT / "src" / "meter_health.cpp"),
            str(ROOT / "src" / "meter_parser.cpp"),
            str(ROOT / "hil_tests" / "meter_parser_harness.cpp"),
            "-o",
            str(executable),
        ],
        check=False,
        capture_output=True,
        text=True,
    )
    assert compile_result.returncode == 0, compile_result.stderr
    run_result = subprocess.run(
        [str(executable)], check=False, capture_output=True, text=True
    )
    assert run_result.returncode == 0, run_result.stderr
    assert "tests passed" in run_result.stdout
