Skip to content

Commit e49268d

Browse files
committed
Swift: show QL class in generated tests on collapsed hierarchies
In those kinds of tests the results may have different final classes that are not necessarily visible (or tested) solely through the string representation. For better testing and reading of expected results, `getQlPrimaryClasses` is added in these cases.
1 parent c3968a2 commit e49268d

File tree

10 files changed

+27
-23
lines changed

10 files changed

+27
-23
lines changed

swift/codegen/generators/qlgen.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ def generate(opts, renderer):
304304
total_props, partial_props = _partition(_get_all_properties_to_be_tested(c, data.classes),
305305
lambda p: p.is_single or p.is_predicate)
306306
renderer.render(ql.ClassTester(class_name=c.name,
307-
properties=total_props), test_dir / f"{c.name}.ql")
307+
properties=total_props,
308+
# in case of collapsed hierarchies we want to see the actual QL class in results
309+
show_ql_class="qltest_collapse_hierarchy" in c.pragmas),
310+
test_dir / f"{c.name}.ql")
308311
for p in partial_props:
309312
renderer.render(ql.PropertyTester(class_name=c.name,
310313
property=p), test_dir / f"{c.name}_{p.getter}.ql")

swift/codegen/lib/ql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ class ClassTester:
165165

166166
class_name: str
167167
properties: List[PropertyForTest] = field(default_factory=list)
168+
show_ql_class: bool = False
168169

169170

170171
@dataclass

swift/codegen/templates/ql_test_class.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ and {{getter}} = x.{{getter}}()
1313
and if x.{{getter}}() then {{getter}} = "yes" else {{getter}} = "no"
1414
{{/is_predicate}}
1515
{{/properties}}
16-
select x{{#properties}}, "{{getter}}:", {{getter}}{{/properties}}
16+
select x{{#show_ql_class}}, x.getPrimaryQlClasses(){{/show_ql_class}}{{#properties}}, "{{getter}}:", {{getter}}{{/properties}}

swift/codegen/test/test_qlgen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def test_test_class_hierarchy_collapse(opts, generate_tests):
584584
schema.Class("D2", bases=["Base"], derived={"D3"}, properties=[schema.SingleProperty("y", "string")]),
585585
schema.Class("D3", bases=["D2"], properties=[schema.SingleProperty("z", "string")]),
586586
]) == {
587-
"Base/Base.ql": ql.ClassTester(class_name="Base"),
587+
"Base/Base.ql": ql.ClassTester(class_name="Base", show_ql_class=True),
588588
}
589589

590590

@@ -598,7 +598,7 @@ def test_test_class_hierarchy_uncollapse(opts, generate_tests):
598598
schema.Class("D3", bases=["D2"]),
599599
schema.Class("D4", bases=["D2"]),
600600
]) == {
601-
"Base/Base.ql": ql.ClassTester(class_name="Base"),
601+
"Base/Base.ql": ql.ClassTester(class_name="Base", show_ql_class=True),
602602
"D3/D3.ql": ql.ClassTester(class_name="D3"),
603603
"D4/D4.ql": ql.ClassTester(class_name="D4"),
604604
}
@@ -613,7 +613,7 @@ def test_test_class_hierarchy_uncollapse_at_final(opts, generate_tests):
613613
schema.Class("D2", bases=["Base"], derived={"D3"}),
614614
schema.Class("D3", bases=["D2"], pragmas=["qltest_uncollapse_hierarchy", "bar"]),
615615
]) == {
616-
"Base/Base.ql": ql.ClassTester(class_name="Base"),
616+
"Base/Base.ql": ql.ClassTester(class_name="Base", show_ql_class=True),
617617
"D3/D3.ql": ql.ClassTester(class_name="D3"),
618618
}
619619

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| empty.swift:0:0:0:0 | empty.swift | getName: | empty.swift |
2-
| file://:0:0:0:0 | | getName: | |
3-
| non_empty.swift:0:0:0:0 | non_empty.swift | getName: | non_empty.swift |
1+
| empty.swift:0:0:0:0 | empty.swift | DbFile | getName: | empty.swift |
2+
| file://:0:0:0:0 | | UnknownFile | getName: | |
3+
| non_empty.swift:0:0:0:0 | non_empty.swift | DbFile | getName: | non_empty.swift |

