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

Add ability to run only one(focused) example #3911

Merged
merged 3 commits into from
Mar 22, 2022

Conversation

PaulTaykalo
Copy link
Collaborator

@PaulTaykalo PaulTaykalo commented Mar 20, 2022

Adds helper method, that allows marking only one example to be run when running tests

Sometimes, when specific rule example is debugged, it is really helpful to run one 'test'/'example'.
This PR adds ability to mark Examples that need to be checked when running tests

i.e.

nonTriggeringExamples: [
    Example("let x: [Int]"),
    Example("let x: [Int: String]").focused()   // only this one will be run in tests
],
triggeringExamples: [
    Example("let x: ↓Array<String>"),
    Example("let x: ↓Dictionary<Int, String>")
]

In case if multiple examples marked as 'focused', then all of them will be checked when running tests.

This PR is inspired by the same functionality in other testing frameworks:
https://github.com/Quick/Quick/blob/72e9afa98f00c719b16c359d67d95366bad0a460/Documentation/en-us/QuickExamplesAndGroups.md#temporarily-running-a-subset-of-focused-examples

@PaulTaykalo PaulTaykalo self-assigned this Mar 20, 2022
@PaulTaykalo PaulTaykalo force-pushed the feature/add-focused-examples branch 2 times, most recently from 9099919 to 80f8524 Compare March 20, 2022 08:47
@SwiftLintBot
Copy link

SwiftLintBot commented Mar 20, 2022

12 Messages
📖 Linting Aerial with this PR took 0.98s vs 0.97s on master (1% slower)
📖 Linting Alamofire with this PR took 1.11s vs 1.11s on master (0% slower)
📖 Linting Firefox with this PR took 4.12s vs 4.12s on master (0% slower)
📖 Linting Kickstarter with this PR took 7.38s vs 7.4s on master (0% faster)
📖 Linting Moya with this PR took 4.42s vs 4.35s on master (1% slower)
📖 Linting Nimble with this PR took 0.4s vs 0.4s on master (0% slower)
📖 Linting Quick with this PR took 0.17s vs 0.17s on master (0% slower)
📖 Linting Realm with this PR took 9.58s vs 10.41s on master (7% faster)
📖 Linting SourceKitten with this PR took 0.33s vs 0.33s on master (0% slower)
📖 Linting Sourcery with this PR took 2.02s vs 2.01s on master (0% slower)
📖 Linting Swift with this PR took 3.14s vs 3.15s on master (0% faster)
📖 Linting WordPress with this PR took 7.39s vs 7.29s on master (1% slower)

Generated by 🚫 Danger

@codecov-commenter
Copy link

codecov-commenter commented Mar 20, 2022

Codecov Report

Merging #3911 (fd2d9fe) into master (702b36a) will decrease coverage by 0.05%.
The diff coverage is 60.71%.

@@            Coverage Diff             @@
##           master    #3911      +/-   ##
==========================================
- Coverage   92.61%   92.56%   -0.06%     
==========================================
  Files         436      436              
  Lines       21964    21990      +26     
==========================================
+ Hits        20343    20355      +12     
- Misses       1621     1635      +14     
Impacted Files Coverage Δ
Source/SwiftLintFramework/Models/Example.swift 86.20% <20.00%> (-13.80%) ⬇️
Tests/SwiftLintFrameworkTests/TestHelpers.swift 79.08% <69.56%> (-0.80%) ⬇️
Source/SwiftLintFramework/Models/Linter.swift 79.09% <0.00%> (-1.70%) ⬇️

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@SimplyDanny
Copy link
Collaborator

I like the idea of focusing on specific examples. Commenting out all but the relevant examples finds an end with this.

I wonder, though, whether it can be made sure that code with focused examples is not checked in. There could be a custom SwiftLint rule which checks for .focused() in rule code. Or the build breaks somehow if the function is called while running on CI.

Copy link
Collaborator

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this will be helpful!

@jpsim
Copy link
Collaborator

jpsim commented Mar 20, 2022

Ah yes Danny's suggestion would be good to consider. I'd be ok if we had a custom rule preventing this from being checked in.

CONTRIBUTING.md Outdated Show resolved Hide resolved
@PaulTaykalo
Copy link
Collaborator Author

@jpsim is there any additional env that is set on CI?

@PaulTaykalo
Copy link
Collaborator Author

@jpsim how about allowing this functionality under #if DEBUG only ?

@PaulTaykalo PaulTaykalo force-pushed the feature/add-focused-examples branch 2 times, most recently from ebb1b71 to 6f08114 Compare March 20, 2022 14:41
@PaulTaykalo
Copy link
Collaborator Author

@jpsim @SimplyDanny
added DISABLE_FOCUSED_EXAMPLES conditional, which will be enabled only on CI
If this conditional enabled, focused examples will fail
image

CONTRIBUTING.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
PaulTaykalo and others added 2 commits March 22, 2022 18:37
Co-authored-by: JP Simard <jp@jpsim.com>
Co-authored-by: JP Simard <jp@jpsim.com>
@PaulTaykalo PaulTaykalo merged commit 1616023 into master Mar 22, 2022
@PaulTaykalo PaulTaykalo deleted the feature/add-focused-examples branch March 22, 2022 17:21
coffmark pushed a commit to coffmark/SwiftLint that referenced this pull request Apr 11, 2022
* Add ability to focus on a specific test example

* Update CHANGELOG.md

Co-authored-by: JP Simard <jp@jpsim.com>

* Update CONTRIBUTING.md

Co-authored-by: JP Simard <jp@jpsim.com>

Co-authored-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants