Skip to content

Add XCTestCase.current property. - #535

Open
grynspan wants to merge 1 commit into
mainfrom
jgrynspan/491-XCTestCase.current
Open

Add XCTestCase.current property.#535
grynspan wants to merge 1 commit into
mainfrom
jgrynspan/491-XCTestCase.current

Conversation

@grynspan

@grynspan grynspan commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

This PR adds a class property to XCTestCase to let you get the currently-running instance. We already have equivalent API in Swift Testing.

Resolves #491.
Resolves rdar://130966686.

This PR adds a class property to `XCTestCase` to let you get the currently-running
instance. We already have equivalent API in Swift Testing.

Resolves #491.
Resolves rdar://130966686.
@grynspan

grynspan commented Mar 9, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@jerryjrchen jerryjrchen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM assuming the potential defer out of order issue isn't a big deal. Note this will probably conflict with #538

Self._current.withLock { $0 = nil }
}
testRun.start()
defer {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These defer blocks could execute out of order right? So it's possible for testRun.stop() to happen after current test case is set to nil. Can that lead to any correctness issues?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Within a given function, defer blocks always execute in the reverse of the order they are declared in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Provide API to determine to grab the currently-running XCTest.

2 participants