-
Notifications
You must be signed in to change notification settings - Fork 74
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 the ability for a trait to run code before and after a test #86
Conversation
@swift-ci please test |
4a67fe3
to
1c67819
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.
Most of my comments are just about documentation and naming. I think the overall shape of the PR is good.
1c67819
to
33e8c15
Compare
@swift-ci please test |
3c8b1c7
to
4874835
Compare
Sources/Testing/Traits/Trait.swift
Outdated
/// `test` represents a test function, this function is the body of that | ||
/// test function (including all cases if it is parameterized.) | ||
/// - test: The test under which `function` is being performed. | ||
/// - testCase: The testCase under which `function` is being performed. |
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.
/// - testCase: The testCase under which `function` is being performed. | |
/// - testCase: The test case under which `function` is being performed. |
This seems really cool. I am wondering if we can also provide something that can run a test in a |
This new API should support that use case, if I understand you correctly. Or if you don't think it will, can you elaborate? |
4874835
to
a3738c1
Compare
@swift-ci please test |
@@ -81,6 +81,40 @@ public protocol SuiteTrait: Trait { | |||
var isRecursive: Bool { get } | |||
} | |||
|
|||
/// A protocol extending ``Trait`` that offers an additional customization point |
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 want to do an editorial pass on this type's documentation after we promote it to API, but it's fine at this point.
a3738c1
to
922a000
Compare
922a000
to
e4a3ef2
Compare
@swift-ci please test |
Add the ability for a trait to run code before and after a test.
Motivation:
As laid out in the vision document, we want traits to become extensible, and be able to invoke code before and after a test's body is invoked.
This PR provides the foundation that will not just give test authors a lot more power and flexibility in what they can achieve with traits, but will allow us (in a future PR) to re-implement e.g. the timeout behavior to be less special-cased.
Modifications:
I added a new protocol
CustomExecutionTrait
which inherits fromTrait
, that has a single additional requirement: anexecute
function that provides a function that eventually executes the test body in its argument so that trait authors can invoke it in whatever way they need, ie. have the ability to execute code before and after they invoke that function.An example of such a trait is
(or see
CustomTraitTest
).Result:
Test authors now have a much more flexible system to write traits, allowing them to execute custom code before and after a test body is run.