Adopt resource bundles for the SPM test target.

This commit is contained in:
Ethan Wong 2022-10-23 16:11:39 +08:00
parent e99ced22d0
commit b2b5af0d98
No known key found for this signature in database
GPG Key ID: 62BE93C47E7FCE14
4 changed files with 8 additions and 7 deletions

View File

@ -225,7 +225,6 @@
isa = PBXGroup;
children = (
2A7DC79E1FB6AFC900539D90 /* GzipTests */,
2A8219C61D65AFB300D65063 /* test.txt.gz */,
);
path = Tests;
sourceTree = "<group>";
@ -234,6 +233,7 @@
isa = PBXGroup;
children = (
2A58A75C1B00F414005FBBC2 /* GzipTests.swift */,
2A8219C61D65AFB300D65063 /* test.txt.gz */,
);
path = GzipTests;
sourceTree = "<group>";

View File

@ -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,

View File

@ -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