-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[5.5] fix a bug in test discovery where tests define in extensions break the discovery #3435
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
Fixtures/Miscellaneous/TestDiscovery/Extensions/Package.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// swift-tools-version:4.2 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "Simple", | ||
targets: [ | ||
.target(name: "Simple"), | ||
.testTarget(name: "SimpleTests", dependencies: ["Simple"]), | ||
] | ||
) |
3 changes: 3 additions & 0 deletions
3
Fixtures/Miscellaneous/TestDiscovery/Extensions/Sources/Simple/Simple.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
struct Simple { | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
Fixtures/Miscellaneous/TestDiscovery/Extensions/Tests/SimpleTests/SwiftTests1.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import XCTest | ||
@testable import Simple | ||
|
||
class SimpleTests1: XCTestCase { | ||
func testExample1() { | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
Fixtures/Miscellaneous/TestDiscovery/Extensions/Tests/SimpleTests/SwiftTests2.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import XCTest | ||
@testable import Simple | ||
|
||
class SimpleTests2: XCTestCase { | ||
func testExample2() { | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Fixtures/Miscellaneous/TestDiscovery/Extensions/Tests/SimpleTests/SwiftTests3.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import XCTest | ||
@testable import Simple | ||
|
||
extension SimpleTests1 { | ||
func testExample1_a() { | ||
} | ||
} | ||
|
||
extension SimpleTests2 { | ||
func testExample2_a() { | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Fixtures/Miscellaneous/TestDiscovery/Extensions/Tests/SimpleTests/SwiftTests4.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import XCTest | ||
@testable import Simple | ||
|
||
class SimpleTests4: XCTestCase { | ||
func testExample() { | ||
} | ||
|
||
func testExample1() { | ||
} | ||
|
||
func testExample2() { | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,14 +54,18 @@ final class TestDiscoveryCommand: CustomLLBuildCommand { | |
) throws { | ||
let stream = try LocalFileOutputByteStream(path) | ||
|
||
let testsByClass = Dictionary(grouping: tests, by: { $0.name }) | ||
|
||
stream <<< "import XCTest" <<< "\n" | ||
stream <<< "@testable import " <<< module <<< "\n" | ||
|
||
for klass in tests { | ||
for classTests in testsByClass { | ||
let className = classTests.key | ||
let testMethods = classTests.value.flatMap{ $0.methods } | ||
stream <<< "\n" | ||
stream <<< "fileprivate extension " <<< klass.name <<< " {" <<< "\n" | ||
stream <<< indent(4) <<< "static let __allTests__\(klass.name) = [" <<< "\n" | ||
for method in klass.methods { | ||
stream <<< "fileprivate extension " <<< className <<< " {" <<< "\n" | ||
stream <<< indent(4) <<< "static let __allTests__\(className) = [" <<< "\n" | ||
for method in testMethods { | ||
let method = method.hasSuffix("()") ? String(method.dropLast(2)) : method | ||
stream <<< indent(8) <<< "(\"\(method)\", \(method))," <<< "\n" | ||
} | ||
|
@@ -74,8 +78,8 @@ final class TestDiscoveryCommand: CustomLLBuildCommand { | |
return [\n | ||
""" | ||
|
||
for klass in tests { | ||
stream <<< indent(8) <<< "testCase(\(klass.name).__allTests__\(klass.name)),\n" | ||
for className in testsByClass.keys { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same question here about order. |
||
stream <<< indent(8) <<< "testCase(\(className).__allTests__\(className)),\n" | ||
} | ||
|
||
stream <<< """ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since this is now iterating over a dictionary instead of an array, should the keys be sorted here to avoid spurious differences in how the output file is emitted?
Uh oh!
There was an error while loading. Please reload this page.
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.
do you mean so that the output won't cause unnecessary compiles? if so, I think this is a good idea but I would do that in a separate optimization PR on main, and let the fix through as-is in 5.5
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.
Yes, that's what I meant — just to always have stable outputs. Agreed that it can be done 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.
#3436