-
Notifications
You must be signed in to change notification settings - Fork 157
Add ability to filter/skip by tags using a special tag: prefix
#1531
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
Open
gmedori
wants to merge
8
commits into
swiftlang:main
Choose a base branch
from
gmedori:goose/prefix-based-tag-filtering
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fd074af
Add some logic to configurationForEntryPoint(from:) to filter by tags…
gmedori 2c75838
Update the testFilters to contain all the logic for processing test f…
gmedori 62ff6a5
Add tests coverage for new `tag:` prefix behavior for both `--filter`…
gmedori eb89eab
Update comment regarding #available check
gmedori cb1f4c0
Update tag filtering to support regular expressions
gmedori f8db130
Add comments to new TestFilter APIs
gmedori b54878b
Add a function to warn & strip backticks from filters if they are det…
gmedori 979dab5
Add tests and fix an edge case around regex initialization caught by …
gmedori 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
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
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
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 |
|---|---|---|
|
|
@@ -17,6 +17,12 @@ private func configurationForEntryPoint(withArguments args: [String]) throws -> | |
| } | ||
|
|
||
| #if !SWT_NO_CODABLE | ||
|
|
||
| private extension Tag { | ||
| @Tag static var testTag: Self | ||
| @Tag static var testTagOther: Self | ||
| @Tag static var unrelatedTag: Self | ||
| } | ||
| /// Reads event stream output from the provided file matching event stream | ||
| /// version `V`. | ||
| private func decodedEventStreamRecords<V: ABI.Version>(fromPath filePath: String) throws -> [ABI.Record<V>] { | ||
|
|
@@ -114,6 +120,18 @@ struct SwiftPMTests { | |
| #expect(!planTests.contains(test2)) | ||
| } | ||
|
|
||
|
|
||
| @Test("--filter argument with tag: prefix") | ||
| func filterByTag() async throws { | ||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "tag:testTag"]) | ||
| let test1 = Test(.tags(.testTag), name: "hello") {} | ||
| let test2 = Test(name: "goodbye") {} | ||
| let plan = await Runner.Plan(tests: [test1, test2], configuration: configuration) | ||
| let planTests = plan.steps.map(\.test) | ||
| #expect(planTests.contains(test1)) | ||
| #expect(!planTests.contains(test2)) | ||
| } | ||
|
|
||
| @Test("Multiple --filter arguments") | ||
| func multipleFilter() async throws { | ||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "hello", "--filter", "sorry"]) | ||
|
|
@@ -157,6 +175,94 @@ struct SwiftPMTests { | |
| #expect(planTests.contains(test2)) | ||
| } | ||
|
|
||
| @Test("--skip argument with tag: prefix") | ||
| func skipByTag() async throws { | ||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--skip", "tag:testTag"]) | ||
| let test1 = Test(.tags(.testTag), name: "hello") {} | ||
| let test2 = Test(name: "goodbye") {} | ||
| let plan = await Runner.Plan(tests: [test1, test2], configuration: configuration) | ||
| let planTests = plan.steps.map(\.test) | ||
| #expect(!planTests.contains(test1)) | ||
| #expect(planTests.contains(test2)) | ||
| } | ||
|
|
||
| @Test("--filter argument with tag: prefix supports regex patterns") | ||
| func filterByTagRegex() async throws { | ||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "tag:testTag.*"]) | ||
| let test1 = Test(.tags(.testTag), name: "hello") {} | ||
| let test2 = Test(.tags(.testTagOther), name: "hi") {} | ||
| let test3 = Test(.tags(.unrelatedTag), name: "goodbye") {} | ||
| let test4 = Test(name: "untagged") {} | ||
| let plan = await Runner.Plan(tests: [test1, test2, test3, test4], configuration: configuration) | ||
| let planTests = plan.steps.map(\.test) | ||
| #expect(planTests.contains(test1)) | ||
| #expect(planTests.contains(test2)) | ||
| #expect(!planTests.contains(test3)) | ||
| #expect(!planTests.contains(test4)) | ||
| } | ||
|
|
||
| @Test("--filter tag: argument strips backticks around tag names") | ||
| func filterByTagStripsBackticks() async throws { | ||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "tag:`testTag`"]) | ||
| let test1 = Test(.tags(.testTag), name: "hello") {} | ||
| let test2 = Test(name: "goodbye") {} | ||
| let plan = await Runner.Plan(tests: [test1, test2], configuration: configuration) | ||
| let planTests = plan.steps.map(\.test) | ||
| #expect(planTests.contains(test1)) | ||
| #expect(!planTests.contains(test2)) | ||
| } | ||
|
|
||
| @Test("--filter combining tag: and id: patterns AND's them together") | ||
| func mixedPrefixedAndUnprefixedFilters() async throws { | ||
|
Contributor
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. issue (possibly-blocking): without reading the evolution proposal, I would expect this to be an |
||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "tag:testTag", "--filter", "hello"]) | ||
| let test1 = Test(.tags(.testTag), name: "hello") {} | ||
| let test2 = Test(.tags(.testTag), name: "goodbye") {} | ||
| let test3 = Test(name: "hello") {} | ||
| let test4 = Test(name: "goodbye") {} | ||
| let plan = await Runner.Plan(tests: [test1, test2, test3, test4], configuration: configuration) | ||
| let planTests = plan.steps.map(\.test) | ||
| #expect(planTests.contains(test1)) | ||
| #expect(!planTests.contains(test2)) | ||
| #expect(!planTests.contains(test3)) | ||
| #expect(!planTests.contains(test4)) | ||
| } | ||
|
|
||
| @Test("--filter argument with explicit id: prefix") | ||
| func filterByExplicitIdPrefix() async throws { | ||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "id:hello"]) | ||
| let test1 = Test(name: "hello") {} | ||
| let test2 = Test(name: "goodbye") {} | ||
| let plan = await Runner.Plan(tests: [test1, test2], configuration: configuration) | ||
| let planTests = plan.steps.map(\.test) | ||
| #expect(planTests.contains(test1)) | ||
| #expect(!planTests.contains(test2)) | ||
| } | ||
|
|
||
| @Test("--filter tag: combined with --skip id: in the same execution") | ||
| func filterByTagAndSkipById() async throws { | ||
| let configuration = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "tag:testTag", "--skip", "id:goodbye"]) | ||
| let test1 = Test(.tags(.testTag), name: "hello") {} | ||
| let test2 = Test(.tags(.testTag), name: "goodbye") {} | ||
| let test3 = Test(.tags(.unrelatedTag), name: "hello") {} | ||
| let test4 = Test(name: "untagged") {} | ||
| let plan = await Runner.Plan(tests: [test1, test2, test3, test4], configuration: configuration) | ||
| let planTests = plan.steps.map(\.test) | ||
| #expect(planTests.contains(test1)) | ||
| #expect(!planTests.contains(test2)) | ||
| #expect(!planTests.contains(test3)) | ||
| #expect(!planTests.contains(test4)) | ||
| } | ||
|
|
||
| @Test("--filter or --skip tag: argument with bad regex") | ||
| func filterByTagWithBadRegex() throws { | ||
| #expect(throws: (any Error).self) { | ||
| _ = try configurationForEntryPoint(withArguments: ["PATH", "--filter", "tag:("]) | ||
| } | ||
| #expect(throws: (any Error).self) { | ||
| _ = try configurationForEntryPoint(withArguments: ["PATH", "--skip", "tag:)"]) | ||
| } | ||
| } | ||
|
|
||
| @Test("--filter or --skip argument as last argument") | ||
| func filterOrSkipAsLast() async throws { | ||
| _ = try configurationForEntryPoint(withArguments: ["PATH", "--filter"]) | ||
|
|
||
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.
suggestion: can we add a test cast that includes and skips tests in the same execution? e.g.:
--filter tag:foo --skip id:barThere 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.
good shout, added this and some more tests in 8ab8d13