Skip to content

Commit afc78ce

Browse files
authored
Merge pull request #19874 from github/redsun82/codegen-use-one-test-file
Codegen: use one generated test file per directory
2 parents 321a4af + 6a0140d commit afc78ce

File tree

1,753 files changed

+7355
-9731
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,753 files changed

+7355
-9731
lines changed

misc/codegen/generators/qlgen.py

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -361,22 +361,13 @@ def _get_all_properties_to_be_tested(
361361
type=p.type if not p.is_predicate else None,
362362
is_indexed=p.is_indexed,
363363
)
364-
if p.is_repeated and not p.is_optional:
365-
yield ql.PropertyForTest(f"getNumberOf{p.plural}", type="int")
366-
elif p.is_optional and not p.is_repeated:
367-
yield ql.PropertyForTest(f"has{p.singular}")
368364

369365

370366
def _partition_iter(x, pred):
371367
x1, x2 = itertools.tee(x)
372368
return filter(pred, x1), itertools.filterfalse(pred, x2)
373369

374370

375-
def _partition(l, pred):
376-
"""partitions a list according to boolean predicate"""
377-
return map(list, _partition_iter(l, pred))
378-
379-
380371
def _is_in_qltest_collapsed_hierarchy(
381372
cls: schema.Class, lookup: typing.Dict[str, schema.Class]
382373
):
@@ -625,29 +616,18 @@ def generate(opts, renderer):
625616
test_dir / missing_test_source_filename,
626617
)
627618
continue
628-
total_props, partial_props = _partition(
629-
_get_all_properties_to_be_tested(c, data.classes),
630-
lambda p: p.is_total,
631-
)
632619
renderer.render(
633620
ql.ClassTester(
634621
class_name=c.name,
635-
properties=total_props,
622+
properties=list(
623+
_get_all_properties_to_be_tested(c, data.classes)
624+
),
636625
elements_module=elements_module,
637626
# in case of collapsed hierarchies we want to see the actual QL class in results
638627
show_ql_class="qltest_collapse_hierarchy" in c.pragmas,
639628
),
640629
test_dir / f"{c.name}.ql",
641630
)
642-
for p in partial_props:
643-
renderer.render(
644-
ql.PropertyTester(
645-
class_name=c.name,
646-
elements_module=elements_module,
647-
property=p,
648-
),
649-
test_dir / f"{c.name}_{p.getter}.ql",
650-
)
651631

652632
final_synth_types = []
653633
non_final_synth_types = []

misc/codegen/lib/ql.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,6 @@ class ClassTester(TesterBase):
245245
show_ql_class: bool = False
246246

247247

248-
@dataclass
249-
class PropertyTester(TesterBase):
250-
template: ClassVar = "ql_test_property"
251-
252-
property: PropertyForTest
253-
254-
255248
@dataclass
256249
class MissingTestInstructions:
257250
template: ClassVar = "ql_test_missing"

misc/codegen/templates/ql_test_class.mustache

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@
33
import {{elements_module}}
44
import TestUtils
55

