Skip to content

Commit

Permalink
Add .testPackageContextDirectory()
Browse files Browse the repository at this point in the history
This checks that the directory contents is accessible.
  • Loading branch information
pcbeard committed Oct 8, 2021
1 parent 93d252e commit 48de506
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions Tests/PackageLoadingTests/PD_5_6_LoadingTests.swift
Expand Up @@ -154,12 +154,11 @@ class PackageDescription5_6LoadingTests: PackageDescriptionLoadingTests {

}

func testPackageContext() throws {
/// Tests use of Context.current.packageDirectory
func testPackageContextName() throws {
let stream = BufferedOutputByteStream()
stream <<< """
import PackageDescription
import Foundation
let package = Package(name: Context.current.packageDirectory)
"""

Expand All @@ -168,4 +167,25 @@ class PackageDescription5_6LoadingTests: PackageDescriptionLoadingTests {
XCTAssertEqual(manifest.name, name)
}
}

/// Tests access to the package's directory contents.
func testPackageContextDirectory() throws {
let stream = BufferedOutputByteStream()
stream <<< """
import PackageDescription
import Foundation
let context = Context.current
let fileManager = FileManager.default
let contents = (try? fileManager.contentsOfDirectory(atPath: context.packageDirectory)) ?? []
let swiftFiles = contents.filter { $0.hasPrefix("TemporaryFile") && $0.hasSuffix(".swift") }
let package = Package(name: swiftFiles[0])
"""

loadManifest(stream.bytes) { manifest in
let name = parsedManifest?.components.last ?? ""
XCTAssertEqual(manifest.name, name)
}
}
}

0 comments on commit 48de506

Please sign in to comment.