swift/ql/test/extractor-tests/generated/File/File.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ where
77
toBeTested(x) and
88
not x.isUnknown() and
99
getName = x.getName()
10-
select x, "getName:", getName
10+
select x, x.getPrimaryQlClasses(), "getName:", getName
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
| implicit_conversions.swift:2:3:2:3 | (UnsafePointer<CChar>) ... | getSubExpr: | implicit_conversions.swift:2:3:2:3 | Hello |
2-
| implicit_conversions.swift:4:16:4:16 | (Int?) ... | getSubExpr: | implicit_conversions.swift:4:16:4:16 | 42 |
3-
| implicit_conversions.swift:5:25:5:25 | (Equatable) ... | getSubExpr: | implicit_conversions.swift:5:25:5:25 | 42 |
1+
| implicit_conversions.swift:2:3:2:3 | (UnsafePointer<CChar>) ... | StringToPointerExpr | getSubExpr: | implicit_conversions.swift:2:3:2:3 | Hello |
2+
| implicit_conversions.swift:4:16:4:16 | (Int?) ... | InjectIntoOptionalExpr | getSubExpr: | implicit_conversions.swift:4:16:4:16 | 42 |
3+
| implicit_conversions.swift:5:25:5:25 | (Equatable) ... | ErasureExpr | getSubExpr: | implicit_conversions.swift:5:25:5:25 | 42 |

swift/ql/test/extractor-tests/generated/expr/ImplicitConversionExpr/ImplicitConversionExpr.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ where
77
toBeTested(x) and
88
not x.isUnknown() and
99
getSubExpr = x.getSubExpr()
10-
select x, "getSubExpr:", getSubExpr
10+
select x, x.getPrimaryQlClasses(), "getSubExpr:", getSubExpr
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
| Builtin.BridgeObject | getName: | Builtin.BridgeObject | getCanonicalType: | Builtin.BridgeObject |
2-
| Builtin.Executor | getName: | Builtin.Executor | getCanonicalType: | Builtin.Executor |
3-
| Builtin.FPIEEE32 | getName: | Builtin.FPIEEE32 | getCanonicalType: | Builtin.FPIEEE32 |
4-
| Builtin.FPIEEE64 | getName: | Builtin.FPIEEE64 | getCanonicalType: | Builtin.FPIEEE64 |
5-
| Builtin.IntLiteral | getName: | Builtin.IntLiteral | getCanonicalType: | Builtin.IntLiteral |
6-
| Builtin.Job | getName: | Builtin.Job | getCanonicalType: | Builtin.Job |
7-
| Builtin.NativeObject | getName: | Builtin.NativeObject | getCanonicalType: | Builtin.NativeObject |
8-
| Builtin.RawPointer | getName: | Builtin.RawPointer | getCanonicalType: | Builtin.RawPointer |
9-
| Builtin.RawUnsafeContinuation | getName: | Builtin.RawUnsafeContinuation | getCanonicalType: | Builtin.RawUnsafeContinuation |
1+
| Builtin.BridgeObject | BuiltinBridgeObjectType | getName: | Builtin.BridgeObject | getCanonicalType: | Builtin.BridgeObject |
2+
| Builtin.Executor | BuiltinExecutorType | getName: | Builtin.Executor | getCanonicalType: | Builtin.Executor |
3+
| Builtin.FPIEEE32 | BuiltinFloatType | getName: | Builtin.FPIEEE32 | getCanonicalType: | Builtin.FPIEEE32 |
4+
| Builtin.FPIEEE64 | BuiltinFloatType | getName: | Builtin.FPIEEE64 | getCanonicalType: | Builtin.FPIEEE64 |
5+
| Builtin.IntLiteral | BuiltinIntegerLiteralType | getName: | Builtin.IntLiteral | getCanonicalType: | Builtin.IntLiteral |
6+
| Builtin.Job | BuiltinJobType | getName: | Builtin.Job | getCanonicalType: | Builtin.Job |
7+
| Builtin.NativeObject | BuiltinNativeObjectType | getName: | Builtin.NativeObject | getCanonicalType: | Builtin.NativeObject |
8+
| Builtin.RawPointer | BuiltinRawPointerType | getName: | Builtin.RawPointer | getCanonicalType: | Builtin.RawPointer |
9+
| Builtin.RawUnsafeContinuation | BuiltinRawUnsafeContinuationType | getName: | Builtin.RawUnsafeContinuation | getCanonicalType: | Builtin.RawUnsafeContinuation |

swift/ql/test/extractor-tests/generated/type/BuiltinType/BuiltinType.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ where
88
not x.isUnknown() and
99
getName = x.getName() and
1010
getCanonicalType = x.getCanonicalType()
11-
select x, "getName:", getName, "getCanonicalType:", getCanonicalType
11+
select x, x.getPrimaryQlClasses(), "getName:", getName, "getCanonicalType:", getCanonicalType

0 commit comments

Comments
 (0)