diff --git a/Package.swift b/Package.swift index a8b4f00..808afed 100644 --- a/Package.swift +++ b/Package.swift @@ -40,6 +40,9 @@ let package = Package( name: "XcodesKitTests", dependencies: [ "XcodesKit", "Version" + ], + resources: [ + .copy("Fixtures"), ]), .target( name: "AppleAPI", diff --git a/Tests/XcodesKitTests/Environment+Mock.swift b/Tests/XcodesKitTests/Environment+Mock.swift index 868c027..bc48da3 100644 --- a/Tests/XcodesKitTests/Environment+Mock.swift +++ b/Tests/XcodesKitTests/Environment+Mock.swift @@ -44,11 +44,11 @@ extension Files { moveItem: { _, _ in return }, contentsAtPath: { path in if path.contains("Info.plist") { - let url = URL(fileURLWithPath: "Stub-0.0.0.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-0.0.0.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path.contains("version.plist") { - let url = URL(fileURLWithPath: "Stub.version.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub.version", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else { diff --git a/Tests/XcodesKitTests/LogOutput-FullHappyPath.txt b/Tests/XcodesKitTests/Fixtures/LogOutput-FullHappyPath.txt similarity index 100% rename from Tests/XcodesKitTests/LogOutput-FullHappyPath.txt rename to Tests/XcodesKitTests/Fixtures/LogOutput-FullHappyPath.txt diff --git a/Tests/XcodesKitTests/Stub-0.0.0.Info.plist b/Tests/XcodesKitTests/Fixtures/Stub-0.0.0.Info.plist similarity index 100% rename from Tests/XcodesKitTests/Stub-0.0.0.Info.plist rename to Tests/XcodesKitTests/Fixtures/Stub-0.0.0.Info.plist diff --git a/Tests/XcodesKitTests/Stub-2.0.0.Info.plist b/Tests/XcodesKitTests/Fixtures/Stub-2.0.0.Info.plist similarity index 100% rename from Tests/XcodesKitTests/Stub-2.0.0.Info.plist rename to Tests/XcodesKitTests/Fixtures/Stub-2.0.0.Info.plist diff --git a/Tests/XcodesKitTests/Stub-2.0.1.Info.plist b/Tests/XcodesKitTests/Fixtures/Stub-2.0.1.Info.plist similarity index 100% rename from Tests/XcodesKitTests/Stub-2.0.1.Info.plist rename to Tests/XcodesKitTests/Fixtures/Stub-2.0.1.Info.plist diff --git a/Tests/XcodesKitTests/Stub.version.plist b/Tests/XcodesKitTests/Fixtures/Stub.version.plist similarity index 100% rename from Tests/XcodesKitTests/Stub.version.plist rename to Tests/XcodesKitTests/Fixtures/Stub.version.plist diff --git a/Tests/XcodesKitTests/developer.apple.com-download-19-6-9.html b/Tests/XcodesKitTests/Fixtures/developer.apple.com-download-19-6-9.html similarity index 100% rename from Tests/XcodesKitTests/developer.apple.com-download-19-6-9.html rename to Tests/XcodesKitTests/Fixtures/developer.apple.com-download-19-6-9.html diff --git a/Tests/XcodesKitTests/XcodesKitTests.swift b/Tests/XcodesKitTests/XcodesKitTests.swift index 726d0ad..90ad7df 100644 --- a/Tests/XcodesKitTests/XcodesKitTests.swift +++ b/Tests/XcodesKitTests/XcodesKitTests.swift @@ -199,8 +199,7 @@ final class XcodesKitTests: XCTestCase { installer.install(.version("0.0.0")) .ensure { - let url = URL(fileURLWithPath: "LogOutput-FullHappyPath.txt", - relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "LogOutput-FullHappyPath", withExtension: "txt", subdirectory: "Fixtures")! XCTAssertEqual(log, try! String(contentsOf: url)) expectation.fulfill() } @@ -221,19 +220,19 @@ final class XcodesKitTests: XCTestCase { Current.files.installedXcodes = { installedXcodes } Current.files.contentsAtPath = { path in if path == "/Applications/Xcode-0.0.0.app/Contents/Info.plist" { - let url = URL(fileURLWithPath: "Stub-0.0.0.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-0.0.0.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path == "/Applications/Xcode-2.0.0.app/Contents/Info.plist" { - let url = URL(fileURLWithPath: "Stub-2.0.0.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-2.0.0.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path == "/Applications/Xcode-2.0.1.app/Contents/Info.plist" { - let url = URL(fileURLWithPath: "Stub-2.0.1.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-2.0.1.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path.contains("version.plist") { - let url = URL(fileURLWithPath: "Stub.version.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub.version", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else { @@ -344,7 +343,7 @@ final class XcodesKitTests: XCTestCase { } func test_ParsePrereleaseXcodes() { - let url = URL(fileURLWithPath: "developer.apple.com-download-19-6-9.html", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "developer.apple.com-download-19-6-9", withExtension: "html", subdirectory: "Fixtures")! let data = try! Data(contentsOf: url) let xcodes = try! XcodeList().parsePrereleaseXcodes(from: data) @@ -380,15 +379,15 @@ final class XcodesKitTests: XCTestCase { InstalledXcode(path: Path("/Applications/Xcode-2.0.1.app")!)!] } Current.files.contentsAtPath = { path in if path == "/Applications/Xcode-0.0.0.app/Contents/Info.plist" { - let url = URL(fileURLWithPath: "Stub-0.0.0.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-0.0.0.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path == "/Applications/Xcode-2.0.1.app/Contents/Info.plist" { - let url = URL(fileURLWithPath: "Stub-2.0.1.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-2.0.1.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path.contains("version.plist") { - let url = URL(fileURLWithPath: "Stub.version.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub.version", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else { @@ -448,15 +447,15 @@ final class XcodesKitTests: XCTestCase { InstalledXcode(path: Path("/Applications/Xcode-2.0.1.app")!)!] } Current.files.contentsAtPath = { path in if path == "/Applications/Xcode-0.0.0.app/Contents/Info.plist" { - let url = URL(fileURLWithPath: "Stub-0.0.0.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-0.0.0.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path == "/Applications/Xcode-2.0.1.app/Contents/Info.plist" { - let url = URL(fileURLWithPath: "Stub-2.0.1.Info.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub-2.0.1.Info", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else if path.contains("version.plist") { - let url = URL(fileURLWithPath: "Stub.version.plist", relativeTo: URL(fileURLWithPath: #file).deletingLastPathComponent()) + let url = Bundle.module.url(forResource: "Stub.version", withExtension: "plist", subdirectory: "Fixtures")! return try? Data(contentsOf: url) } else {