зеркало из https://github.com/github/codeql.git
Codegen: add `@qltest.test_with`
This allows to group together related AST classes to reuse the same test source and extraction. For example this is useful for `EnumDecl/EnumCaseDecl/EnumElementDecl`, where this is applied to.
This commit is contained in:
Родитель
319b799f95
Коммит
7cc20587ad
|
@ -381,7 +381,8 @@ def generate(opts, renderer):
|
|||
for c in data.classes.values():
|
||||
if _should_skip_qltest(c, data.classes):
|
||||
continue
|
||||
test_dir = test_out / c.group / c.name
|
||||
test_with = data.classes[c.test_with] if c.test_with else c
|
||||
test_dir = test_out / test_with.group / test_with.name
|
||||
test_dir.mkdir(parents=True, exist_ok=True)
|
||||
if all(f.suffix in (".txt", ".ql", ".actual", ".expected") for f in test_dir.glob("*.*")):
|
||||
log.warning(f"no test source in {test_dir.relative_to(test_out)}")
|
||||
|
|
|
@ -93,6 +93,7 @@ class Class:
|
|||
doc: List[str] = field(default_factory=list)
|
||||
default_doc_name: Optional[str] = None
|
||||
hideable: bool = False
|
||||
test_with: Optional[str] = None
|
||||
|
||||
@property
|
||||
def final(self):
|
||||
|
@ -110,6 +111,7 @@ class Class:
|
|||
if self.synth.on_arguments is not None:
|
||||
for t in self.synth.on_arguments.values():
|
||||
_check_type(t, known)
|
||||
_check_type(self.test_with, known)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
|
|
@ -148,6 +148,7 @@ use_for_null = _annotate(null=True)
|
|||
_Pragma("qltest_skip")
|
||||
_Pragma("qltest_collapse_hierarchy")
|
||||
_Pragma("qltest_uncollapse_hierarchy")
|
||||
qltest.test_with = lambda cls: _annotate(test_with=cls)
|
||||
|
||||
ql.default_doc_name = lambda doc: _annotate(doc_name=doc)
|
||||
ql.hideable = _annotate(hideable=True)
|
||||
|
|
|
@ -19,6 +19,14 @@ class _PropertyNamer(schema.PropertyModifier):
|
|||
prop.name = self.name.rstrip("_")
|
||||
|
||||
|
||||
def _get_name(x: str | type | None):
|
||||
if x is None:
|
||||
return None
|
||||
if isinstance(x, str):
|
||||
return x
|
||||
return x.__name__
|
||||
|
||||
|
||||
def _get_class(cls: type) -> schema.Class:
|
||||
if not isinstance(cls, type):
|
||||
raise schema.Error(f"Only class definitions allowed in schema, found {cls}")
|
||||
|
@ -38,6 +46,7 @@ def _get_class(cls: type) -> schema.Class:
|
|||
# getattr to inherit from bases
|
||||
group=getattr(cls, "_group", ""),
|
||||
hideable=getattr(cls, "_hideable", False),
|
||||
test_with=_get_name(getattr(cls, "_test_with", None)),
|
||||
# in the following we don't use `getattr` to avoid inheriting
|
||||
pragmas=cls.__dict__.get("_pragmas", []),
|
||||
synth=cls.__dict__.get("_synth", None),
|
||||
|
@ -107,6 +116,13 @@ def _fill_hideable_information(classes: typing.Dict[str, schema.Class]):
|
|||
todo.append(supercls)
|
||||
|
||||
|
||||
def _check_test_with(classes: typing.Dict[str, schema.Class]):
|
||||
for cls in classes.values():
|
||||
if cls.test_with is not None and classes[cls.test_with].test_with is not None:
|
||||
raise schema.Error(f"{cls.name} has test_with {cls.test_with} which in turn "
|
||||
f"has test_with {classes[cls.test_with].test_with}, use that directly")
|
||||
|
||||
|
||||
def load(m: types.ModuleType) -> schema.Schema:
|
||||
includes = set()
|
||||
classes = {}
|
||||
|
@ -136,6 +152,7 @@ def load(m: types.ModuleType) -> schema.Schema:
|
|||
|
||||
_fill_synth_information(classes)
|
||||
_fill_hideable_information(classes)
|
||||
_check_test_with(classes)
|
||||
|
||||
return schema.Schema(includes=includes, classes=_toposort_classes_by_group(classes), null=null)
|
||||
|
||||
|
|
|
@ -688,6 +688,18 @@ def test_test_class_hierarchy_uncollapse_at_final(opts, generate_tests):
|
|||
}
|
||||
|
||||
|
||||
def test_test_with(opts, generate_tests):
|
||||
write(opts.ql_test_output / "B" / "test.swift")
|
||||
assert generate_tests([
|
||||
schema.Class("Base", derived={"A", "B"}),
|
||||
schema.Class("A", bases=["Base"], test_with="B"),
|
||||
schema.Class("B", bases=["Base"]),
|
||||
]) == {
|
||||
"B/A.ql": a_ql_class_tester(class_name="A"),
|
||||
"B/B.ql": a_ql_class_tester(class_name="B"),
|
||||
}
|
||||
|
||||
|
||||
def test_property_description(generate_classes):
|
||||
description = ["Lorem", "Ipsum"]
|
||||
assert generate_classes([
|
||||
|
|
|
@ -727,5 +727,83 @@ def test_hideable():
|
|||
}
|
||||
|
||||
|
||||
def test_test_with():
|
||||
@load
|
||||
class data:
|
||||
class Root:
|
||||
pass
|
||||
|
||||
class A(Root):
|
||||
pass
|
||||
|
||||
@defs.qltest.test_with(A)
|
||||
class B(Root):
|
||||
pass
|
||||
|
||||
@defs.qltest.test_with("D")
|
||||
class C(Root):
|
||||
pass
|
||||
|
||||
class D(Root):
|
||||
pass
|
||||
|
||||
assert data.classes == {
|
||||
"Root": schema.Class("Root", derived=set("ABCD")),
|
||||
"A": schema.Class("A", bases=["Root"]),
|
||||
"B": schema.Class("B", bases=["Root"], test_with="A"),
|
||||
"C": schema.Class("C", bases=["Root"], test_with="D"),
|
||||
"D": schema.Class("D", bases=["Root"]),
|
||||
}
|
||||
|
||||
|
||||
def test_test_with_unknown_string():
|
||||
with pytest.raises(schema.Error):
|
||||
@load
|
||||
class data:
|
||||
class Root:
|
||||
pass
|
||||
|
||||
@defs.qltest.test_with("B")
|
||||
class A(Root):
|
||||
pass
|
||||
|
||||
|
||||
def test_test_with_unknown_class():
|
||||
with pytest.raises(schema.Error):
|
||||
class B:
|
||||
pass
|
||||
|
||||
@load
|
||||
class data:
|
||||
class Root:
|
||||
pass
|
||||
|
||||
@defs.qltest.test_with(B)
|
||||
class A(Root):
|
||||
pass
|
||||
|
||||
|
||||
def test_test_with_double():
|
||||
with pytest.raises(schema.Error):
|
||||
class B:
|
||||
pass
|
||||
|
||||
@load
|
||||
class data:
|
||||
class Root:
|
||||
pass
|
||||
|
||||
class A(Root):
|
||||
pass
|
||||
|
||||
@defs.qltest.test_with("C")
|
||||
class B(Root):
|
||||
pass
|
||||
|
||||
@defs.qltest.test_with(A)
|
||||
class C(Root):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(pytest.main([__file__] + sys.argv[1:]))
|
||||
|
|
|
@ -690,12 +690,16 @@ test/extractor-tests/generated/decl/ConcreteVarDecl/ConcreteVarDecl_getPropertyW
|
|||
test/extractor-tests/generated/decl/ConcreteVarDecl/ConcreteVarDecl_getPropertyWrapperProjectionVar.ql 502a76b34c78d3cf8f38969671840dc9e28d478ba7afe671963145ba4dc9460d 6125a91820b6b8d139392c32478383e52e40e572e0f92a32f0e513409d2c4e11
|
||||
test/extractor-tests/generated/decl/ConcreteVarDecl/ConcreteVarDecl_getPropertyWrapperProjectionVarBinding.ql 40274aac8b67cb6a285bf91ccdc725ae1556b13ebcc6854a43e759b029733687 44e569aac32148bcce4cd5e8ebb33d7418580b7f5f03dfbd18635db9965b28d9
|
||||
test/extractor-tests/generated/decl/Deinitializer/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
|
||||
test/extractor-tests/generated/decl/EnumCaseDecl/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl.ql 0a06a7923e20b2eca83c5beae58227b63441a0ab1bc971ed03e699c0fe970dbf 2a4995d66f65c402f03482eb2ed205a21b17d49a43c7343f191a5d5e90e003fd
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getElement.ql b8393876ba8b24a0cae892ab5545971fcdae83f3bcae1129176269c0257d665e 09070c34d69667f761d6d2c4496f42322721188dc614f95ebdaad8abe5d70ba9
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getMember.ql 1e235193d7e4cbcdeb4f9e07448c391dc612bd97d58d9c6ad4d8880c6cf74a81 06840a76c0dd22c94aa51299d1f6d014ccd19dd6fbd82eaef1b01e2998b2c694
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumDecl.ql b0befc31c0f68c850cc00ceb7e1c051d930d5cfffc03b5f871de62103425b6d1 13ead91987d0da290a1e3f3e3c9e59df6aaded94e8de2f486c00a9c76706dabb
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumDecl_getGenericTypeParam.ql 3a0927f87a21d69bfc309f5f7faedb3d0cc2956c071b16c38b2b4acd36f24ea9 aafed56a1744579f05b3817adef6a5fd011d1b5cb7da2db230a43b6f55a04649
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumDecl_getInheritedType.ql abb969cd2200a8a7fd39b25ae6a7b6f75fdb6b359c1565e35b18dbe550cbc815 e7b69579675d3bccfe08f1bc1e0bbe5379fb7411597a9d6387f4b7afc8d7dba3
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumDecl_getMember.ql 621870b7dbeaeefa93cbbfc102e97810b15d39b49db685019c9e3cbf2423ffef e110630f0ba8f588e7f8ebc56a1a31c2ca2f22f2cc763baa76854beb3b3a4ece
|
||||
test/extractor-tests/generated/decl/EnumElementDecl/MISSING_SOURCE.txt 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7 66846d526b0bc4328735c3c4dd9c390a9325da5b5dfd42ec07622f9c7108a7d7
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl.ql 9cc76d4ca7d92bc7d3a25283671863cf3cd71424ba84e51bc640a87b4ef98a66 b77a2d5565e44655d10d2162ef5fa4f8053567449fb8200fdd6dbe4ddfa6c8cf
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getMember.ql 316dd1e14b391a242312856143268d8c2f7936b4767f1f2ff2392abeabce2f5e 47813172cb466cf2ec5a321f3ac90b2560b3017f75f329a75b64613ef224775d
|
||||
test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getParam.ql 0f1404a17c9238eae90edb4d13abf6bca4d58ddbad68ed28759110989ecd45af 42a67bcd861f19eb38dc67a4e6b1dc693c2c49477aeb3c91d4e8c505dd1ee1a5
|
||||
test/extractor-tests/generated/decl/ExtensionDecl/ExtensionDecl.ql 71523b034d2abc6225f433f140841a35a466e82c04cbf07bdb3a9e384024fedb 919c66eeff004324b48249fd746c38891f6f8723f1281ad60126cf4b3c1febe0
|
||||
test/extractor-tests/generated/decl/ExtensionDecl/ExtensionDecl_getGenericTypeParam.ql e8c9815756cd3d82abfb421b1e38d6381e48938a21f798fd9abd93686acc070b 2574ead6e511f41ba416e831e176ecdaac27dde410157a4ee472a680f922dd20
|
||||
test/extractor-tests/generated/decl/ExtensionDecl/ExtensionDecl_getMember.ql 8d1c6a2b7cb381a81d11775f0d1cfb13ee04dd27dc742e00a72d676f21481dde 430e5b9ed7eccd90383e362ffa5e512704883304c711b13c9110a57ae282bb40
|
||||
|
|
|
@ -692,12 +692,16 @@
|
|||
/test/extractor-tests/generated/decl/ConcreteVarDecl/ConcreteVarDecl_getPropertyWrapperProjectionVar.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/ConcreteVarDecl/ConcreteVarDecl_getPropertyWrapperProjectionVarBinding.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/Deinitializer/MISSING_SOURCE.txt linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumCaseDecl/MISSING_SOURCE.txt linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getElement.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getMember.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumDecl.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumDecl_getGenericTypeParam.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumDecl_getInheritedType.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumDecl_getMember.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumElementDecl/MISSING_SOURCE.txt linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getMember.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getParam.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/ExtensionDecl/ExtensionDecl.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/ExtensionDecl/ExtensionDecl_getGenericTypeParam.ql linguist-generated
|
||||
/test/extractor-tests/generated/decl/ExtensionDecl/ExtensionDecl_getMember.ql linguist-generated
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
// generated by codegen/codegen.py
|
||||
|
||||
After a source file is added in this directory and codegen/codegen.py is run again, test queries
|
||||
will appear and this file will be deleted
|
|
@ -0,0 +1,12 @@
|
|||
| enums.swift:2:5:2:18 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 2 |
|
||||
| enums.swift:3:5:3:26 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 3 |
|
||||
| enums.swift:8:5:8:18 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 2 |
|
||||
| enums.swift:9:5:9:26 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 3 |
|
||||
| enums.swift:13:5:13:22 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
||||
| enums.swift:14:5:14:21 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
||||
| enums.swift:15:5:15:35 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
||||
| enums.swift:19:5:19:10 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
||||
| enums.swift:20:5:20:16 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
||||
| enums.swift:24:5:24:25 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
||||
| enums.swift:25:5:25:24 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
||||
| enums.swift:26:5:26:44 | case ... | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getNumberOfElements: | 1 |
|
13
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl.ql
сгенерированный
Normal file
13
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl.ql
сгенерированный
Normal file
|
@ -0,0 +1,13 @@
|
|||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from EnumCaseDecl x, ModuleDecl getModule, int getNumberOfMembers, int getNumberOfElements
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
getModule = x.getModule() and
|
||||
getNumberOfMembers = x.getNumberOfMembers() and
|
||||
getNumberOfElements = x.getNumberOfElements()
|
||||
select x, "getModule:", getModule, "getNumberOfMembers:", getNumberOfMembers,
|
||||
"getNumberOfElements:", getNumberOfElements
|
|
@ -0,0 +1,18 @@
|
|||
| enums.swift:2:5:2:18 | case ... | 0 | enums.swift:2:10:2:10 | value1 |
|
||||
| enums.swift:2:5:2:18 | case ... | 1 | enums.swift:2:18:2:18 | value2 |
|
||||
| enums.swift:3:5:3:26 | case ... | 0 | enums.swift:3:10:3:10 | value3 |
|
||||
| enums.swift:3:5:3:26 | case ... | 1 | enums.swift:3:18:3:18 | value4 |
|
||||
| enums.swift:3:5:3:26 | case ... | 2 | enums.swift:3:26:3:26 | value5 |
|
||||
| enums.swift:8:5:8:18 | case ... | 0 | enums.swift:8:10:8:10 | value1 |
|
||||
| enums.swift:8:5:8:18 | case ... | 1 | enums.swift:8:18:8:18 | value2 |
|
||||
| enums.swift:9:5:9:26 | case ... | 0 | enums.swift:9:10:9:10 | value3 |
|
||||
| enums.swift:9:5:9:26 | case ... | 1 | enums.swift:9:18:9:18 | value4 |
|
||||
| enums.swift:9:5:9:26 | case ... | 2 | enums.swift:9:26:9:26 | value5 |
|
||||
| enums.swift:13:5:13:22 | case ... | 0 | enums.swift:13:10:13:22 | nodata1 |
|
||||
| enums.swift:14:5:14:21 | case ... | 0 | enums.swift:14:10:14:21 | intdata |
|
||||
| enums.swift:15:5:15:35 | case ... | 0 | enums.swift:15:10:15:35 | tuple |
|
||||
| enums.swift:19:5:19:10 | case ... | 0 | enums.swift:19:10:19:10 | none |
|
||||
| enums.swift:20:5:20:16 | case ... | 0 | enums.swift:20:10:20:16 | some |
|
||||
| enums.swift:24:5:24:25 | case ... | 0 | enums.swift:24:10:24:25 | nodata1 |
|
||||
| enums.swift:25:5:25:24 | case ... | 0 | enums.swift:25:10:25:24 | intdata |
|
||||
| enums.swift:26:5:26:44 | case ... | 0 | enums.swift:26:10:26:44 | tuple |
|
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getElement.ql
сгенерированный
Normal file
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getElement.ql
сгенерированный
Normal file
|
@ -0,0 +1,7 @@
|
|||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from EnumCaseDecl x, int index
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, index, x.getElement(index)
|
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getMember.ql
сгенерированный
Normal file
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumCaseDecl_getMember.ql
сгенерированный
Normal file
|
@ -0,0 +1,7 @@
|
|||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from EnumCaseDecl x, int index
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, index, x.getMember(index)
|
|
@ -2,3 +2,4 @@
|
|||
| enums.swift:7:1:10:1 | EnumValuesWithBase | getNumberOfGenericTypeParams: | 0 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 11 | getInterfaceType: | EnumValuesWithBase.Type | getName: | EnumValuesWithBase | getNumberOfInheritedTypes: | 1 | getType: | EnumValuesWithBase |
|
||||
| enums.swift:12:1:16:1 | EnumWithParams | getNumberOfGenericTypeParams: | 0 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 6 | getInterfaceType: | EnumWithParams.Type | getName: | EnumWithParams | getNumberOfInheritedTypes: | 0 | getType: | EnumWithParams |
|
||||
| enums.swift:18:1:21:1 | GenericEnum | getNumberOfGenericTypeParams: | 1 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 4 | getInterfaceType: | GenericEnum<T>.Type | getName: | GenericEnum | getNumberOfInheritedTypes: | 0 | getType: | GenericEnum |
|
||||
| enums.swift:23:1:27:1 | EnumWithNamedParams | getNumberOfGenericTypeParams: | 0 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 6 | getInterfaceType: | EnumWithNamedParams.Type | getName: | EnumWithNamedParams | getNumberOfInheritedTypes: | 0 | getType: | EnumWithNamedParams |
|
||||
|
|
|
@ -30,3 +30,9 @@
|
|||
| enums.swift:18:1:21:1 | GenericEnum | 1 | enums.swift:19:10:19:10 | none |
|
||||
| enums.swift:18:1:21:1 | GenericEnum | 2 | enums.swift:20:5:20:16 | case ... |
|
||||
| enums.swift:18:1:21:1 | GenericEnum | 3 | enums.swift:20:10:20:16 | some |
|
||||
| enums.swift:23:1:27:1 | EnumWithNamedParams | 0 | enums.swift:24:5:24:25 | case ... |
|
||||
| enums.swift:23:1:27:1 | EnumWithNamedParams | 1 | enums.swift:24:10:24:25 | nodata1 |
|
||||
| enums.swift:23:1:27:1 | EnumWithNamedParams | 2 | enums.swift:25:5:25:24 | case ... |
|
||||
| enums.swift:23:1:27:1 | EnumWithNamedParams | 3 | enums.swift:25:10:25:24 | intdata |
|
||||
| enums.swift:23:1:27:1 | EnumWithNamedParams | 4 | enums.swift:26:5:26:44 | case ... |
|
||||
| enums.swift:23:1:27:1 | EnumWithNamedParams | 5 | enums.swift:26:10:26:44 | tuple |
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
| enums.swift:2:10:2:10 | value1 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValues.Type) -> EnumValues | getName: | value1 | getNumberOfParams: | 0 |
|
||||
| enums.swift:2:18:2:18 | value2 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValues.Type) -> EnumValues | getName: | value2 | getNumberOfParams: | 0 |
|
||||
| enums.swift:3:10:3:10 | value3 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValues.Type) -> EnumValues | getName: | value3 | getNumberOfParams: | 0 |
|
||||
| enums.swift:3:18:3:18 | value4 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValues.Type) -> EnumValues | getName: | value4 | getNumberOfParams: | 0 |
|
||||
| enums.swift:3:26:3:26 | value5 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValues.Type) -> EnumValues | getName: | value5 | getNumberOfParams: | 0 |
|
||||
| enums.swift:8:10:8:10 | value1 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValuesWithBase.Type) -> EnumValuesWithBase | getName: | value1 | getNumberOfParams: | 0 |
|
||||
| enums.swift:8:18:8:18 | value2 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValuesWithBase.Type) -> EnumValuesWithBase | getName: | value2 | getNumberOfParams: | 0 |
|
||||
| enums.swift:9:10:9:10 | value3 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValuesWithBase.Type) -> EnumValuesWithBase | getName: | value3 | getNumberOfParams: | 0 |
|
||||
| enums.swift:9:18:9:18 | value4 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValuesWithBase.Type) -> EnumValuesWithBase | getName: | value4 | getNumberOfParams: | 0 |
|
||||
| enums.swift:9:26:9:26 | value5 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumValuesWithBase.Type) -> EnumValuesWithBase | getName: | value5 | getNumberOfParams: | 0 |
|
||||
| enums.swift:13:10:13:22 | nodata1 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumWithParams.Type) -> (Void) -> EnumWithParams | getName: | nodata1 | getNumberOfParams: | 1 |
|
||||
| enums.swift:14:10:14:21 | intdata | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumWithParams.Type) -> (Int) -> EnumWithParams | getName: | intdata | getNumberOfParams: | 1 |
|
||||
| enums.swift:15:10:15:35 | tuple | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumWithParams.Type) -> (Int, String, Double) -> EnumWithParams | getName: | tuple | getNumberOfParams: | 3 |
|
||||
| enums.swift:19:10:19:10 | none | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | <T> (GenericEnum<T>.Type) -> GenericEnum<T> | getName: | none | getNumberOfParams: | 0 |
|
||||
| enums.swift:20:10:20:16 | some | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | <T> (GenericEnum<T>.Type) -> (T) -> GenericEnum<T> | getName: | some | getNumberOfParams: | 1 |
|
||||
| enums.swift:24:10:24:25 | nodata1 | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumWithNamedParams.Type) -> (Void) -> EnumWithNamedParams | getName: | nodata1 | getNumberOfParams: | 1 |
|
||||
| enums.swift:25:10:25:24 | intdata | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumWithNamedParams.Type) -> (Int) -> EnumWithNamedParams | getName: | intdata | getNumberOfParams: | 1 |
|
||||
| enums.swift:26:10:26:44 | tuple | getModule: | file://:0:0:0:0 | enums | getNumberOfMembers: | 0 | getInterfaceType: | (EnumWithNamedParams.Type) -> (Int, String, Double) -> EnumWithNamedParams | getName: | tuple | getNumberOfParams: | 3 |
|
17
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl.ql
сгенерированный
Normal file
17
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl.ql
сгенерированный
Normal file
|
@ -0,0 +1,17 @@
|
|||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from
|
||||
EnumElementDecl x, ModuleDecl getModule, int getNumberOfMembers, Type getInterfaceType,
|
||||
string getName, int getNumberOfParams
|
||||
where
|
||||
toBeTested(x) and
|
||||
not x.isUnknown() and
|
||||
getModule = x.getModule() and
|
||||
getNumberOfMembers = x.getNumberOfMembers() and
|
||||
getInterfaceType = x.getInterfaceType() and
|
||||
getName = x.getName() and
|
||||
getNumberOfParams = x.getNumberOfParams()
|
||||
select x, "getModule:", getModule, "getNumberOfMembers:", getNumberOfMembers, "getInterfaceType:",
|
||||
getInterfaceType, "getName:", getName, "getNumberOfParams:", getNumberOfParams
|
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getMember.ql
сгенерированный
Normal file
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getMember.ql
сгенерированный
Normal file
|
@ -0,0 +1,7 @@
|
|||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from EnumElementDecl x, int index
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, index, x.getMember(index)
|
|
@ -0,0 +1,11 @@
|
|||
| enums.swift:13:10:13:22 | nodata1 | 0 | enums.swift:13:18:13:18 | _ |
|
||||
| enums.swift:14:10:14:21 | intdata | 0 | enums.swift:14:18:14:18 | _ |
|
||||
| enums.swift:15:10:15:35 | tuple | 0 | enums.swift:15:16:15:16 | _ |
|
||||
| enums.swift:15:10:15:35 | tuple | 1 | enums.swift:15:21:15:21 | _ |
|
||||
| enums.swift:15:10:15:35 | tuple | 2 | enums.swift:15:29:15:29 | _ |
|
||||
| enums.swift:20:10:20:16 | some | 0 | enums.swift:20:15:20:15 | _ |
|
||||
| enums.swift:24:10:24:25 | nodata1 | 0 | enums.swift:24:18:24:21 | v |
|
||||
| enums.swift:25:10:25:24 | intdata | 0 | enums.swift:25:18:25:21 | i |
|
||||
| enums.swift:26:10:26:44 | tuple | 0 | enums.swift:26:16:26:19 | i |
|
||||
| enums.swift:26:10:26:44 | tuple | 1 | enums.swift:26:24:26:27 | s |
|
||||
| enums.swift:26:10:26:44 | tuple | 2 | enums.swift:26:35:26:38 | d |
|
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getParam.ql
сгенерированный
Normal file
7
swift/ql/test/extractor-tests/generated/decl/EnumDecl/EnumElementDecl_getParam.ql
сгенерированный
Normal file
|
@ -0,0 +1,7 @@
|
|||
// generated by codegen/codegen.py
|
||||
import codeql.swift.elements
|
||||
import TestUtils
|
||||
|
||||
from EnumElementDecl x, int index
|
||||
where toBeTested(x) and not x.isUnknown()
|
||||
select x, index, x.getParam(index)
|
|
@ -19,3 +19,9 @@ enum GenericEnum<T> {
|
|||
case none
|
||||
case some(T)
|
||||
}
|
||||
|
||||
enum EnumWithNamedParams {
|
||||
case nodata1(v: Void)
|
||||
case intdata(i: Int)
|
||||
case tuple(i: Int, s: String, d: Double)
|
||||
}
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
// generated by codegen/codegen.py
|
||||
|
||||
After a source file is added in this directory and codegen/codegen.py is run again, test queries
|
||||
will appear and this file will be deleted
|
|
@ -107,6 +107,7 @@ class Stmt(AstNode):
|
|||
class GenericContext(Element):
|
||||
generic_type_params: list["GenericTypeParamDecl"] | child
|
||||
|
||||
@qltest.test_with("EnumDecl")
|
||||
class EnumCaseDecl(Decl):
|
||||
elements: list["EnumElementDecl"]
|
||||
|
||||
|
@ -247,6 +248,7 @@ class Callable(Element):
|
|||
class Function(GenericContext, ValueDecl, Callable):
|
||||
pass
|
||||
|
||||
@qltest.test_with("EnumDecl")
|
||||
class EnumElementDecl(ValueDecl):
|
||||
name: string
|
||||
params: list[ParamDecl] | child
|
||||
|
|
Загрузка…
Ссылка в новой задаче