Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-12912] SPM: Resources do not work in test targets #4541

Closed
Nef10 opened this issue May 31, 2020 · 3 comments
Closed

[SR-12912] SPM: Resources do not work in test targets #4541

Nef10 opened this issue May 31, 2020 · 3 comments
Labels

Comments

@Nef10
Copy link

Nef10 commented May 31, 2020

Previous ID SR-12912
Radar None
Original Reporter @Nef10
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

swiftenv version:

5.3-DEVELOPMENT-SNAPSHOT-2020-05-19-a

swift version:

Apple Swift version 5.3-dev (LLVM d2c5a6fb91, Swift 4eac5a1f0f) Target: x86_64-apple-darwin19.5.0

swift build --version:

Swift Package Manager - Swift 5.3.0
Additional Detail from JIRA
Votes 7
Component/s Package Manager
Labels Bug
Assignee Steven0351 (JIRA)
Priority Medium

md5: a0e09b8dd3c59c4e33ec01211d8f9f6c

Issue Description:

When using resources in combination with testTargets, the resources cannot be found. This happens regardless if the resource is in a library which is being tested or in the test target itself. The resource is being loaded via the new Bundle.module.

For minimal reproducible code including full debug output see https://github.com/Nef10/SPMResourcesInTest (or attachment)

The code tries to load the bundle from

/Applications/Xcode.app/Contents/Developer/usr/bin/BUNDLENAME.bundle

This is where the xctest executable is located. Te loading happens in the resource_bundle_accessor.swift which the SPM writes. In there it uses Bundle.main.bundlePath to get the bundle path. According to https://forums.swift.org/t/bundle-main-path-pointing-to-odd-path/13814 it is correct that Bundle.main in case of test execution points to the directory of the xctest executable.

Therefor I think the resource_bundle_accessor.swift needs adjustment to find the correct bundle path in case of test targets. The resources are correctly copied to a bundle in the .build directory

See also https://forums.swift.org/t/swift-5-3-spm-resources-in-tests-uses-wrong-bundle-path/37051

@swift-ci
Copy link
Contributor

Comment by Steven Sherry (JIRA)

@Nef10 I ran into the same issue myself and I opened a PR for this here: #2817

@swift-ci
Copy link
Contributor

Comment by Steven Sherry (JIRA)

Resolved with this PR being merged: #2817 (comment)

@abertelrud
Copy link
Contributor

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants