From af13696f55d4e541368e3bda5bc813fac5430200 Mon Sep 17 00:00:00 2001 From: Brian Croom Date: Mon, 8 Nov 2021 08:58:36 -0800 Subject: [PATCH 1/5] Sync with main to pick up the Swift async symbol property definition. --- Sources/TSCclibc/include/indexstore_functions.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/TSCclibc/include/indexstore_functions.h b/Sources/TSCclibc/include/indexstore_functions.h index fa7384c6..fb8ddab7 100644 --- a/Sources/TSCclibc/include/indexstore_functions.h +++ b/Sources/TSCclibc/include/indexstore_functions.h @@ -168,6 +168,7 @@ typedef enum { INDEXSTORE_SYMBOL_PROPERTY_GKINSPECTABLE = 1 << 6, INDEXSTORE_SYMBOL_PROPERTY_LOCAL = 1 << 7, INDEXSTORE_SYMBOL_PROPERTY_PROTOCOL_INTERFACE = 1 << 8, + INDEXSTORE_SYMBOL_PROPERTY_SWIFT_ASYNC = 1 << 16, } indexstore_symbol_property_t; typedef enum { From abd0ecffec34ce29d7d6b2ea60bd364eceafae97 Mon Sep 17 00:00:00 2001 From: Brian Croom Date: Mon, 8 Nov 2021 09:13:01 -0800 Subject: [PATCH 2/5] Extend `IndexStore.TestCaseClass` to include information about `async` test methods. --- Sources/TSCUtility/IndexStore.swift | 33 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Sources/TSCUtility/IndexStore.swift b/Sources/TSCUtility/IndexStore.swift index bbd8910a..bd2aa13c 100644 --- a/Sources/TSCUtility/IndexStore.swift +++ b/Sources/TSCUtility/IndexStore.swift @@ -14,9 +14,24 @@ import TSCBasic public final class IndexStore { public struct TestCaseClass { + public enum TestMethod: Hashable, Comparable { + case standard(String) + case async(String) + + public var name: String { + switch self { + case .standard(let name): + return name + case .async(let name): + return name + } + } + } + public var name: String public var module: String - public var methods: [String] + public var testMethods: [TestMethod] + @available(*, deprecated, message: "use testMethods instead") public var methods: [String] } fileprivate var impl: IndexStoreImpl { _impl as! IndexStoreImpl } @@ -90,15 +105,16 @@ private final class IndexStoreImpl { let recordReader = try api.call{ fn.record_reader_create(store, record, &$0) } class TestCaseBuilder { - var classToMethods: [String: Set] = [:] + var classToMethods: [String: Set] = [:] - func add(klass: String, method: String) { + func add(klass: String, method: TestCaseClass.TestMethod) { classToMethods[klass, default: []].insert(method) } func build() -> [TestCaseClass] { return classToMethods.map { - TestCaseClass(name: $0.key, module: "", methods: $0.value.sorted()) + let testMethods = Array($0.value).sorted() + return TestCaseClass(name: $0.key, module: "", testMethods: testMethods, methods: testMethods.map(\.name)) } } } @@ -112,9 +128,9 @@ private final class IndexStoreImpl { // Get the symbol. let sym = fn.occurrence_get_symbol(occ) - + let symbolProperties = fn.symbol_get_properties(sym) // We only care about symbols that are marked unit tests and are instance methods. - if fn.symbol_get_properties(sym) != UInt64(INDEXSTORE_SYMBOL_PROPERTY_UNITTEST.rawValue) { + if symbolProperties & UInt64(INDEXSTORE_SYMBOL_PROPERTY_UNITTEST.rawValue) == 0 { return true } if fn.symbol_get_kind(sym) != INDEXSTORE_SYMBOL_KIND_INSTANCEMETHOD { @@ -140,8 +156,9 @@ private final class IndexStoreImpl { } if !className.instance.isEmpty { - let testMethod = fn.symbol_get_name(sym).str - builder.instance.add(klass: className.instance, method: testMethod) + let methodName = fn.symbol_get_name(sym).str + let isAsync = symbolProperties & UInt64(INDEXSTORE_SYMBOL_PROPERTY_SWIFT_ASYNC.rawValue) != 0 + builder.instance.add(klass: className.instance, method: isAsync ? .async(methodName) : .standard(methodName)) } return true From 31a8d9fe772fc55519c6643a4aa2f00ee42b593f Mon Sep 17 00:00:00 2001 From: Brian Croom Date: Tue, 9 Nov 2021 12:30:13 -0800 Subject: [PATCH 3/5] Model as a struct instead of enum for easier future expansion. --- Sources/TSCUtility/IndexStore.swift | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Sources/TSCUtility/IndexStore.swift b/Sources/TSCUtility/IndexStore.swift index bd2aa13c..8d6a1667 100644 --- a/Sources/TSCUtility/IndexStore.swift +++ b/Sources/TSCUtility/IndexStore.swift @@ -14,17 +14,12 @@ import TSCBasic public final class IndexStore { public struct TestCaseClass { - public enum TestMethod: Hashable, Comparable { - case standard(String) - case async(String) - - public var name: String { - switch self { - case .standard(let name): - return name - case .async(let name): - return name - } + public struct TestMethod: Hashable, Comparable { + public let name: String + public let isAsync: Bool + + public static func < (lhs: IndexStore.TestCaseClass.TestMethod, rhs: IndexStore.TestCaseClass.TestMethod) -> Bool { + return lhs.name < rhs.name } } @@ -158,7 +153,7 @@ private final class IndexStoreImpl { if !className.instance.isEmpty { let methodName = fn.symbol_get_name(sym).str let isAsync = symbolProperties & UInt64(INDEXSTORE_SYMBOL_PROPERTY_SWIFT_ASYNC.rawValue) != 0 - builder.instance.add(klass: className.instance, method: isAsync ? .async(methodName) : .standard(methodName)) + builder.instance.add(klass: className.instance, method: TestCaseClass.TestMethod(name: methodName, isAsync: isAsync)) } return true From bfa0465394a54d3bda586f6e9011ba72297c9e4c Mon Sep 17 00:00:00 2001 From: Brian Croom Date: Tue, 9 Nov 2021 12:43:55 -0800 Subject: [PATCH 4/5] Take isAsync into account when comparing. --- Sources/TSCUtility/IndexStore.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/TSCUtility/IndexStore.swift b/Sources/TSCUtility/IndexStore.swift index 8d6a1667..130f644e 100644 --- a/Sources/TSCUtility/IndexStore.swift +++ b/Sources/TSCUtility/IndexStore.swift @@ -19,7 +19,7 @@ public final class IndexStore { public let isAsync: Bool public static func < (lhs: IndexStore.TestCaseClass.TestMethod, rhs: IndexStore.TestCaseClass.TestMethod) -> Bool { - return lhs.name < rhs.name + return (lhs.name, (lhs.isAsync ? 1 : 0)) < (rhs.name, (rhs.isAsync ? 1 : 0)) } } From da1348f034f361db34a504bc237973f2f928646f Mon Sep 17 00:00:00 2001 From: Brian Croom Date: Tue, 9 Nov 2021 14:16:00 -0800 Subject: [PATCH 5/5] Tweak argument name for clarity. --- Sources/TSCUtility/IndexStore.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/TSCUtility/IndexStore.swift b/Sources/TSCUtility/IndexStore.swift index 130f644e..4f70f03d 100644 --- a/Sources/TSCUtility/IndexStore.swift +++ b/Sources/TSCUtility/IndexStore.swift @@ -102,8 +102,8 @@ private final class IndexStoreImpl { class TestCaseBuilder { var classToMethods: [String: Set] = [:] - func add(klass: String, method: TestCaseClass.TestMethod) { - classToMethods[klass, default: []].insert(method) + func add(className: String, method: TestCaseClass.TestMethod) { + classToMethods[className, default: []].insert(method) } func build() -> [TestCaseClass] { @@ -153,7 +153,7 @@ private final class IndexStoreImpl { if !className.instance.isEmpty { let methodName = fn.symbol_get_name(sym).str let isAsync = symbolProperties & UInt64(INDEXSTORE_SYMBOL_PROPERTY_SWIFT_ASYNC.rawValue) != 0 - builder.instance.add(klass: className.instance, method: TestCaseClass.TestMethod(name: methodName, isAsync: isAsync)) + builder.instance.add(className: className.instance, method: TestCaseClass.TestMethod(name: methodName, isAsync: isAsync)) } return true