Add option to retain #include directives in preprocessor

This commit is contained in:
seladb
2023-10-05 02:29:30 -07:00
committed by Dustin Spicuzza
parent 26da91836a
commit 312f6fba6b
2 changed files with 38 additions and 3 deletions

View File

@@ -1,9 +1,16 @@
import os
import pathlib
import re
from cxxheaderparser.options import ParserOptions
from cxxheaderparser.preprocessor import make_pcpp_preprocessor
from cxxheaderparser.simple import NamespaceScope, ParsedData, parse_file, parse_string
from cxxheaderparser.simple import (
NamespaceScope,
ParsedData,
parse_file,
parse_string,
Include,
)
from cxxheaderparser.types import (
FundamentalSpecifier,
NameSpecifier,
@@ -135,3 +142,23 @@ def test_preprocessor_encoding(tmp_path: pathlib.Path) -> None:
]
)
)
def test_preprocessor_passthru_includes(tmp_path: pathlib.Path) -> None:
"""Ensure that all #include pass through"""
h_content = '#include "t2.h"\n'
with open(tmp_path / "t1.h", "w") as fp:
fp.write(h_content)
with open(tmp_path / "t2.h", "w") as fp:
fp.write("")
options = ParserOptions(
preprocessor=make_pcpp_preprocessor(passthru_includes=re.compile(".+"))
)
data = parse_file(tmp_path / "t1.h", options=options)
assert data == ParsedData(
namespace=NamespaceScope(), includes=[Include(filename='"t2.h"')]
)