From b2b5af0d9878489be1c01654e7ef731675370d5e Mon Sep 17 00:00:00 2001 From: Ethan Wong Date: Sun, 23 Oct 2022 16:11:39 +0800 Subject: [PATCH] Adopt resource bundles for the SPM test target. --- Gzip.xcodeproj/project.pbxproj | 2 +- Package.swift | 8 ++++++-- Tests/GzipTests/GzipTests.swift | 5 +---- Tests/{ => GzipTests}/test.txt.gz | Bin 4 files changed, 8 insertions(+), 7 deletions(-) rename Tests/{ => GzipTests}/test.txt.gz (100%) diff --git a/Gzip.xcodeproj/project.pbxproj b/Gzip.xcodeproj/project.pbxproj index 2680342..d135bcc 100644 --- a/Gzip.xcodeproj/project.pbxproj +++ b/Gzip.xcodeproj/project.pbxproj @@ -225,7 +225,6 @@ isa = PBXGroup; children = ( 2A7DC79E1FB6AFC900539D90 /* GzipTests */, - 2A8219C61D65AFB300D65063 /* test.txt.gz */, ); path = Tests; sourceTree = ""; @@ -234,6 +233,7 @@ isa = PBXGroup; children = ( 2A58A75C1B00F414005FBBC2 /* GzipTests.swift */, + 2A8219C61D65AFB300D65063 /* test.txt.gz */, ); path = GzipTests; sourceTree = ""; diff --git a/Package.swift b/Package.swift index b77b1aa..4fe3f0f 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.0 +// swift-tools-version:5.3 import PackageDescription @@ -10,7 +10,11 @@ let package = Package( targets: [ .target(name: "Gzip", dependencies: ["system-zlib"]), .target(name: "system-zlib"), - .testTarget(name: "GzipTests", dependencies: ["Gzip"]), + .testTarget( + name: "GzipTests", + dependencies: ["Gzip"], + resources: [.copy("./test.txt.gz")] + ), ], swiftLanguageVersions: [ .v5, diff --git a/Tests/GzipTests/GzipTests.swift b/Tests/GzipTests/GzipTests.swift index c7b0dab..47c78a8 100644 --- a/Tests/GzipTests/GzipTests.swift +++ b/Tests/GzipTests/GzipTests.swift @@ -127,10 +127,7 @@ private extension XCTestCase { func bundleFile(name: String) -> URL { #if SWIFT_PACKAGE - return URL(fileURLWithPath: #file) - .deletingLastPathComponent() - .deletingLastPathComponent() - .appendingPathComponent(name) + return Bundle.module.url(forResource: name, withExtension: nil)! #else return Bundle(for: type(of: self)).url(forResource: name, withExtension: nil)! #endif diff --git a/Tests/test.txt.gz b/Tests/GzipTests/test.txt.gz similarity index 100% rename from Tests/test.txt.gz rename to Tests/GzipTests/test.txt.gz