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-1276] swift tests fail to link library during test build when name doesn't match tested target #5302

Closed
masters3d opened this issue Apr 20, 2016 · 6 comments
Labels

Comments

@masters3d
Copy link
Contributor

Previous ID SR-1276
Radar None
Original Reporter @masters3d
Type Bug
Status Closed
Resolution Done

Attachment: Download

Environment

xcode 7.3
10.11.4 (15E65)
swift-DEVELOPMENT-SNAPSHOT-2016-04-12-a
Same thing happens with 3-24 snapshotp

Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug
Assignee None
Priority Medium

md5: e6ccdf7a6a1514b8239d5704eadfd7f9

Issue Description:

I added some test to a fork of the sample playing card.
https://github.com/masters3d/example-package-playingcard
It builds okay but the test do not link.
Log.
https://gist.github.com/masters3d/658fbaf009ef3b85b8509bf9dc6b2857

This seems similar to https://bugs.swift.org/browse/SR-151
but this is just happens for the test build.

Steps to reproduce:
swift build -v // See gist log.
swift test // See gist log.

@ddunbar
Copy link
Member

ddunbar commented Apr 21, 2016

The package manager will add an implicit dependency between the test suite and the target it assumes it is trying to test. In your case, however, your package module is named PlayingCard, and your test module is name CardTests (not PlayingCardTests) so it doesn't find that dependency. This leaves it without any dependencies, and so the link fails. That the build of the individual test files doesn't fail is because we don't yet have a good way to enforce your Swift code only see what it is allowed to.

If you do:
```
$ git mv Tests/Card Tests/PlayingCard
$ TOOLCHAINS=swift swift build
$ TOOLCHAINS=swift swift test
```
then it should work.

Keeping this bug open to track better diagnostics to help the user find this issue.

@masters3d
Copy link
Contributor Author

Ah interesting. I was under the impression that ```@testable import xxxx``` would auto link the imported target.

<https://github.com/apple/swift-package-manager/blob/master/Documentation/Package.swift.md>

got it . I just need to declare the target name I want to match to the subfolder.

   

@abertelrud
Copy link
Contributor

Is this resolved, or do you feel that there is a SwiftPM issue still to fix here?

@ddunbar
Copy link
Member

ddunbar commented Aug 27, 2016

I would like for us to find a way to help users discover the right convention here.

One idea: maybe we could have a warning in cases where there is a Source module, and there is a Test module, but there is no dependency between them? It seems really unlikely that that is something would come up. If we do that, we should probably think about a way to suppress the warning (e.g., write an explicit dependencies: [] specification in the manifest.

@swift-ci
Copy link
Contributor

swift-ci commented Nov 3, 2016

Comment by Scott (JIRA)

I'm so glad I came across this. This was one of those good 1/2 day head scratchers. I would second that I like the idea of the warning in this situation. There is a risk of not being familiar with this convention when you are primarily building in Xcode but want to include SPM support.

@ankitspd
Copy link
Member

We no longer have implicit dependencies.

@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

5 participants