Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
tomerd committed Nov 18, 2022
1 parent fc2121e commit f3a4016
Show file tree
Hide file tree
Showing 43 changed files with 539 additions and 538 deletions.
2 changes: 1 addition & 1 deletion Sources/Build/LLBuildManifestBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ extension LLBuildManifestBuilder {

var outputs: [Node] = []

let infoPlistDestination = try! RelativePath(validating: "Info.plist") //try! safe
let infoPlistDestination = RelativePath(static: "Info.plist")

// Create a copy command for each resource file.
for resource in target.resources {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PackageLoading/TargetSourcesBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public struct TargetSourcesBuilder {
}

private func diagnoseInfoPlistConflicts(in resources: [Resource]) {
let infoPlist = try! RelativePath(validating: "Info.plist")
let infoPlist = RelativePath(static: "Info.plist")
for resource in resources {
if resource.destination == infoPlist {
self.observabilityScope.emit(.infoPlistResourceConflict(
Expand Down
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/InMemoryGitRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ extension InMemoryGitRepository: FileSystem {
}

public var currentWorkingDirectory: AbsolutePath? {
return AbsolutePath(path: "/")
return AbsolutePath(static: "/")
}

public func changeCurrentWorkingDirectory(to path: AbsolutePath) throws {
Expand Down
12 changes: 6 additions & 6 deletions Sources/SPMTestSupport/SwiftPMProduct.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ public enum SwiftPMProduct: Product {
public var exec: RelativePath {
switch self {
case .SwiftBuild:
return try! RelativePath(validating: "swift-build") //try! safe
return RelativePath(static: "swift-build")
case .SwiftPackage:
return try! RelativePath(validating: "swift-package") //try! safe
return RelativePath(static: "swift-package")
case .SwiftPackageRegistry:
return try! RelativePath(validating: "swift-package-registry") //try! safe
return RelativePath(static: "swift-package-registry")
case .SwiftTest:
return try! RelativePath(validating: "swift-test") //try! safe
return RelativePath(static: "swift-test")
case .SwiftRun:
return try! RelativePath(validating: "swift-run") //try! safe
return RelativePath(static: "swift-run")
case .XCTestHelper:
return try! RelativePath(validating: "swiftpm-xctest-helper") //try! safe
return RelativePath(static: "swiftpm-xctest-helper")
}
}
}
2 changes: 1 addition & 1 deletion Sources/SPMTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public func fixture(

// Construct the expected path of the fixture.
// FIXME: This seems quite hacky; we should provide some control over where fixtures are found.
let fixtureDir = AbsolutePath(path: "../../../Fixtures", relativeTo: AbsolutePath(path: #file)).appending(fixtureSubpath)
let fixtureDir = AbsolutePath(static: "../../../Fixtures", relativeTo: AbsolutePath(path: #file)).appending(fixtureSubpath)

// Check that the fixture is really there.
guard localFileSystem.isDirectory(fixtureDir) else {
Expand Down
2 changes: 1 addition & 1 deletion Tests/BasicsTests/FileSystemTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class FileSystemTests: XCTestCase {
func testStripFirstLevelComponent() throws {
let fileSystem = InMemoryFileSystem()

let rootPath = AbsolutePath(path: "/root")
let rootPath = AbsolutePath(static: "/root")
try fileSystem.createDirectory(rootPath)

let totalDirectories = Int.random(in: 0 ..< 100)
Expand Down
36 changes: 18 additions & 18 deletions Tests/BasicsTests/VFSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,62 +56,62 @@ class VFSTests: XCTestCase {
let vfs = try VirtualFileSystem(path: vfsPath.path, fs: fs)

// exists()
XCTAssertTrue(vfs.exists(AbsolutePath(path: "/")))
XCTAssertFalse(vfs.exists(AbsolutePath(path: "/does-not-exist")))
XCTAssertTrue(vfs.exists(AbsolutePath(static: "/")))
XCTAssertFalse(vfs.exists(AbsolutePath(static: "/does-not-exist")))

// isFile()
let filePath = AbsolutePath(path: "/best")
let filePath = AbsolutePath(static: "/best")
XCTAssertTrue(vfs.exists(filePath))
XCTAssertTrue(vfs.isFile(filePath))
XCTAssertEqual(try vfs.getFileInfo(filePath).fileType, .typeRegular)
XCTAssertFalse(vfs.isDirectory(filePath))
XCTAssertFalse(vfs.isFile(AbsolutePath(path: "/does-not-exist")))
XCTAssertFalse(vfs.isSymlink(AbsolutePath(path: "/does-not-exist")))
XCTAssertThrowsError(try vfs.getFileInfo(AbsolutePath(path: "/does-not-exist")))
XCTAssertFalse(vfs.isFile(AbsolutePath(static: "/does-not-exist")))
XCTAssertFalse(vfs.isSymlink(AbsolutePath(static: "/does-not-exist")))
XCTAssertThrowsError(try vfs.getFileInfo(AbsolutePath(static: "/does-not-exist")))

// isSymlink()
let symPath = AbsolutePath(path: "/hello")
let symPath = AbsolutePath(static: "/hello")
XCTAssertTrue(vfs.isSymlink(symPath))
XCTAssertTrue(vfs.isFile(symPath))
XCTAssertEqual(try vfs.getFileInfo(symPath).fileType, .typeSymbolicLink)
XCTAssertFalse(vfs.isDirectory(symPath))

// isExecutableFile
let executablePath = AbsolutePath(path: "/exec-foo")
let executableSymPath = AbsolutePath(path: "/exec-sym")
let executablePath = AbsolutePath(static: "/exec-foo")
let executableSymPath = AbsolutePath(static: "/exec-sym")
XCTAssertTrue(vfs.isExecutableFile(executablePath))
XCTAssertTrue(vfs.isExecutableFile(executableSymPath))
XCTAssertTrue(vfs.isSymlink(executableSymPath))
XCTAssertFalse(vfs.isExecutableFile(symPath))
XCTAssertFalse(vfs.isExecutableFile(filePath))
XCTAssertFalse(vfs.isExecutableFile(AbsolutePath(path: "/does-not-exist")))
XCTAssertFalse(vfs.isExecutableFile(AbsolutePath(path: "/")))
XCTAssertFalse(vfs.isExecutableFile(AbsolutePath(static: "/does-not-exist")))
XCTAssertFalse(vfs.isExecutableFile(AbsolutePath(static: "/")))

// readFileContents
let execFileContents = try vfs.readFileContents(executablePath)
XCTAssertEqual(execFileContents, ByteString(contents))

// isDirectory()
XCTAssertTrue(vfs.isDirectory(AbsolutePath(path: "/")))
XCTAssertFalse(vfs.isDirectory(AbsolutePath(path: "/does-not-exist")))
XCTAssertTrue(vfs.isDirectory(AbsolutePath(static: "/")))
XCTAssertFalse(vfs.isDirectory(AbsolutePath(static: "/does-not-exist")))

// getDirectoryContents()
do {
_ = try vfs.getDirectoryContents(AbsolutePath(path: "/does-not-exist"))
_ = try vfs.getDirectoryContents(AbsolutePath(static: "/does-not-exist"))
XCTFail("Unexpected success")
} catch {
XCTAssertEqual(error.localizedDescription, "no such file or directory: \(AbsolutePath(path: "/does-not-exist"))")
XCTAssertEqual(error.localizedDescription, "no such file or directory: \(AbsolutePath(static: "/does-not-exist"))")
}

let thisDirectoryContents = try vfs.getDirectoryContents(AbsolutePath(path: "/"))
let thisDirectoryContents = try vfs.getDirectoryContents(AbsolutePath(static: "/"))
XCTAssertFalse(thisDirectoryContents.contains(where: { $0 == "." }))
XCTAssertFalse(thisDirectoryContents.contains(where: { $0 == ".." }))
XCTAssertEqual(thisDirectoryContents.sorted(), ["best", "dir", "exec-foo", "exec-sym", "hello"])

let contents = try vfs.getDirectoryContents(AbsolutePath(path: "/dir"))
let contents = try vfs.getDirectoryContents(AbsolutePath(static: "/dir"))
XCTAssertEqual(contents, ["file"])

let fileContents = try vfs.readFileContents(AbsolutePath(path: "/dir/file"))
let fileContents = try vfs.readFileContents(AbsolutePath(static: "/dir/file"))
XCTAssertEqual(fileContents, "")
}
}
Expand Down
20 changes: 10 additions & 10 deletions Tests/BasicsTests/ZipArchiverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ZipArchiverTests: XCTestCase {
func testZipArchiverSuccess() throws {
try testWithTemporaryDirectory { tmpdir in
let archiver = ZipArchiver(fileSystem: localFileSystem)
let inputArchivePath = AbsolutePath(path: #file).parentDirectory.appending(components: "Inputs", "archive.zip")
let inputArchivePath = AbsolutePath(static: #file).parentDirectory.appending(components: "Inputs", "archive.zip")
try archiver.extract(from: inputArchivePath, to: tmpdir)
let content = tmpdir.appending(component: "file")
XCTAssert(localFileSystem.exists(content))
Expand All @@ -30,34 +30,34 @@ class ZipArchiverTests: XCTestCase {
func testZipArchiverArchiveDoesntExist() {
let fileSystem = InMemoryFileSystem()
let archiver = ZipArchiver(fileSystem: fileSystem)
let archive = AbsolutePath(path: "/archive.zip")
XCTAssertThrowsError(try archiver.extract(from: archive, to: AbsolutePath(path: "/"))) { error in
let archive = AbsolutePath(static: "/archive.zip")
XCTAssertThrowsError(try archiver.extract(from: archive, to: AbsolutePath(static: "/"))) { error in
XCTAssertEqual(error as? FileSystemError, FileSystemError(.noEntry, archive))
}
}

func testZipArchiverDestinationDoesntExist() throws {
let fileSystem = InMemoryFileSystem(emptyFiles: "/archive.zip")
let archiver = ZipArchiver(fileSystem: fileSystem)
let destination = AbsolutePath(path: "/destination")
XCTAssertThrowsError(try archiver.extract(from: AbsolutePath(path: "/archive.zip"), to: destination)) { error in
let destination = AbsolutePath(static: "/destination")
XCTAssertThrowsError(try archiver.extract(from: AbsolutePath(static: "/archive.zip"), to: destination)) { error in
XCTAssertEqual(error as? FileSystemError, FileSystemError(.notDirectory, destination))
}
}

func testZipArchiverDestinationIsFile() throws {
let fileSystem = InMemoryFileSystem(emptyFiles: "/archive.zip", "/destination")
let archiver = ZipArchiver(fileSystem: fileSystem)
let destination = AbsolutePath(path: "/destination")
XCTAssertThrowsError(try archiver.extract(from: AbsolutePath(path: "/archive.zip"), to: destination)) { error in
let destination = AbsolutePath(static: "/destination")
XCTAssertThrowsError(try archiver.extract(from: AbsolutePath(static: "/archive.zip"), to: destination)) { error in
XCTAssertEqual(error as? FileSystemError, FileSystemError(.notDirectory, destination))
}
}

func testZipArchiverInvalidArchive() throws {
try testWithTemporaryDirectory { tmpdir in
let archiver = ZipArchiver(fileSystem: localFileSystem)
let inputArchivePath = AbsolutePath(path: #file).parentDirectory
let inputArchivePath = AbsolutePath(static: #file).parentDirectory
.appending(components: "Inputs", "invalid_archive.zip")
XCTAssertThrowsError(try archiver.extract(from: inputArchivePath, to: tmpdir)) { error in
#if os(Windows)
Expand All @@ -73,14 +73,14 @@ class ZipArchiverTests: XCTestCase {
// valid
try testWithTemporaryDirectory { tmpdir in
let archiver = ZipArchiver(fileSystem: localFileSystem)
let path = AbsolutePath(path: #file).parentDirectory
let path = AbsolutePath(static: #file).parentDirectory
.appending(components: "Inputs", "archive.zip")
XCTAssertTrue(try archiver.validate(path: path))
}
// invalid
try testWithTemporaryDirectory { tmpdir in
let archiver = ZipArchiver(fileSystem: localFileSystem)
let path = AbsolutePath(path: #file).parentDirectory
let path = AbsolutePath(static: #file).parentDirectory
.appending(components: "Inputs", "invalid_archive.zip")
XCTAssertFalse(try archiver.validate(path: path))
}
Expand Down
Loading

0 comments on commit f3a4016

Please sign in to comment.