Skip to content

Commit b4f14fa

Browse files
committed
Move PackageSigningTests to async/await and remove all usages of temp_await
Add async alternatives to PackageSigningEntityStorage Mark non-async methods noasync Improve the fixture method to return the result of the body
1 parent 24929f3 commit b4f14fa

File tree

6 files changed

+311
-243
lines changed

6 files changed

+311
-243
lines changed

Sources/PackageSigning/SigningEntity/PackageSigningEntityStorage.swift

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import struct TSCUtility.Version
2020

2121
public protocol PackageSigningEntityStorage {
2222
/// For a given package, return the signing entities and the package versions that each of them signed.
23+
@available(*, noasync, message: "Use the async alternative")
2324
func get(
2425
package: PackageIdentity,
2526
observabilityScope: ObservabilityScope,
@@ -31,6 +32,7 @@ public protocol PackageSigningEntityStorage {
3132
///
3233
/// This throws `PackageSigningEntityStorageError.conflict` if `signingEntity`
3334
/// of the package version is different from that in storage.
35+
@available(*, noasync, message: "Use the async alternative")
3436
func put(
3537
package: PackageIdentity,
3638
version: Version,
@@ -46,6 +48,7 @@ public protocol PackageSigningEntityStorage {
4648
/// If the package version already has other `SigningEntity`s in storage, this
4749
/// API **adds** `signingEntity` to the package version's signers rather than
4850
/// throwing an error.
51+
@available(*, noasync, message: "Use the async alternative")
4952
func add(
5053
package: PackageIdentity,
5154
version: Version,
@@ -57,6 +60,7 @@ public protocol PackageSigningEntityStorage {
5760
)
5861

5962
/// Make `signingEntity` the package's expected signer starting from the given version.
63+
@available(*, noasync, message: "Use the async alternative")
6064
func changeSigningEntityFromVersion(
6165
package: PackageIdentity,
6266
version: Version,
@@ -71,6 +75,7 @@ public protocol PackageSigningEntityStorage {
7175
///
7276
/// This API deletes all other existing signers from storage, therefore making
7377
/// `signingEntity` the package's sole signer.
78+
@available(*, noasync, message: "Use the async alternative")
7479
func changeSigningEntityForAllVersions(
7580
package: PackageIdentity,
7681
version: Version,
@@ -82,6 +87,107 @@ public protocol PackageSigningEntityStorage {
8287
)
8388
}
8489

90+
public extension PackageSigningEntityStorage {
91+
func get(
92+
package: PackageIdentity,
93+
observabilityScope: ObservabilityScope,
94+
callbackQueue: DispatchQueue
95+
) async throws -> PackageSigners {
96+
try await safe_async {
97+
self.get(
98+
package: package,
99+
observabilityScope: observabilityScope,
100+
callbackQueue: callbackQueue,
101+
callback: $0
102+
)
103+
}
104+
}
105+
106+
func put(
107+
package: PackageIdentity,
108+
version: Version,
109+
signingEntity: SigningEntity,
110+
origin: SigningEntity.Origin,
111+
observabilityScope: ObservabilityScope,
112+
callbackQueue: DispatchQueue
113+
) async throws {
114+
try await safe_async {
115+
self.put(
116+
package: package,
117+
version: version,
118+
signingEntity: signingEntity,
119+
origin: origin,
120+
observabilityScope: observabilityScope,
121+
callbackQueue: callbackQueue,
122+
callback: $0
123+
)
124+
}
125+
}
126+
127+
func add(
128+
package: PackageIdentity,
129+
version: Version,
130+
signingEntity: SigningEntity,
131+
origin: SigningEntity.Origin,
132+
observabilityScope: ObservabilityScope,
133+
callbackQueue: DispatchQueue
134+
) async throws {
135+
try await safe_async {
136+
self.add(
137+
package: package,
138+
version: version,
139+
signingEntity: signingEntity,
140+
origin: origin,
141+
observabilityScope: observabilityScope,
142+
callbackQueue: callbackQueue,
143+
callback: $0
144+
)
145+
}
146+
}
147+
148+
func changeSigningEntityFromVersion(
149+
package: PackageIdentity,
150+
version: Version,
151+
signingEntity: SigningEntity,
152+
origin: SigningEntity.Origin,
153+
observabilityScope: ObservabilityScope,
154+
callbackQueue: DispatchQueue
155+
) async throws {
156+
try await safe_async {
157+
self.changeSigningEntityFromVersion(
158+
package: package,
159+
version: version,
160+
signingEntity: signingEntity,
161+
origin: origin,
162+
observabilityScope: observabilityScope,
163+
callbackQueue: callbackQueue,
164+
callback: $0
165+
)
166+
}
167+
}
168+
169+
func changeSigningEntityForAllVersions(
170+
package: PackageIdentity,
171+
version: Version,
172+
signingEntity: SigningEntity,
173+
origin: SigningEntity.Origin,
174+
observabilityScope: ObservabilityScope,
175+
callbackQueue: DispatchQueue
176+
) async throws {
177+
try await safe_async {
178+
self.changeSigningEntityForAllVersions(
179+
package: package,
180+
version: version,
181+
signingEntity: signingEntity,
182+
origin: origin,
183+
observabilityScope: observabilityScope,
184+
callbackQueue: callbackQueue,
185+
callback: $0
186+
)
187+
}
188+
}
189+
}
190+
85191
// MARK: - Models
86192

87193
extension SigningEntity {

Sources/SPMTestSupport/misc.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,20 @@ public func testWithTemporaryDirectory(
7373
/// The temporary copy is deleted after the block returns. The fixture name may
7474
/// contain `/` characters, which are treated as path separators, exactly as if
7575
/// the name were a relative path.
76-
public func fixture(
76+
public func fixture<T>(
7777
name: String,
7878
createGitRepo: Bool = true,
7979
file: StaticString = #file,
8080
line: UInt = #line,
81-
body: (AbsolutePath) throws -> Void
82-
) throws {
81+
body: (AbsolutePath) throws -> T
82+
) throws -> T {
8383
do {
8484
// Make a suitable test directory name from the fixture subpath.
8585
let fixtureSubpath = try RelativePath(validating: name)
8686
let copyName = fixtureSubpath.components.joined(separator: "_")
8787

8888
// Create a temporary directory for the duration of the block.
89-
try withTemporaryDirectory(prefix: copyName) { tmpDirPath in
89+
return try withTemporaryDirectory(prefix: copyName) { tmpDirPath in
9090

9191
defer {
9292
// Unblock and remove the tmp dir on deinit.
@@ -102,7 +102,7 @@ public func fixture(
102102
// Check that the fixture is really there.
103103
guard localFileSystem.isDirectory(fixtureDir) else {
104104
XCTFail("No such fixture: \(fixtureDir)", file: file, line: line)
105-
return
105+
throw SwiftPMError.packagePathNotFound
106106
}
107107

108108
// The fixture contains either a checkout or just a Git directory.
@@ -116,7 +116,7 @@ public func fixture(
116116
#endif
117117

118118
// Invoke the block, passing it the path of the copied fixture.
119-
try body(dstDir)
119+
return try body(dstDir)
120120
} else {
121121
// Copy each of the package directories and construct a git repo in it.
122122
for fileName in try localFileSystem.getDirectoryContents(fixtureDir).sorted() {
@@ -134,7 +134,7 @@ public func fixture(
134134
}
135135

136136
// Invoke the block, passing it the path of the copied fixture.
137-
try body(tmpDirPath)
137+
return try body(tmpDirPath)
138138
}
139139
}
140140
} catch SwiftPMError.executionFailure(let error, let output, let stderr) {

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ final class PackageToolTests: CommandsTestCase {
944944
}
945945

946946
func testPinning() throws {
947-
try fixture(name: "Miscellaneous/PackageEdit") { fixturePath in
947+
let _: Void = try fixture(name: "Miscellaneous/PackageEdit") { fixturePath in
948948
let fooPath = fixturePath.appending("foo")
949949
func build() throws -> String {
950950
return try SwiftPM.Build.execute(packagePath: fooPath).stdout

Tests/FunctionalTests/DependencyResolutionTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DependencyResolutionTests: XCTestCase {
2929
}
3030

3131
func testInternalExecAsDep() throws {
32-
try fixture(name: "DependencyResolution/Internal/InternalExecutableAsDependency") { fixturePath in
32+
_ = try fixture(name: "DependencyResolution/Internal/InternalExecutableAsDependency") { fixturePath in
3333
XCTAssertBuildFails(fixturePath)
3434
}
3535
}
@@ -139,7 +139,7 @@ class DependencyResolutionTests: XCTestCase {
139139
}
140140

141141
func testPackageLookupCaseInsensitive() throws {
142-
try fixture(name: "DependencyResolution/External/PackageLookupCaseInsensitive") { fixturePath in
142+
_ = try fixture(name: "DependencyResolution/External/PackageLookupCaseInsensitive") { fixturePath in
143143
try SwiftPM.Package.execute(["update"], packagePath: fixturePath.appending("pkg"))
144144
}
145145
}

0 commit comments

Comments
 (0)