Skip to content

Re-revert "Avoid use of temp_await in PackageRegistryToolTests.swift" #7176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions Sources/Basics/Archiver/Archiver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,43 @@ public protocol Archiver {
}

extension Archiver {
/// Asynchronously extracts the contents of an archive to a destination folder.
///
/// - Parameters:
/// - archivePath: The `AbsolutePath` to the archive to extract.
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
public func extract(
from archivePath: AbsolutePath,
to destinationPath: AbsolutePath
) async throws {
try await safe_async {
self.extract(from: archivePath, to: destinationPath, completion: $0)
try await withCheckedThrowingContinuation {
self.extract(from: archivePath, to: destinationPath, completion: $0.resume(with:))
}
}

/// Asynchronously compresses the contents of a directory to a destination archive.
///
/// - Parameters:
/// - directory: The `AbsolutePath` to the archive to extract.
/// - destinationPath: The `AbsolutePath` to the directory to extract to.
public func compress(
directory: AbsolutePath,
to: AbsolutePath
to destinationPath: AbsolutePath
) async throws {
try await safe_async {
self.compress(directory: directory, to: to, completion: $0)
try await withCheckedThrowingContinuation {
self.compress(directory: directory, to: destinationPath, completion: $0.resume(with:))
}
}

/// Asynchronously validates if a file is an archive.
///
/// - Parameters:
/// - path: The `AbsolutePath` to the archive to validate.
public func validate(
path: AbsolutePath
) async throws -> Bool {
try await safe_async {
self.validate(path: path, completion: $0)
try await withCheckedThrowingContinuation {
self.validate(path: path, completion: $0.resume(with:))
}
}
}
22 changes: 11 additions & 11 deletions Tests/CommandsTests/PackageRegistryToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ final class PackageRegistryToolTests: CommandsTestCase {

// TODO: Test example with login and password

func testArchiving() throws {
func testArchiving() async throws {
#if os(Linux)
// needed for archiving
guard SPM_posix_spawn_file_actions_addchdir_np_supported() else {
Expand All @@ -293,7 +293,7 @@ final class PackageRegistryToolTests: CommandsTestCase {
let metadataFilename = SwiftPackageRegistryTool.Publish.metadataFilename

// git repo
try withTemporaryDirectory { temporaryDirectory in
try await withTemporaryDirectory { temporaryDirectory in
let packageDirectory = temporaryDirectory.appending("MyPackage")
try localFileSystem.createDirectory(packageDirectory)

Expand All @@ -320,12 +320,12 @@ final class PackageRegistryToolTests: CommandsTestCase {
observabilityScope: observability.topScope
)

try validatePackageArchive(at: archivePath)
try await validatePackageArchive(at: archivePath)
XCTAssertTrue(archivePath.isDescendant(of: workingDirectory))
}

// not a git repo
try withTemporaryDirectory { temporaryDirectory in
try await withTemporaryDirectory { temporaryDirectory in
let packageDirectory = temporaryDirectory.appending("MyPackage")
try localFileSystem.createDirectory(packageDirectory)

Expand All @@ -350,11 +350,11 @@ final class PackageRegistryToolTests: CommandsTestCase {
observabilityScope: observability.topScope
)

try validatePackageArchive(at: archivePath)
try await validatePackageArchive(at: archivePath)
}

// canonical metadata location
try withTemporaryDirectory { temporaryDirectory in
try await withTemporaryDirectory { temporaryDirectory in
let packageDirectory = temporaryDirectory.appending("MyPackage")
try localFileSystem.createDirectory(packageDirectory)

Expand Down Expand Up @@ -385,17 +385,17 @@ final class PackageRegistryToolTests: CommandsTestCase {
observabilityScope: observability.topScope
)

let extractedPath = try validatePackageArchive(at: archivePath)
let extractedPath = try await validatePackageArchive(at: archivePath)
XCTAssertFileExists(extractedPath.appending(component: metadataFilename))
}

@discardableResult
func validatePackageArchive(at archivePath: AbsolutePath) throws -> AbsolutePath {
func validatePackageArchive(at archivePath: AbsolutePath) async throws -> AbsolutePath {
XCTAssertFileExists(archivePath)
let archiver = ZipArchiver(fileSystem: localFileSystem)
let extractPath = archivePath.parentDirectory.appending(component: UUID().uuidString)
try localFileSystem.createDirectory(extractPath)
try temp_await { archiver.extract(from: archivePath, to: extractPath, completion: $0) }
try await archiver.extract(from: archivePath, to: extractPath)
try localFileSystem.stripFirstLevel(of: extractPath)
XCTAssertFileExists(extractPath.appending("Package.swift"))
return extractPath
Expand Down Expand Up @@ -550,7 +550,7 @@ final class PackageRegistryToolTests: CommandsTestCase {
let archiver = ZipArchiver(fileSystem: localFileSystem)
let extractPath = archivePath.parentDirectory.appending(component: UUID().uuidString)
try localFileSystem.createDirectory(extractPath)
try temp_await { archiver.extract(from: archivePath, to: extractPath, completion: $0) }
try await archiver.extract(from: archivePath, to: extractPath)
try localFileSystem.stripFirstLevel(of: extractPath)

let manifestInArchive = try localFileSystem.readFileContents(extractPath.appending(manifestFile)).contents
Expand Down Expand Up @@ -963,7 +963,7 @@ final class PackageRegistryToolTests: CommandsTestCase {
let archiver = ZipArchiver(fileSystem: localFileSystem)
let extractPath = archivePath.parentDirectory.appending(component: UUID().uuidString)
try localFileSystem.createDirectory(extractPath)
try temp_await { archiver.extract(from: archivePath, to: extractPath, completion: $0) }
try await archiver.extract(from: archivePath, to: extractPath)
try localFileSystem.stripFirstLevel(of: extractPath)

let manifestSignature = try ManifestSignatureParser.parse(
Expand Down