-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Proposal for testing support in SwiftPM #51
Conversation
└── Tests | ||
└── TestFoo.swift | ||
|
||
The filename: `TestFoo.swift` is arbituary. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arbitrary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😊
However, any such decision would warrant extensive design consideration, | ||
so as to avoid polluting or crowding the command-line interface. | ||
Should there be sufficient demand and justification for it, though, | ||
it would be straightforward to add this functionality. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would really like to see any arguments after swift build --test
or swift test
pass though to the test runner.
Example, the test framework Spectre allows command line flags to use different reporters. For example, --tap
, --dot
etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very much agree in terms of command-line arguments being used by test runners, and in terms of the necessity of custom test reporters.
Still, I believe Swift's Process.environment
may be able to suffice for now, and would allow us to decouple that important discussion from this proposal.
Currently the test suites in swift-corelibs-foundation's and swift-package-manager use different scripts/Xcode projects for testing, but both do the following:
How will this change as a result of this proposal, if at all? |
Ultimately we want swift-corelibs-foundation to be able to build, run, and test itself with swiftpm. |
@parkera On Linux? Or on OS X as well? |
On Linux - the plan with the core libraries is to provide their features where we do not have the Darwin equivalents. |
a test for "Foo" will depend on compilation of the library target `Foo`. | ||
Any additional dependencies or dependencies that could not be automatically determined | ||
would need to be specified in a package manifest separately. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify the author's intent for resolving additional dependencies - does this mean that in Package.swift
there will be a "private" section for dependencies used by the tests, (things like DVR), or that the Test directory will include its own manifest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to link this to swiftlang/swift-package-manager#74
There is a pull request and discussion around "private dependencies" in this pull request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As much as I like the idea of having another manifest and thus keeping it all separate, maintaining two manifests is an extra layer of tedium for packagers, so I think we'll (longterm) be learning towards keeping all of this in one manifest file. The linked PR is being reviewed today, but is not a firm decision, we may at a later time change the manifest format before Swift 3 drops.
Does this accommodate projects with an integration test suite that might run more slowly, require a second process (e.g. database), require nonstandard build config, etc.? Perhaps such tests should not be run as part of the standard package test suite? If so, how would that play out in the proposed directory structure? |
├── Foo.swift | ||
└── Tests | ||
└── Test.swift | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason for this variant? Will one format be recommended over the other? Having one recommended structure seems like it would be better in terms of consistency/providing guidance to developers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One will be recommended. I believe in strong recommendations for flexible workflows.
How are perf tests handled? Is that:
|
Detail the ability to specify specific tests to run.
This is a concern of mine as well. Tests that require to be run on a physical device or on a specific platform would also fall into this category. Although I think it should be sufficient for the first version of this to allow opting out of certain test cases within this directory structure. Maybe by having a static var on XCTestCase subclasses: class FooDeviceTests: XCTestCase {
static var excludeFromPackageManagerTests = true
} |
(As I commented above) I don't love the idea of coupling swiftpm to corelibs-xctest. Adding something like Theoretically, you could exclude certain test cases from swiftpm using existing concepts: class FooDeviceTests: XCTestCase {
var allTests: [(String -> () -> Void)] {
var tests = [(String -> () -> Void)]()
if !Process.arguments.contains("swift-build") {
tests.append(("test_onPhysicalDevice", test_onPhysicalDevice))
}
return tests
}
} Going forward, we should have test frameworks like swift-corelibs-xctest and Spectre determine how to aggregate tests. When left to implement their own aggregation schemes, testing frameworks can innovate: the way JUnit 4 implements aggregation is different from how RSpec uses test filters; both have pros and cons. Asserting too much control in how tests are run in the package manager stifles these frameworks' opportunity to develop new concepts. The command-line arguments part of the proposal, introduced in 68e618c, is great. It sounds like it would make filtering easy to implement, either in swift-corelibs-xctest or other frameworks: // swift build -t --exclude broken
// MyTestingFramework parses command-line arguments to
// determine which tests to run or not run.
class MyBrokenTests: MyTestingFrameworkTestCase {
// These tests don't work yet, so I tag them as 'broken'.
var tags: [String] { ['broken'] }
func test_myTestThatDoesntPassYet() { /* ... */ }
} |
Long term a goal is to remove the divergence here, but there is no timeline for it. |
There is no proposal for this at this time. However, we intend to support other test frameworks that conform to a protocol vended by swiftpm, it seems easy enough to design the protocol with these considerations in mind (it could signify the end of a test with a closure to allow asynchronous running mechanisms, and start-end functions could be provided to allow control of external test processes). |
From the top of my head, I don’t see why it would need to be separated.
We could certainly allow this kind of specification. Currently the proposal says it will accept the name of the test case on the command line and that seems sufficient initially.
I would think: yes.
I would think: yes. |
It seems to me that |
If you feel we are missing any understandings here, please feel free to enlighten us. I am certainly less of an expert in this area than I'd like. |
Can we take this discussion over to a mailing list? Presumable the package manager mailing list, since it's not really in the purview of the general swift-evolution list? |
Oops, sorry if my comment came across as sanctimonious here! 😝 My intention was simply to point out that baking into the package manager the ability to include or exclude performance tests, depending on how that was implemented, may make it harder for test frameworks to build cool new features. I don't think anyone's missing any understandings; based on your comments above I think we're all on the same page! 👍
Sounds fine to me! |
I’m less concerned about the details of how the test framework is invoked, and more about being about to put all the things in
It’s unclear to me from the wording of the current proposal whether this is covered. It sounds like SwiftPM would find everything named |
If anyone has any further comments then we should take them to
Not at all, I seek merely to ensure we have considered all aspects.
Excluding targets will be possible as a result of future work on |
Proposal for testing support in SwiftPM
Structured concurrency: discuss what executors tasks start on
Our proposal for how testing infrastructure should operate and be implemented in the package manager.