Skip to content

Add an attribute that emits a warning.#895

Merged
grynspan merged 2 commits into
mainfrom
jgrynspan/warning-attribute
Jan 7, 2025
Merged

Add an attribute that emits a warning.#895
grynspan merged 2 commits into
mainfrom
jgrynspan/warning-attribute

Conversation

@grynspan

@grynspan grynspan commented Jan 7, 2025

Copy link
Copy Markdown
Contributor

This PR adds an attribute (an overload of @__testing()) that emits a warning. This allows us to emit compile-time warnings from contexts where only attributes are semantically valid.

We need this in particular for test content records because their section info is comprised of a big IfConfigDecl node and platforms that aren't covered (i.e. the #else clause) don't have a way to emit a diagnostic that says "we need to fix this platform's Swift Testing port!" like we can do in other contexts with #warning():

#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) || os(visionOS)
@_section("__DATA_CONST,__swift5_tests")
#elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) || os(WASI)
@_section("swift5_tests")
#elseif os(Windows)
@_section(".sw5test$B")
#else
// ⚠️ #warning isn't valid here, what do we do!?
#endif
@_used
private static let record: __TestContentRecord = (...)

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 an attribute (an overload of `@__testing()`) that emits a warning.
This allows us to emit compile-time warnings from contexts where only attributes
are semantically valid.

We need this in particular for test content records because their section info
is comprised of a big `IfConfigDecl` node and platforms that aren't covered
(i.e. the `#else` clause) don't have a way to emit a diagnostic that says "we
need to fix this platform's Swift Testing port!" like we can do in other
contexts with `#warning()`:

```swift
@_section("__DATA_CONST,__swift5_tests")
@_section("swift5_tests")
@_section(".sw5test$B")
// ⚠️ #warning isn't valid here, what do we do!?
@_used
private static let record: __TestContentRecord = (...)
```
@grynspan grynspan added enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later) build 🧱 Affects the project's build configuration or process labels Jan 7, 2025
@grynspan grynspan added this to the Swift 6.x milestone Jan 7, 2025
@grynspan grynspan self-assigned this Jan 7, 2025
@grynspan

grynspan commented Jan 7, 2025

Copy link
Copy Markdown
Contributor Author

@swift-ci test

Comment thread Sources/TestingMacros/PragmaMacro.swift
Comment thread Tests/TestingMacrosTests/PragmaMacroTests.swift
@grynspan

grynspan commented Jan 7, 2025

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@grynspan grynspan merged commit 6f7688a into main Jan 7, 2025
@grynspan grynspan deleted the jgrynspan/warning-attribute branch January 7, 2025 19:05
@grynspan grynspan added the discovery 🔎 test content discovery label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build 🧱 Affects the project's build configuration or process discovery 🔎 test content discovery enhancement New feature or request workaround Workaround for an issue in another component (may need to revert later)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants