Skip to content
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

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

Open
younata opened this issue Jun 13, 2024 · 2 comments
Open

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

younata opened this issue Jun 13, 2024 · 2 comments

Comments

@younata
Copy link

younata commented Jun 13, 2024

Hello!

I'm maintainer of Nimble, a framework that provides an alternative assertion DSL for Swift and Objective-C. Earlier today, I noticed that Nimble's integration with XCTest on Linux & Windows is lacking, which is entirely because there isn't a good place for Nimble to register its XCTestObservation conformer - which is how Nimble currently keeps track of the current test case - in a non-objc environment. On Darwin platforms, Nimble registers its XCTestObservation conformer when it's loaded, but that only works when the objc runtime is available.

Naively, I would think that making XCTCurrentTestCase publicly readable would solve this issue for Nimble, such as this patch:

diff --git a/Sources/XCTest/Public/XCTestCase.swift b/Sources/XCTest/Public/XCTestCase.swift
index 2d899b9..6e229fe 100644
--- a/Sources/XCTest/Public/XCTestCase.swift
+++ b/Sources/XCTest/Public/XCTestCase.swift
@@ -25,7 +25,7 @@ public typealias XCTestCaseEntry = (testCaseClass: XCTestCase.Type, allTests: [(

 // A global pointer to the currently running test case. This is required in
 // order for XCTAssert functions to report failures.
-internal var XCTCurrentTestCase: XCTestCase?
+public private(set) var XCTCurrentTestCase: XCTestCase?

 /// An instance of this class represents an individual test case which can be
 /// run by the framework. This class is normally subclassed and extended with

Which would work, but I'm curious if that's actually the right approach that should be used here. There's probably a very good reason you haven't made XCTCurrentTestCase publicly readable, after all.

@grynspan
Copy link
Contributor

grynspan commented Jul 2, 2024

Would you mind also filing feedback against Apple's XCTest implementation and let us know the FB number here? To add API for this to corelibs-xctest, we generally would want to add it to XCTest.framework first. (Mmm, bureaucracy.)

@younata
Copy link
Author

younata commented Jul 2, 2024

FB14167426

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants