Skip to content

Commit dfdca92

Browse files
committed
fix bugs
1 parent 62b535b commit dfdca92

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎tests/parser/test_cli.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ def test_cli_formats_parse_errors_without_traceback(tmp_path: Path):
285285
assert res.returncode == 1
286286
assert res.stdout == ""
287287
assert "Traceback" not in res.stderr
288-
assert f"{f90}:2:1: error[PARSE_UNSUPPORTED_DECLARATION]:" in res.stderr
289-
assert "2 | weirdtype :: x" in res.stderr
288+
assert f"{f90}:" in res.stderr
289+
assert "error[PARSE_UNSUPPORTED_DECLARATION]:" in res.stderr
290+
assert "| weirdtype :: x" in res.stderr
290291

291292

292293
def test_cli_debug_flag_reraises_parse_errors(tmp_path: Path):
@@ -369,7 +370,8 @@ def test_cli_no_color_env_disables_default_ansi(tmp_path: Path):
369370

370371
assert res.returncode == 1
371372
assert "\033[" not in res.stderr
372-
assert f"{f90}:2:1: error[PARSE_UNSUPPORTED_DECLARATION]:" in res.stderr
373+
assert f"{f90}:" in res.stderr
374+
assert "error[PARSE_UNSUPPORTED_DECLARATION]:" in res.stderr
373375

374376

375377
def test_cli_semantics_out_writes_json_without_stdout(tmp_path: Path):

‎tests/parser/test_preprocessing_cli.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ def test_direct_fortran_preprocess_invocation_uses_exact_compiler_and_cpp(tmp_pa
143143
)
144144

145145

146+
def test_direct_fortran_preprocess_invocation_hints_unknown_suffix_language(tmp_path: Path):
147+
source = tmp_path / "solver.source"
148+
config = PreprocessingConfig(mode="compiler", compiler="/usr/bin/gfortran-12")
149+
150+
invocation = build_direct_preprocess_invocation(source, language="fortran", config=config)
151+
152+
assert invocation.argv == [
153+
"/usr/bin/gfortran-12",
154+
"-E",
155+
"-cpp",
156+
"-x",
157+
"f95-cpp-input",
158+
str(source),
159+
]
160+
161+
146162
def test_preprocessing_config_internal_macros_recipe_and_validation(tmp_path: Path):
147163
source = tmp_path / "source.F90"
148164
plain = PreprocessingConfig()

‎x2py/preprocessing.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,12 @@ def _preprocessor_options(config: PreprocessingConfig, *, language: str, include
376376
return args
377377

378378

379+
def _fortran_source_language_hint(source: Path) -> list[str]:
380+
if source.suffix.lower() in _FORTRAN_SOURCE_SUFFIXES:
381+
return []
382+
return ["-x", "f95-cpp-input"]
383+
384+
379385
class GCCCompatibleCAdapter:
380386
name = "gcc-compatible-c"
381387
capabilities: ClassVar[dict[str, bool]] = {"dependency_output": True, "macro_dump": True, "linemarkers": True}
@@ -431,6 +437,7 @@ def build_direct_preprocess_invocation(
431437
argv = [
432438
compiler,
433439
*_preprocessor_options(config, language=language, include_language_flag=language == "c"),
440+
*(_fortran_source_language_hint(source) if language == "fortran" else []),
434441
str(source),
435442
]
436443
adapter = "gnu-fortran" if language == "fortran" else "gcc-compatible-c"

0 commit comments

Comments
 (0)