How to write a test against fixture resources from generated xcodeproj test bundle?

Hi Swift Community,
I'm Toshihiro Suzuki and have a question about Swift Package Manager.
I'm trying out with new Xcode9-beta.

When I generate a new xcodeproj like this, `Resources` directory is
imported as a folder reference in xcodeproj.

$ swift -version
Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
Target: x86_64-apple-macosx10.9
$ swift package init --type library
$ mkdir -p Resources/Fixtures/
$ touch Resources/Fixtures/test.txt
$ swift package generate-xcodeproj

When I open the xcodeproj and hit Cmd+U, I want to access test.txt with
code like this.

let path = Bundle(for: Swift4sampleTests.self).path(forResource:
"test.txt", ofType: nil)!
let data = Data(contentsOf: URL(string: path)!)

To make it work, I need to manually
- add Resources/ as a group, instead of folder reference.
- add "Copy Files Phase" in Build Phase to copy test.txt as "Resources".

Can SwiftPM handle this use-case automatically?
Or is there a way to access test resources from generated xcodeproj test
bundle?

Thanks,
Toshihiro Suzuki

路路路

--
Toshihiro Suzuki

Swiftpm does not currently support resources - not in applications, libraries, or tests.

It鈥檚 a commonly-requested feature, though. I鈥檓 sure it will come in a future release.

- Karl

路路路

On 10. Jun 2017, at 04:02, Toshihiro Suzuki via swift-users <swift-users@swift.org> wrote:

Hi Swift Community,
I'm Toshihiro Suzuki and have a question about Swift Package Manager.
I'm trying out with new Xcode9-beta.

When I generate a new xcodeproj like this, `Resources` directory is imported as a folder reference in xcodeproj.

$ swift -version
Apple Swift version 4.0 (swiftlang-900.0.43 clang-900.0.22.8)
Target: x86_64-apple-macosx10.9
$ swift package init --type library
$ mkdir -p Resources/Fixtures/
$ touch Resources/Fixtures/test.txt
$ swift package generate-xcodeproj

When I open the xcodeproj and hit Cmd+U, I want to access test.txt with code like this.

let path = Bundle(for: Swift4sampleTests.self).path(forResource: "test.txt", ofType: nil)!
let data = Data(contentsOf: URL(string: path)!)

To make it work, I need to manually
- add Resources/ as a group, instead of folder reference.
- add "Copy Files Phase" in Build Phase to copy test.txt as "Resources".

Can SwiftPM handle this use-case automatically?
Or is there a way to access test resources from generated xcodeproj test bundle?

Thanks,
Toshihiro Suzuki
--
Toshihiro Suzuki
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users