Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/c_parser/c_parser_architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Implemented now:
rejected until semantic conversion exists.
- Focused partial CLI/API, declaration/function, diagnostic color, project
include/index, raw lexer/directive, project golden, error golden, and JSON
schema tests are active while corpus, semantic, and `.pyi` roadmap tests
remain skipped.
schema tests are active. Remaining parser-suite skips are limited to the
pinned corpus roadmap and compiler-preprocessed `.i`/`#line` behavior.
- `tests/data/c/` contains general fixtures modeled after the Fortran general
fixture themes, additional C-specific API shapes, fatal diagnostic inputs,
and real-world cJSON/jsmn/tinyexpr/linmath/NanoSVG/stb inputs whose partial
Expand Down
2 changes: 2 additions & 0 deletions docs/c_parser/c_parser_cli_workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ member placement and flexible union members produce
`parser_status: "partial"`. C parse diagnostics, currently including
unsupported K&R-style function definitions and invalid primitive-specifier
combinations such as `unsigned float`, honor `--no-color` and `NO_COLOR=1`.
Active CLI regression tests also verify that `--debug-traceback` and
`C_PARSER_DEBUG=1` re-raise fatal C parse errors for debugging.
Function definitions do not store executable body text; they preserve a
direct `start` location and `end` location from the signature start through the
closing brace. Compatible repeated top-level declarations are merged;
Expand Down
11 changes: 7 additions & 4 deletions docs/c_parser/c_parser_implementation_checklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,19 @@ Scope:
- [x] Keep the skipped C suite separate from existing Fortran tests.
- [x] Keep Fortran tests green whenever C tests are unskipped.

### Skipped Roadmap Test Files
### Roadmap And Active Test Files

- [x] Create `tests/parser/c/README.md` with the staged unskip policy.
- [x] Create `tests/parser/c/test_c_public_entrypoints.py`.
- [x] Create `tests/parser/c/test_c_cli.py`.
- [x] Consolidate implemented public API roadmap coverage into
`tests/parser/c/test_c_public_api_skeleton.py`.
- [x] Consolidate implemented CLI roadmap coverage into
`tests/parser/c/test_c_cli_skeleton.py`.
- [x] Create `tests/parser/c/test_c_lexer_preprocessor.py`.
- [x] Create `tests/parser/c/test_c_declarations_and_declarators.py`.
- [x] Create `tests/parser/c/test_c_functions.py`.
- [x] Create `tests/parser/c/test_c_structs_unions_enums_typedefs.py`.
- [x] Create `tests/parser/c/test_c_project_includes.py`.
- [x] Consolidate implemented project/include roadmap coverage into
`tests/parser/c/test_c_project_resolution.py`.
- [x] Create `tests/semantics/test_c_semantic_readiness.py` or equivalent
semantic-layer coverage for C wrappability once that layer exists.
- [x] Create `tests/parser/c/test_c_fixture_suite.py`.
Expand Down
18 changes: 10 additions & 8 deletions docs/c_parser/c_parser_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,8 @@ Test families should mirror the Fortran parser:
- error fixture/golden tests
- corpus parse-only tests

The C test area now contains both unskipped partial-parser/raw-metadata tests
and skipped roadmap tests under `tests/parser/c/`. The active tests cover
The C test area now contains active partial-parser/raw-metadata tests plus
narrowly scoped roadmap skips under `tests/parser/c/`. The active tests cover
public entrypoints, empty model serialization, CLI discovery, JSON/output-file
behavior, unsupported C stages, comment stripping, line-continuation folding,
top-level splitting, include collection, simple macro collection, macro-shaped
Expand All @@ -476,13 +476,15 @@ macro-dependency metadata, project include/index behavior, simple declarations,
variables, typedefs, top-level redeclaration diagnostics, recursive declarator
composition, aggregate definitions, members, enums, simple function
prototypes/definitions, function-definition start/end locations, JSON golden
serialization, and fatal diagnostic goldens. The `json` regression inputs
serialization, fatal diagnostic goldens, and project-level callback typedef
resolution. The `json` regression inputs
intentionally retain recoverable diagnostics from unsupported constructs; they
do not claim complete library parsing. Corpus, semantic, and `.pyi` roadmap
tests remain skipped until their matching implementation branches land. Future
implementation
branches should unskip only the tests for the capability they implement, then
merge those branches back into `c-parser/main`.
do not claim complete library parsing. Remaining parser-suite skips cover the
pinned/provenanced corpus target and compiler-preprocessed `.i`/`#line`
behavior; golden inventory checks also skip deliberately while update mode is
rewriting their baselines. Future implementation branches should activate only
the tests for the capability they implement, then merge those branches back
into `c-parser/main`.

### Declaration Coverage Boundary

Expand Down
17 changes: 14 additions & 3 deletions tests/parser/c/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# C Parser Tests

This directory contains active tests for the implemented partial C parser and
skipped roadmap tests for later parser, corpus, semantic, and `.pyi` work.
narrowly scoped skipped tests for genuinely deferred input/corpus work.

Unskip tests one capability at a time on a short-lived `c-parser/*` branch, then
merge only into `c-parser/main`.
Expand All @@ -10,11 +10,22 @@ Guidelines:

- keep these tests separate from the Fortran parser tests
- keep wrap-readiness tests under `tests/semantics`, not under parser tests
- do not import `c_parser` at module import time while the suite is skipped
- unskip the smallest useful group of tests with each implementation branch
- do not import `c_parser` at module import time while a roadmap test is skipped
- activate or remove roadmap tests once matching active coverage lands
- add fixtures and goldens only when the corresponding schema is stable
- keep cJSON as the first real-world corpus target once corpus tests start

## Intentional Skips

The normal parser test run retains skips only for the pinned/provenanced
cJSON corpus roadmap and compiler-preprocessed `.i`/`#line` behavior, which
are not implemented yet. CLI, public API, and current project-resolution
coverage are active.

When `C_PARSER_UPDATE_GOLDENS=1` is set, golden inventory checks are skipped
while their corresponding comparison tests rewrite the expected output. Those
update-mode skips are workflow behavior, not unsupported parser input.

## Parser Goldens

Active parser goldens cover grouped projects from `tests/data/c/general/`,
Expand Down
190 changes: 0 additions & 190 deletions tests/parser/c/test_c_cli.py

This file was deleted.

38 changes: 38 additions & 0 deletions tests/parser/c/test_c_cli_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,44 @@ def test_cli_c_invalid_primitive_specifier_sequence_is_fatal(tmp_path: Path):
assert "\x1b[" not in res.stderr


def test_cli_c_debug_traceback_reraises_parse_errors(tmp_path: Path):
header = tmp_path / "invalid_specifiers.h"
header.write_text("unsigned float value;\n", encoding="utf-8")
cmd = [
sys.executable,
"-m",
"x2py",
str(header),
"--language",
"c",
"--parse",
"--debug-traceback",
]

res = subprocess.run(cmd, capture_output=True, text=True)

assert res.returncode == 1
assert "Traceback" in res.stderr
assert "CParseError" in res.stderr


def test_cli_c_debug_env_reraises_parse_errors(tmp_path: Path):
header = tmp_path / "invalid_specifiers.h"
header.write_text("unsigned float value;\n", encoding="utf-8")
cmd = [sys.executable, "-m", "x2py", str(header), "--language", "c", "--parse"]

res = subprocess.run(
cmd,
capture_output=True,
text=True,
env={**os.environ, "C_PARSER_DEBUG": "1"},
)

assert res.returncode == 1
assert "Traceback" in res.stderr
assert "CParseError" in res.stderr


def test_cli_without_language_keeps_fortran_default_behavior():
fixture = Path(__file__).resolve().parents[2] / "data" / "fortran" / "general" / "basic_subroutine.f90"
cmd = [sys.executable, "-m", "x2py", str(fixture), "--parse"]
Expand Down
16 changes: 8 additions & 8 deletions tests/parser/c/test_c_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,19 @@ def test_function_parameter_preserves_declaration_and_adjusts_to_callback_pointe
assert parsed.functions[0].type.parameter_types[0] is callback.type


@pytest.mark.skip(reason="function pointer typedef resolution is not implemented yet.")
def test_callback_typedef_parameter_links_to_typedef_signature():
from c_parser import CFunctionType, CTypedef, parse_c_file
def test_project_resolves_callback_typedef_parameter_to_typedef_signature():
from c_parser import CFunctionType, CTypedef, parse_c_project

parsed = parse_c_file(
"""
project = parse_c_project(
{
"callback_typedef.h": """
typedef int (*compare_fn)(const void *a, const void *b);
void sort_items(void *items, compare_fn compare);
""",
filename="callback_typedef.h",
"""
}
)

referenced = parsed.functions[0].parameters[1].type
referenced = project.functions["sort_items"].parameters[1].type
assert isinstance(referenced, CTypedef)
assert isinstance(referenced.type.components[1], CFunctionType)

Expand Down
Loading
Loading