Skip to content

Commit 8d291ab

Browse files
author
Paolo Tranquilli
committed
Codegen: move qltest.test_with to parametrized pragmas
1 parent 3e2f886 commit 8d291ab

File tree

8 files changed

+18
-17
lines changed

8 files changed

+18
-17
lines changed

misc/codegen/generators/qlgen.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ def get_ql_property(cls: schema.Class, prop: schema.Property, lookup: typing.Dic
154154

155155

156156
def get_ql_class(cls: schema.Class, lookup: typing.Dict[str, schema.Class]) -> ql.Class:
157-
pragmas = {k: True for k in cls.pragmas if k.startswith("qltest")}
158157
prev_child = ""
159158
properties = []
160159
for p in cls.properties:
@@ -172,7 +171,6 @@ def get_ql_class(cls: schema.Class, lookup: typing.Dict[str, schema.Class]) -> q
172171
doc=cls.doc,
173172
hideable=cls.hideable,
174173
internal="ql_internal" in cls.pragmas,
175-
**pragmas,
176174
)
177175

178176

@@ -448,7 +446,8 @@ def generate(opts, renderer):
448446
for c in data.classes.values():
449447
if should_skip_qltest(c, data.classes):
450448
continue
451-
test_with = data.classes[c.test_with] if c.test_with else c
449+
test_with_name = c.pragmas.get("qltest_test_with")
450+
test_with = data.classes[test_with_name] if test_with_name else c
452451
test_dir = test_out / test_with.group / test_with.name
453452
test_dir.mkdir(parents=True, exist_ok=True)
454453
if all(f.suffix in (".txt", ".ql", ".actual", ".expected") for f in test_dir.glob("*.*")):

misc/codegen/generators/rusttestgen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def generate(opts, renderer):
6060
if fn:
6161
indent = 4 * " "
6262
code = [indent + l for l in code]
63-
test_with = schema.classes[cls.test_with] if cls.test_with else cls
63+
test_with_name = typing.cast(str, cls.pragmas.get("qltest_test_with"))
64+
test_with = schema.classes[test_with_name] if test_with_name else cls
6465
test = opts.ql_test_output / test_with.group / test_with.name / f"gen_{test_name}.rs"
6566
renderer.render(TestCode(code="\n".join(code), function=fn), test)

misc/codegen/lib/ql.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,6 @@ class Class:
107107
dir: pathlib.Path = pathlib.Path()
108108
imports: List[str] = field(default_factory=list)
109109
import_prefix: Optional[str] = None
110-
qltest_skip: bool = False
111-
qltest_collapse_hierarchy: bool = False
112-
qltest_uncollapse_hierarchy: bool = False
113110
internal: bool = False
114111
doc: List[str] = field(default_factory=list)
115112
hideable: bool = False

misc/codegen/lib/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class Class:
9595
pragmas: List[str] | Dict[str, object] = field(default_factory=dict)
9696
doc: List[str] = field(default_factory=list)
9797
hideable: bool = False
98-
test_with: Optional[str] = None
9998

10099
def __post_init__(self):
101100
if not isinstance(self.pragmas, dict):
@@ -118,7 +117,7 @@ def check_types(self, known: typing.Iterable[str]):
118117
if synth.on_arguments is not None:
119118
for t in synth.on_arguments.values():
120119
_check_type(t, known)
121-
_check_type(self.test_with, known)
120+
_check_type(self.pragmas.get("qltest_test_with"), known)
122121

123122
@property
124123
def synth(self) -> SynthInfo | bool | None:

misc/codegen/lib/schemadefs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def f(cls: type) -> type:
238238
qltest.add(_Pragma("skip"))
239239
qltest.add(_ClassPragma("collapse_hierarchy"))
240240
qltest.add(_ClassPragma("uncollapse_hierarchy"))
241-
qltest.test_with = lambda cls: _annotate(test_with=cls) # inheritable
241+
qltest.add(_ParametrizedClassPragma("test_with", inherited=True, factory=_schema.get_type_name))
242242

243243
ql.add(_ParametrizedClassPragma("default_doc_name", factory=lambda doc: doc))
244244
ql.hideable = _annotate(hideable=True) # inheritable

misc/codegen/loaders/schemaloader.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ def _get_class(cls: type) -> schema.Class:
5353
# getattr to inherit from bases
5454
group=getattr(cls, "_group", ""),
5555
hideable=getattr(cls, "_hideable", False),
56-
test_with=_get_name(getattr(cls, "_test_with", None)),
5756
pragmas=pragmas,
5857
# in the following we don't use `getattr` to avoid inheriting
5958
properties=[
@@ -123,9 +122,11 @@ def _fill_hideable_information(classes: typing.Dict[str, schema.Class]):
123122

124123
def _check_test_with(classes: typing.Dict[str, schema.Class]):
125124
for cls in classes.values():
126-
if cls.test_with is not None and classes[cls.test_with].test_with is not None:
127-
raise schema.Error(f"{cls.name} has test_with {cls.test_with} which in turn "
128-
f"has test_with {classes[cls.test_with].test_with}, use that directly")
125+
test_with = typing.cast(str, cls.pragmas.get("qltest_test_with"))
126+
transitive_test_with = test_with and classes[test_with].pragmas.get("qltest_test_with")
127+
if test_with and transitive_test_with:
128+
raise schema.Error(f"{cls.name} has test_with {test_with} which in turn "
129+
f"has test_with {transitive_test_with}, use that directly")
129130

130131

131132
def load(m: types.ModuleType) -> schema.Schema:

misc/codegen/test/test_qlgen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def test_test_with(opts, generate_tests):
749749
write(opts.ql_test_output / "B" / "test.swift")
750750
assert generate_tests([
751751
schema.Class("Base", derived={"A", "B"}),
752-
schema.Class("A", bases=["Base"], test_with="B"),
752+
schema.Class("A", bases=["Base"], pragmas={"qltest_test_with": "B"}),
753753
schema.Class("B", bases=["Base"]),
754754
]) == {
755755
"B/A.ql": a_ql_class_tester(class_name="A"),

misc/codegen/test/test_schemaloader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,16 @@ class C(Root):
754754
class D(Root):
755755
pass
756756

757+
class E(B):
758+
pass
759+
757760
assert data.classes == {
758761
"Root": schema.Class("Root", derived=set("ABCD")),
759762
"A": schema.Class("A", bases=["Root"]),
760-
"B": schema.Class("B", bases=["Root"], test_with="A"),
761-
"C": schema.Class("C", bases=["Root"], test_with="D"),
763+
"B": schema.Class("B", bases=["Root"], pragmas={"qltest_test_with": "A"}, derived={'E'}),
764+
"C": schema.Class("C", bases=["Root"], pragmas={"qltest_test_with": "D"}),
762765
"D": schema.Class("D", bases=["Root"]),
766+
"E": schema.Class("E", bases=["B"], pragmas={"qltest_test_with": "A"}),
763767
}
764768

765769

0 commit comments

Comments
 (0)