-
Notifications
You must be signed in to change notification settings - Fork 112
Refactor test content discovery to produce a sequence. #914
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
Conversation
This PR does away with `enumerateTestContent {}` and replaces it with `discover()`, a function that returns a sequence of `TestContentRecord` instances that the caller can then inspect. This simplifies the logic in callers by letting them use sequence operations/monads like `map()`, and simplifies the logic in the implementation by doing away with intermediate tuples and allowing it to just map section bounds to sequences of `TestContentRecord` values. Evaluation of the accessor functions for test content records is now lazier, allowing us to potentially leverage the `context` field of a test content record to avoid calling accessors for records we know won't match due to the content of that field. (This functionality isn't currently needed, but could be useful for future test content types.)
@swift-ci test |
Note the rendering of the diff is terrible. Might help to just look at one side or the other. |
case legacyOnly | ||
} | ||
let discoveryMode: DiscoveryMode = switch Environment.flag(named: "SWT_USE_LEGACY_TEST_DISCOVERY") { | ||
let (useNewMode, useLegacyMode) = switch Environment.flag(named: "SWT_USE_LEGACY_TEST_DISCOVERY") { |
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.
This change makes it easier to disable this code in #880.
@@ -615,43 +615,45 @@ struct MiscellaneousTests { | |||
0xABCD1234, | |||
0, | |||
{ outValue, hint in | |||
if let hint, hint.loadUnaligned(as: TestContentAccessorHint.self) != expectedHint { | |||
if let hint, hint.load(as: TestContentAccessorHint.self) != expectedHint { |
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.
The hint is always well-aligned.
@swift-ci test |
1 similar comment
@swift-ci test |
Sources/Testing/Discovery.swift
Outdated
/// - Returns: A sequence of instances of ``TestContentRecord``. Only test | ||
/// content records matching this ``TestContent`` type's requirements are | ||
/// included in the sequence. | ||
static func discover() -> some Sequence<TestContentRecord<Self>> { |
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.
Can you talk about the choice of name? I might suggest a property instead of a function and naming it something like allRecords
or allTestContentRecords
. At the call site, discover()
feels more like an imperative instruction rather than a call which returns a value to me.
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.
Changed.
@swift-ci test |
@swift-ci test |
@swift-ci test |
This PR does away with
enumerateTestContent {}
and replaces it withdiscover()
, a function that returns a sequence ofTestContentRecord
instances that the caller can then inspect. This simplifies the logic in callers by letting them use sequence operations/monads likemap()
, and simplifies the logic in the implementation by doing away with intermediate tuples and allowing it to just map section bounds to sequences ofTestContentRecord
values.Evaluation of the accessor functions for test content records is now lazier, allowing us to potentially leverage the
context
field of a test content record to avoid calling accessors for records we know won't match due to the content of that field. (This functionality isn't currently needed, but could be useful for future test content types.)Checklist: