mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Merge branch 'main' into redsun82/codegen-new-parent-child
This commit is contained in:
@@ -281,10 +281,6 @@ class Resolver:
|
||||
type=p.type if not p.is_predicate else None,
|
||||
is_indexed=p.is_indexed,
|
||||
)
|
||||
if p.is_repeated and not p.is_optional:
|
||||
yield ql.PropertyForTest(f"getNumberOf{p.plural}", type="int")
|
||||
elif p.is_optional and not p.is_repeated:
|
||||
yield ql.PropertyForTest(f"has{p.singular}")
|
||||
|
||||
def _is_in_qltest_collapsed_hierarchy(
|
||||
self,
|
||||
@@ -415,16 +411,6 @@ def _get_path_public(cls: schema.Class) -> pathlib.Path:
|
||||
).with_suffix(".qll")
|
||||
|
||||
|
||||
def _partition_iter(x, pred):
|
||||
x1, x2 = itertools.tee(x)
|
||||
return filter(pred, x1), itertools.filterfalse(pred, x2)
|
||||
|
||||
|
||||
def _partition(l, pred):
|
||||
"""partitions a list according to boolean predicate"""
|
||||
return map(list, _partition_iter(l, pred))
|
||||
|
||||
|
||||
def _get_stub(
|
||||
cls: schema.Class, base_import: str, generated_import_prefix: str
|
||||
) -> ql.Stub:
|
||||
@@ -650,29 +636,16 @@ def generate(opts, renderer):
|
||||
test_dir / missing_test_source_filename,
|
||||
)
|
||||
continue
|
||||
total_props, partial_props = _partition(
|
||||
resolver.get_all_properties_to_be_tested(c),
|
||||
lambda p: p.is_total,
|
||||
)
|
||||
renderer.render(
|
||||
ql.ClassTester(
|
||||
class_name=c.name,
|
||||
properties=total_props,
|
||||
properties=list(resolver.get_all_properties_to_be_tested(c)),
|
||||
elements_module=elements_module,
|
||||
# in case of collapsed hierarchies we want to see the actual QL class in results
|
||||
show_ql_class="qltest_collapse_hierarchy" in c.pragmas,
|
||||
),
|
||||
test_dir / f"{c.name}.ql",
|
||||
)
|
||||
for p in partial_props:
|
||||
renderer.render(
|
||||
ql.PropertyTester(
|
||||
class_name=c.name,
|
||||
elements_module=elements_module,
|
||||
property=p,
|
||||
),
|
||||
test_dir / f"{c.name}_{p.getter}.ql",
|
||||
)
|
||||
|
||||
final_synth_types = []
|
||||
non_final_synth_types = []
|
||||
|
||||
@@ -248,13 +248,6 @@ class ClassTester(TesterBase):
|
||||
show_ql_class: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
class PropertyTester(TesterBase):
|
||||
template: ClassVar = "ql_test_property"
|
||||
|
||||
property: PropertyForTest
|
||||
|
||||
|
||||
@dataclass
|
||||
class MissingTestInstructions:
|
||||
template: ClassVar = "ql_test_missing"
|
||||
|
||||
@@ -3,14 +3,28 @@
|
||||
import {{elements_module}}
|
||||
import TestUtils
|
||||
|
||||
from {{class_name}} x{{#properties}}, {{#type}}{{.}}{{/type}}{{^type}}string{{/type}} {{getter}}{{/properties}}
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
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}}) {
|
||||
toBeTested(x) and not x.isUnknown()
|
||||
{{#show_ql_class}}
|
||||
and primaryQlClasses = x.getPrimaryQlClasses()
|
||||
{{/show_ql_class}}
|
||||
{{#properties}}
|
||||
{{#is_total}}
|
||||
and {{getter}}__label = "{{getter}}:"
|
||||
{{#type}}
|
||||
and {{getter}} = x.{{getter}}()
|
||||
{{/type}}
|
||||
{{^type}}
|
||||
and if x.{{getter}}() then {{getter}} = "yes" else {{getter}} = "no"
|
||||
{{/type}}
|
||||
{{/is_total}}
|
||||
{{/properties}}
|
||||
}
|
||||
|
||||
{{#properties}}
|
||||
{{#type}}
|
||||
and {{getter}} = x.{{getter}}()
|
||||
{{/type}}
|
||||
{{^type}}
|
||||
and if x.{{getter}}() then {{getter}} = "yes" else {{getter}} = "no"
|
||||
{{/type}}
|
||||
{{^is_total}}
|
||||
query predicate {{getter}}({{class_name}} x{{#is_indexed}}, int index{{/is_indexed}}, {{type}} {{getter}}) {
|
||||
toBeTested(x) and not x.isUnknown() and {{getter}} = x.{{getter}}({{#is_indexed}}index{{/is_indexed}})
|
||||
}
|
||||
{{/is_total}}
|
||||
{{/properties}}
|
||||
select x{{#show_ql_class}}, x.getPrimaryQlClasses(){{/show_ql_class}}{{#properties}}, "{{getter}}:", {{getter}}{{/properties}}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
// generated by {{generator}}, do not edit
|
||||
|
||||
import {{elements_module}}
|
||||
import TestUtils
|
||||
|
||||
{{#property}}
|
||||
from {{class_name}} x{{#is_indexed}}, int index{{/is_indexed}}
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, {{#is_indexed}}index, {{/is_indexed}}x.{{getter}}({{#is_indexed}}index{{/is_indexed}})
|
||||
{{/property}}
|
||||
@@ -1006,10 +1006,6 @@ def a_ql_class_tester(**kwargs):
|
||||
return ql.ClassTester(**kwargs, elements_module=stub_import)
|
||||
|
||||
|
||||
def a_ql_property_tester(**kwargs):
|
||||
return ql.PropertyTester(**kwargs, elements_module=stub_import)
|
||||
|
||||
|
||||
def test_test_source_present(opts, generate_tests):
|
||||
write(opts.ql_test_output / "A" / "test.swift")
|
||||
assert generate_tests(
|
||||
@@ -1087,31 +1083,16 @@ def test_test_partial_properties(opts, generate_tests):
|
||||
"B/B.ql": a_ql_class_tester(
|
||||
class_name="B",
|
||||
properties=[
|
||||
ql.PropertyForTest(getter="hasX"),
|
||||
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
|
||||
ql.PropertyForTest(getter="getNumberOfWs", type="int"),
|
||||
ql.PropertyForTest(getter="getX", is_total=False, type="string"),
|
||||
ql.PropertyForTest(
|
||||
getter="getY", is_total=False, is_indexed=True, type="bool"
|
||||
),
|
||||
ql.PropertyForTest(
|
||||
getter="getZ", is_total=False, is_indexed=True, type="int"
|
||||
),
|
||||
ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
|
||||
],
|
||||
),
|
||||
"B/B_getX.ql": a_ql_property_tester(
|
||||
class_name="B",
|
||||
property=ql.PropertyForTest(getter="getX", is_total=False, type="string"),
|
||||
),
|
||||
"B/B_getY.ql": a_ql_property_tester(
|
||||
class_name="B",
|
||||
property=ql.PropertyForTest(
|
||||
getter="getY", is_total=False, is_indexed=True, type="bool"
|
||||
),
|
||||
),
|
||||
"B/B_getZ.ql": a_ql_property_tester(
|
||||
class_name="B",
|
||||
property=ql.PropertyForTest(
|
||||
getter="getZ", is_total=False, is_indexed=True, type="int"
|
||||
),
|
||||
),
|
||||
"B/B_getAW.ql": a_ql_property_tester(
|
||||
class_name="B",
|
||||
property=ql.PropertyForTest(getter="getAW", is_total=False, type="string"),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
@@ -1136,15 +1117,11 @@ def test_test_properties_deduplicated(opts, generate_tests):
|
||||
class_name="Final",
|
||||
properties=[
|
||||
ql.PropertyForTest(getter="getX", type="string"),
|
||||
ql.PropertyForTest(getter="getNumberOfYs", type="int"),
|
||||
ql.PropertyForTest(
|
||||
getter="getY", is_total=False, is_indexed=True, type="bool"
|
||||
),
|
||||
],
|
||||
),
|
||||
"Final/Final_getY.ql": a_ql_property_tester(
|
||||
class_name="Final",
|
||||
property=ql.PropertyForTest(
|
||||
getter="getY", is_total=False, is_indexed=True, type="bool"
|
||||
),
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user