Skip to content

Commit 6bbf1e3

Browse files
committed
Codegen: use one generated test file per directory
This collapses all generated test QL sources into a single one per directory, using query predicates to run the different tests. This should improve the time required to run generated tests.
1 parent 3d9e2f5 commit 6bbf1e3

File tree

1,753 files changed

+7752
-7850
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

+7752
-7850
lines changed

misc/codegen/generators/qlgen.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -372,11 +372,6 @@ def _partition_iter(x, pred):
372372
return filter(pred, x1), itertools.filterfalse(pred, x2)
373373

374374

375-
def _partition(l, pred):
376-
"""partitions a list according to boolean predicate"""
377-
return map(list, _partition_iter(l, pred))
378-
379-
380375
def _is_in_qltest_collapsed_hierarchy(
381376
cls: schema.Class, lookup: typing.Dict[str, schema.Class]
382377
):
@@ -625,29 +620,18 @@ def generate(opts, renderer):
625620
test_dir / missing_test_source_filename,
626621
)
627622
continue
628-
total_props, partial_props = _partition(
629-
_get_all_properties_to_be_tested(c, data.classes),
630-
lambda p: p.is_total,
631-
)
632623
renderer.render(
633624
ql.ClassTester(
634625
class_name=c.name,
635-
properties=total_props,
626+
properties=list(
627+
_get_all_properties_to_be_tested(c, data.classes)
628+
),
636629
elements_module=elements_module,
637630
# in case of collapsed hierarchies we want to see the actual QL class in results
638631
show_ql_class="qltest_collapse_hierarchy" in c.pragmas,
639632
),
640633
test_dir / f"{c.name}.ql",
641634
)
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-
)
651635

652636
final_synth_types = []
653637
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 & 30 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,19 @@ def test_test_partial_properties(opts, generate_tests):
10411037
"B/B.ql": a_ql_class_tester(
10421038
class_name="B",
10431039
properties=[
1040+
ql.PropertyForTest(getter="getX", is_total=False, type="string"),
10441041
ql.PropertyForTest(getter="hasX"),
1042+
ql.PropertyForTest(
1043+
getter="getY", is_total=False, is_indexed=True, type="bool"
1044+
),
10451045
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
1046+
ql.PropertyForTest(
1047+
getter="getZ", is_total=False, is_indexed=True, type="int"
1048+
),
1049+
ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
10461050
ql.PropertyForTest(getter="getNumberOfWs", type="int"),
10471051
],
10481052
),
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-
),
10691053
}
10701054

10711055

@@ -1090,15 +1074,12 @@ def test_test_properties_deduplicated(opts, generate_tests):
10901074
class_name="Final",
10911075
properties=[
10921076
ql.PropertyForTest(getter="getX", type="string"),
1077+
ql.PropertyForTest(
1078+
getter="getY", is_total=False, is_indexed=True, type="bool"
1079+
),
10931080
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
10941081
],
10951082
),
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-
),
11021083
}
11031084

11041085

0 commit comments

Comments
 (0)