6-
from {{class_name}} x{{#properties}}, {{#type}}{{.}}{{/type}}{{^type}}string{{/type}} {{getter}}{{/properties}}
7-
where toBeTested(x) and not x.isUnknown()
6+
query predicate instances({{class_name}} x{{#show_ql_class}}, string primaryQlClasses{{/show_ql_class}}{{#properties}}{{#is_total}}, string {{getter}}__label, {{#type}}{{.}}{{/type}}{{^type}}string{{/type}} {{getter}}{{/is_total}}{{/properties}}) {
7+
toBeTested(x) and not x.isUnknown()
8+
{{#show_ql_class}}
9+
and primaryQlClasses = x.getPrimaryQlClasses()
10+
{{/show_ql_class}}
11+
{{#properties}}
12+
{{#is_total}}
13+
and {{getter}}__label = "{{getter}}:"
14+
{{#type}}
15+
and {{getter}} = x.{{getter}}()
16+
{{/type}}
17+
{{^type}}
18+
and if x.{{getter}}() then {{getter}} = "yes" else {{getter}} = "no"
19+
{{/type}}
20+
{{/is_total}}
21+
{{/properties}}
22+
}
23+
824
{{#properties}}
9-
{{#type}}
10-
and {{getter}} = x.{{getter}}()
11-
{{/type}}
12-
{{^type}}
13-
and if x.{{getter}}() then {{getter}} = "yes" else {{getter}} = "no"
14-
{{/type}}
25+
{{^is_total}}
26+
query predicate {{getter}}({{class_name}} x{{#is_indexed}}, int index{{/is_indexed}}, {{type}} {{getter}}) {
27+
toBeTested(x) and not x.isUnknown() and {{getter}} = x.{{getter}}({{#is_indexed}}index{{/is_indexed}})
28+
}
29+
{{/is_total}}
1530
{{/properties}}
16-
select x{{#show_ql_class}}, x.getPrimaryQlClasses(){{/show_ql_class}}{{#properties}}, "{{getter}}:", {{getter}}{{/properties}}

misc/codegen/templates/ql_test_property.mustache

Lines changed: 0 additions & 10 deletions
This file was deleted.

misc/codegen/test/test_qlgen.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -960,10 +960,6 @@ def a_ql_class_tester(**kwargs):
960960
return ql.ClassTester(**kwargs, elements_module=stub_import)
961961

962962

963-
def a_ql_property_tester(**kwargs):
964-
return ql.PropertyTester(**kwargs, elements_module=stub_import)
965-
966-
967963
def test_test_source_present(opts, generate_tests):
968964
write(opts.ql_test_output / "A" / "test.swift")
969965
assert generate_tests(
@@ -1041,31 +1037,16 @@ def test_test_partial_properties(opts, generate_tests):
10411037
"B/B.ql": a_ql_class_tester(
10421038
class_name="B",
10431039
properties=[
1044-
ql.PropertyForTest(getter="hasX"),
1045-
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
1046-
ql.PropertyForTest(getter="getNumberOfWs", type="int"),
1040+
ql.PropertyForTest(getter="getX", is_total=False, type="string"),
1041+
ql.PropertyForTest(
1042+
getter="getY", is_total=False, is_indexed=True, type="bool"
1043+
),
1044+
ql.PropertyForTest(
1045+
getter="getZ", is_total=False, is_indexed=True, type="int"
1046+
),
1047+
ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
10471048
],
10481049
),
1049-
"B/B_getX.ql": a_ql_property_tester(
1050-
class_name="B",
1051-
property=ql.PropertyForTest(getter="getX", is_total=False, type="string"),
1052-
),
1053-
"B/B_getY.ql": a_ql_property_tester(
1054-
class_name="B",
1055-
property=ql.PropertyForTest(
1056-
getter="getY", is_total=False, is_indexed=True, type="bool"
1057-
),
1058-
),
1059-
"B/B_getZ.ql": a_ql_property_tester(
1060-
class_name="B",
1061-
property=ql.PropertyForTest(
1062-
getter="getZ", is_total=False, is_indexed=True, type="int"
1063-
),
1064-
),
1065-
"B/B_getAW.ql": a_ql_property_tester(
1066-
class_name="B",
1067-
property=ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
1068-
),
10691050
}
10701051

10711052

@@ -1090,15 +1071,11 @@ def test_test_properties_deduplicated(opts, generate_tests):
10901071
class_name="Final",
10911072
properties=[
10921073
ql.PropertyForTest(getter="getX", type="string"),
1093-
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
1074+
ql.PropertyForTest(
1075+
getter="getY", is_total=False, is_indexed=True, type="bool"
1076+
),
10941077
],
10951078
),
1096-
"Final/Final_getY.ql": a_ql_property_tester(
1097-
class_name="Final",
1098-
property=ql.PropertyForTest(
1099-
getter="getY", is_total=False, is_indexed=True, type="bool"
1100-
),
1101-
),
11021079
}
11031080

11041081

0 commit comments

Comments
 (0)