Skip to content

Add the current configuration to Event.Context. #677

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Sep 11, 2024

This PR adds a var configuration: Configuration property to Event.Context and adds a verbosity property to Configuration. We solve two problems:

  1. An event handler cannot see the current configuration (without querying Configuration.current) which limits its ability to customize its behaviour; and
  2. The verbosity of human-readable output is tracked by individual event handlers when it is intended to be part of a test run's configuration.

Since the configuration contains the event handler to which we pass the event context, the eventHandler property of the context is cleared before the event handler is called (thus breaking any reference cycles.)

Callers of the internal Event.post() function are now required to either pass both the test and test case for the event, or to pass neither (in which case we now gather both from the runtime state in a single call rather than hitting the task-local twice.) This is effected with a tuple as an argument to Event.post() which is admittedly a bit wonky but does force our call sites to explicitly pass values for both the test and test case, where previously we could accidentally pass a specific test and then go look up the task-local current test case (which should have been nil in all the cases where we were doing this anyway.)

A couple of interfaces on the event recorder types have changed in this PR in source-breaking ways. The old interfaces remain present but deprecated; they will be removed later in the Swift 6.1 development cycle after tools authors have had time to migrate.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR adds a `var configuration: Configuration` property to `Event.Context`
and adds a `verbosity` property to `Configuration`. We solve two problems:

1. An event handler cannot see the current configuration (without querying
   `Configuration.current`) which limits its ability to customize its behaviour;
   and
2. The verbosity of human-readable output is tracked by individual event
   handlers when it is intended to be part of a test run's configuration.

Since the configuration contains the event handler to which we pass the event
context, the `eventHandler` property of the context is cleared before the event
handler is called (thus breaking any reference cycles.)

Callers of the internal `Event.post()` function are now required to either pass
_both_ the test and test case for the event, or to pass neither (in which case
we now gather both from the runtime state in a single call rather than hitting
the task-local twice.) This is effected with a tuple as an argument to
`Event.post()` which is admittedly a bit wonky but does force our call sites to
explicitly pass values for both the test and test case, where previously we
could accidentally pass a specific test and then go look up the task-local
current test case (which should have been `nil` in all the cases where we were
doing this anyway.)

A couple of interfaces on the event recorder types have changed in this PR in
source-breaking ways. The old interfaces remain present but deprecated; they
will be removed later in the Swift 6.1 development cycle after tools authors
have had time to migrate.
@grynspan grynspan added enhancement New feature or request tools integration Integration of swift-testing into tools/IDEs performance Performance issues labels Sep 11, 2024
@grynspan grynspan added this to the Swift 6.1 milestone Sep 11, 2024
@grynspan grynspan self-assigned this Sep 11, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan mentioned this pull request Sep 11, 2024
2 tasks
@grynspan grynspan merged commit cca6de2 into main Sep 11, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/add-configuration-to-event-context branch September 11, 2024 21:22
grynspan added a commit that referenced this pull request Sep 17, 2024
This PR restores/undeprecates the `verbosity` argument to
`HumanReadableOutputRecorder.record()` that was deprecated in #677. We still
need to be able to override the command-line-specified value in the event
stream.
grynspan added a commit that referenced this pull request Sep 17, 2024
…)`. (#707)

This PR restores/undeprecates the `verbosity` argument to
`HumanReadableOutputRecorder.record()` that was deprecated in #677. We
still need to be able to override the command-line-specified value in
the event stream.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request performance Performance issues tools integration Integration of swift-testing into tools/IDEs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants