зеркало из https://github.com/github/codeql.git
Codegen: implement `set` in ql test generation
This commit is contained in:
Родитель
d5ee728657
Коммит
d7a3cb2d01
|
@ -256,7 +256,7 @@ def _get_all_properties_to_be_tested(cls: schema.Class, lookup: typing.Dict[str,
|
|||
# TODO here operations are duplicated, but should be better if we split ql and qltest generation
|
||||
p = get_ql_property(c, p)
|
||||
yield ql.PropertyForTest(p.getter, is_total=p.is_single or p.is_predicate,
|
||||
type=p.type if not p.is_predicate else None, is_repeated=p.is_repeated)
|
||||
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:
|
||||
|
|
|
@ -197,7 +197,7 @@ class PropertyForTest:
|
|||
getter: str
|
||||
is_total: bool = True
|
||||
type: Optional[str] = None
|
||||
is_repeated: bool = False
|
||||
is_indexed: bool = False
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
@ -4,7 +4,7 @@ import {{elements_module}}
|
|||
import TestUtils
|
||||
|
||||
{{#property}}
|
||||
from {{class_name}} x{{#is_repeated}}, int index{{/is_repeated}}
|
||||
from {{class_name}} x{{#is_indexed}}, int index{{/is_indexed}}
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, {{#is_repeated}}index, {{/is_repeated}}x.{{getter}}({{#is_repeated}}index{{/is_repeated}})
|
||||
select x, {{#is_indexed}}index, {{/is_indexed}}x.{{getter}}({{#is_indexed}}index{{/is_indexed}})
|
||||
{{/property}}
|
||||
|
|
|
@ -568,23 +568,28 @@ def test_test_partial_properties(opts, generate_tests):
|
|||
schema.Class("B", bases=["A"], properties=[
|
||||
schema.RepeatedProperty("y", "bool"),
|
||||
schema.RepeatedOptionalProperty("z", "int"),
|
||||
schema.RepeatedUnorderedProperty("w", "string"),
|
||||
]),
|
||||
]) == {
|
||||
"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"),
|
||||
]),
|
||||
"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_repeated=True,
|
||||
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_repeated=True,
|
||||
type="int")),
|
||||
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")),
|
||||
}
|
||||
|
||||
|
||||
|
@ -605,7 +610,7 @@ def test_test_properties_deduplicated(opts, generate_tests):
|
|||
]),
|
||||
"Final/Final_getY.ql": a_ql_property_tester(class_name="Final",
|
||||
property=ql.PropertyForTest(getter="getY", is_total=False,
|
||||
is_repeated=True,
|
||||
is_indexed=True,
|
||||
type="bool")),
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче