-
-
Notifications
You must be signed in to change notification settings - Fork 508
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
Add related test targets as testables #818
Conversation
@vytis your pull request is missing a changelog! |
3742801
to
d550c4c
Compare
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.
Thanks for looking into this @vytis
Regarding testing you are right it doesn't look like there's a wholistic test for the scheme generator, a few options for us:
-
create another internal method with a similar signature to
generateProjectSchemes
except this one doesn't write to disk, but returns the[Scheme]
which would allow us to unit test it without ever needing to go to disk (should be faster and much more reliable) -
We can make
createDefaultScheme
internal to unit test that one method
Hope this helps!
testTargets = [TestableTarget(target: targetReference)] | ||
} else if let targetNode = graph.findTargetNode(path: project.path, name: target.name) { | ||
// Find all test targets that depend on this target | ||
testTargets = graph.targets |
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 a suggestion, we can limit the scope of the search to targets within the same project as opposed to the whole workspace
A few ways we can go about it:
- Scan project targets directly
targetNode.project
.targets
.filter { $0.product.testsBundle }
.filter { $0.dependencies.contains(.target(name: targetNode.name)) }
.map { TargetReference.project(path: targetNode.project.path, target: $0.name) }
// ...
- Add another helper to the graph
In graph we could introduce another method:
/// Returns all target nodes at a given path (i.e. all target nodes in a project)
public func targetNodes(at path: AbsolutePath) -> [TargetNode] {
guard let nodes = cache.targetNodes[path] else {
return []
}
return Array(nodes.values)
}
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.
Makes sense, I was thinking what could be the performance impact of looping through all targets. Only looking through project targets sounds much better.
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.
@kwridan I added the helper, might be useful in other places too
d550c4c
to
213fd1c
Compare
@kwridan I have added tests and addressed the points you raised. I think it's ready for review π€ |
testTargets = [TestableTarget(target: targetReference)] | ||
} else if let targetNode = graph.findTargetNode(path: project.path, name: target.name) { | ||
// Find all test targets that depend on this target | ||
testTargets = graph.targets(at: project.path) |
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.
What about moving this logic to the Graph
model? Something along the lines of:
func testableDependants(of: TargetNode) -> [TargetNode]
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.
@pepibumur updated!
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 a minor thing but it looks good overall. π good job @vytis
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.
nice work @vytis
Tested it out on a few fixtures π
Resolves #569
Short description π
It should be possible to run tests if target has any test targets.
Solution π¦
This PR finds all related test targets to the test scheme. It was already done for test targets themselves, but the functionality was extended to include all other targets.
Implementation π©βπ»π¨βπ»
Test Plan π
Run with
app_with_framework_and_tests
fixture and check that in generated schemes:Previous behaviour didn't break
AppTests
scheme hasAppTests
as a testable target.FrameworkTests
scheme hasFrameworkTests
as a testable target.New behaviour works as expected
App
scheme hasAppTests
as a testable target.Framework
scheme hasFrameworkTests
as a testable target.