Add option to retain #include directives in preprocessor
This commit is contained in:
@@ -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"')]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user