From 833edd9a1f4163c1f8cf3a61be1ce960674aedbf Mon Sep 17 00:00:00 2001 From: said Date: Sun, 17 May 2026 23:36:14 +0100 Subject: [PATCH 1/2] codex: add public CLI traceback coverage tests --- tests/parser/test_cli.py | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/tests/parser/test_cli.py b/tests/parser/test_cli.py index 61621e850..2306976b5 100644 --- a/tests/parser/test_cli.py +++ b/tests/parser/test_cli.py @@ -685,3 +685,44 @@ def test_x2py_cli_rejects_invalid_stage_combinations(extra_args, message): res = subprocess.run(cmd, capture_output=True, text=True) assert res.returncode == 2 assert message in res.stderr + + +def test_fortran_parser_cli_debug_traceback_flag_reraises_parse_errors(tmp_path: Path): + f90 = tmp_path / "bad.f90" + f90.write_text( + """subroutine bad(x) + weirdtype :: x +end subroutine bad +""", + encoding="utf-8", + ) + + cmd = [sys.executable, "-m", "fortran_parser", str(f90), "--debug-traceback"] + res = subprocess.run(cmd, capture_output=True, text=True) + + assert res.returncode == 1 + assert "Traceback" in res.stderr + assert "FortranParseError" in res.stderr + + +def test_fortran_parser_cli_debug_traceback_env_reraises_parse_errors(tmp_path: Path): + f90 = tmp_path / "bad.f90" + f90.write_text( + """subroutine bad(x) + weirdtype :: x +end subroutine bad +""", + encoding="utf-8", + ) + + cmd = [sys.executable, "-m", "fortran_parser", str(f90)] + res = subprocess.run( + cmd, + capture_output=True, + text=True, + env={**os.environ, "FORTRAN_PARSER_DEBUG": "1"}, + ) + + assert res.returncode == 1 + assert "Traceback" in res.stderr + assert "note: parser raised at" in res.stderr From 1f039aa04ac094e5895b4954a3d72bbd9cac7e7d Mon Sep 17 00:00:00 2001 From: said Date: Sun, 17 May 2026 23:39:32 +0100 Subject: [PATCH 2/2] codex: add public main-entry CLI coverage tests --- tests/parser/test_cli.py | 69 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/tests/parser/test_cli.py b/tests/parser/test_cli.py index 2306976b5..fbe68f725 100644 --- a/tests/parser/test_cli.py +++ b/tests/parser/test_cli.py @@ -726,3 +726,72 @@ def test_fortran_parser_cli_debug_traceback_env_reraises_parse_errors(tmp_path: assert res.returncode == 1 assert "Traceback" in res.stderr assert "note: parser raised at" in res.stderr + + +def test_fortran_parser_main_public_api_modes_from_inline_source(tmp_path: Path, monkeypatch, capsys): + f90 = tmp_path / "mini.f90" + f90.write_text( + """module m +contains + subroutine work(n) + integer, intent(in) :: n + end subroutine work +end module m +""", + encoding="utf-8", + ) + json_out = tmp_path / "report.json" + + monkeypatch.setattr(sys, "argv", ["fortran_parser", str(f90), "--json-out", str(json_out), "--json"]) + assert fortran_parser_cli.main() == 0 + stdout_payload = json.loads(capsys.readouterr().out) + assert str(f90) in stdout_payload + assert json_out.exists() + + monkeypatch.setattr(sys, "argv", ["fortran_parser", str(f90), "--pyi"]) + assert fortran_parser_cli.main() == 0 + pyi_out = capsys.readouterr().out + assert "File:" in pyi_out + assert "def work(" in pyi_out + + monkeypatch.setattr(sys, "argv", ["fortran_parser", str(f90), "--wrap-readiness"]) + assert fortran_parser_cli.main() == 0 + wrap_out = capsys.readouterr().out + assert "Wrappable: yes" in wrap_out + + monkeypatch.setattr(sys, "argv", ["fortran_parser", str(f90)]) + assert fortran_parser_cli.main() == 0 + readable = capsys.readouterr().out + assert "module m" in readable + + +def test_x2py_main_public_api_modes_from_inline_source(tmp_path: Path, monkeypatch, capsys): + f90 = tmp_path / "mini.f90" + f90.write_text( + """module m +contains + subroutine work(n) + integer, intent(in) :: n + end subroutine work +end module m +""", + encoding="utf-8", + ) + json_out = tmp_path / "parse.json" + + monkeypatch.setattr(sys, "argv", ["x2py", str(f90), "--parse", "--json", "--out", str(json_out)]) + assert x2py_cli.main() == 0 + assert capsys.readouterr().out == "" + assert json.loads(json_out.read_text(encoding="utf-8")).get(str(f90)) is not None + + monkeypatch.setattr(sys, "argv", ["x2py", str(f90), "--parse", "--wrap-readiness"]) + assert x2py_cli.main() == 0 + assert "Wrappable: yes" in capsys.readouterr().out + + monkeypatch.setattr(sys, "argv", ["x2py", str(f90), "--pyi"]) + assert x2py_cli.main() == 0 + assert "def work(" in capsys.readouterr().out + + monkeypatch.setattr(sys, "argv", ["x2py", str(f90), "--parse"]) + assert x2py_cli.main() == 0 + assert "module m" in capsys.readouterr().out