Improve reusable TestCase and Swift Testing integration - #2
Conversation
20d8a11 to
c6c86f1
Compare
Fix test infrastructure availability
Simplified code duplication and context description.
Refactor lastPathComponent to support Windows-style paths and remove Foundation dependency.
Added guidelines for collaborative coding workflow to improve interaction with maintainers.
Added testing requirements and TODOs for release preparation.
This reverts commit d82e8c0.
fix @available where macOS 12 was paired with watchOS 8
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ae7c4eef2e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| #if hasFeature(Embedded) || !canImport(Foundation) | ||
| let isMainThread = true | ||
| #endif | ||
| #else | ||
| let isMainThread = Thread.isMainThread // capture before we switch to main thread for printing | ||
| let message = String(describing: message) // convert to sendable item to avoid any thread issues. |
There was a problem hiding this comment.
Stringify debug values on non-Foundation runtimes
In a full-runtime configuration where Foundation is unavailable but Embedded Swift is not enabled, DebugMessage is Any, yet this branch only initializes isMainThread and skips the String(describing:) conversion. The call on line 364 then passes Any to the overload whose message parameter is String, so supported non-Foundation WASM or similar builds fail to compile; separate the Embedded and non-Foundation branches and stringify values in the latter.
Useful? React with 👍 / 👎.
| test: @escaping TestClosure, | ||
| tearDown: TestClosure? = nil | ||
| tearDown: TestClosure? = nil, | ||
| source: SourceContext = SourceContext() |
There was a problem hiding this comment.
Capture TestCase source at its caller
When callers omit source, Swift evaluates the nested SourceContext defaults where SourceContext() appears in this initializer rather than where the TestCase is created. A TestCase("foo") { ... } created in another file therefore records Test.swift:338 (and direct calls to this initializer record line 324), so normalization of any thrown non-TestFailure points diagnostics to the framework initializer instead of the test declaration. Capture #file, #function, #line, and #column as initializer defaults and construct the context in the body.
Useful? React with 👍 / 👎.
What changed
This draft PR keeps the work in two reviewable commits:
Consolidate TestCase execution and preserve diagnostics
execute()and the live-UIrun()path through one lifecycle implementation.awaitinsidedefer..paralleland.serializedexecution modes for tests that mutate process-global state.TestFailure, retaining file, function, line, column, and detailed expectation values..ERRORbefore throwing so command-line runs retain useful diagnostics.Add reusable Swift Testing module adapter
Compatibility Testing Libraryproduct in the same package and.swiftpmproject.ModuleTestEntry, one Swift Testing argument per CompatibilityTestCase.CustomTestStringConvertiblefor readable Xcode names such asDevice › Battery Tests › Reports current battery state.CustomTestArgumentEncodablefor stable argument identity and selective reruns.ModuleTestEntry.entries(including:)andentry.execute().Design decisions
TestCaseremains@MainActorbecause it owns observable UI progress and a mutable test closure. A sendable execution snapshot keeps detached execution safe and prevents the UI model from crossing actors.main {}remains distinct fromawait MainActor.run {}: the former schedules fire-and-forget work, while the latter awaits completion and can return a value.main/background/sleep/WASM overload consolidation belongs to follow-up PR Add awaited main and WebAssembly async threading fallbacks #3.Open draft review items
Before this PR is marked ready for review:
.serializedexecution truly exclusive against both serialized and parallel reusable tests;deferrather than automatically resetting all Compatibility settings around every test;Validation so far
Dependent follow-up
After this API is finalized and released, create a Device pull request that imports
CompatibilityTestingand replaces its duplicatedEntry/module lookup adapter withModuleTestEntry.