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-4725] Support Test Collateral in Package Manager #5030

Open
swift-ci opened this issue Apr 28, 2017 · 4 comments
Open

[SR-4725] Support Test Collateral in Package Manager #5030

swift-ci opened this issue Apr 28, 2017 · 4 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-4725
Radar None
Original Reporter owensd (JIRA User)
Type New Feature
Additional Detail from JIRA
Votes 6
Component/s Package Manager
Labels New Feature
Assignee None
Priority Medium

md5: f1c9317e97dfd1c1578d379e97bc2a11

relates to:

  • SR-2866 [SwiftPM] Need a way to include resources with targets

Issue Description:

The Swift Package Manager needs the ability to place test collateral in the output folder. Currently, I have to resort to this hack:

let path = NSString.path(withComponents: [Bundle(for: JSValuePerformanceTests.self).bundlePath, "..", "..", "..", "TestCollateral", "sample.json"])

@belkadan
Copy link

@aciidb0mb3r, is there already a bug for "test target resources"?

@ankitspd
Copy link
Member

No, but we have a bug for resources in general, added relation.

@swift-ci
Copy link
Contributor Author

swift-ci commented Jun 4, 2018

Comment by Carlos García Nieto (JIRA)

Other workaround is:

let sampleJSONPath = URL(fileURLWithPath: "(#file)")

        .deletingLastPathComponent()

        .appendingPathComponent("Resources", isDirectory: true)

        .appendingPathComponent("sample.json")

        .path

@swift-ci
Copy link
Contributor Author

Comment by David Owens (JIRA)

carlosypunto (JIRA User), that kind of works. You need to invoke the function with #file though, otherwise you won't necessarily get the right thing:

Say your test file is found here: <project_root>/tests/ddb/testfile.swift and you want data in <project_root>/test-data, you need to do something like this:

func baseURL(donotuse location: String = #file) -> URL {
    return URL(fileURLWithPath: location)
        .deletingLastPathComponent()    // remove the .swift file
        .deletingLastPathComponent()    // remove ddb folder
        .deletingLastPathComponent()    // remove tests
        .appendingPathComponent("test-data")
}

@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants