-
Notifications
You must be signed in to change notification settings - Fork 22
Runnable support for indirect subclasses of XCTestCase #50
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
base: main
Are you sure you want to change the base?
Runnable support for indirect subclasses of XCTestCase #50
Conversation
- Added test suite in src/runnables_test.rs with 12 test cases - Tests cover Swift Testing (@suite, @test), XCTest, Quick, and AsyncSpec frameworks - Validates query captures for test classes and test functions - Added tree-sitter and tree-sitter-swift dev dependencies - Includes README documentation for test suite structure and usage All tests validate that the runnables query correctly identifies: - @suite annotations on structs/classes - @test annotations on functions (top-level and member) - XCTestCase subclasses and test methods (with 'test' prefix) - QuickSpec and AsyncSpec subclasses
- Use OnceLock to compile runnables query once and reuse across all tests - Cache Language instance to avoid redundant initialization - Reduced redundant language construction from 2x per test to 1x total - Tests still take ~58s due to tree-sitter 0.20 query compilation performance Performance analysis: - Language loading: <1ms (fast) - Query compilation: ~58s (bottleneck with tree-sitter 0.20) - Per-test parsing: <1s each The 58-second compilation time is a known issue with tree-sitter 0.20 when compiling complex queries. This optimization ensures compilation happens only once for the entire test suite rather than per-test.
- Upgrade tree-sitter from 0.20 to 0.25.10 - Upgrade tree-sitter-swift from 0.6.0 to 0.7.1 - Add streaming-iterator 0.1 as dev dependency API compatibility changes: - Update get_language() to return &'static Language - Use LanguageFn.into() for language initialization - Use StreamingIterator pattern for QueryMatches - Change from for-loop to while-let pattern for query matching Performance improvement: - Test suite now runs in ~4.6 seconds (down from ~68 seconds) - Query compilation is now essentially instant - All 12 tests pass successfully
…round - Add test_xctest_indirect_subclass() to document tree-sitter limitation * Tree-sitter queries cannot follow inheritance chains semantically * Only direct XCTestCase subclasses are detected * Indirect subclasses (MyTests <- MyTestsBase <- XCTestCase) are NOT detected - Add test_comment_annotation_for_indirect_subclass() to demonstrate workaround * Users can add '// @XCTestClass' comments before indirect subclasses * Tree-sitter CAN match comment + class patterns * Both classes and test functions are successfully captured * Provides opt-in mechanism for marking indirect test classes These tests provide documentation of current limitations and potential workarounds for users who need to support indirect XCTest inheritance.
Tree-sitter queries cannot follow inheritance chains semantically, so
indirect XCTest subclasses (MyTests <- MyTestsBase <- XCTestCase) are
not automatically detected.
This commit adds support for a comment-based workaround:
Usage:
class MyTestsBase: XCTestCase { }
// @XCTestClass
class MyTests: MyTestsBase {
func testSomething() { }
}
Changes:
- Added two new query patterns in runnables.scm to match @XCTestClass comments
- Added comprehensive documentation at the top of runnables.scm
- Updated test_xctest_indirect_subclass() to document the workaround
- Added test_xctest_indirect_subclass_with_annotation() to verify annotated classes work
- Added test_comment_annotation_for_indirect_subclass() with realistic example
- All 15 tests pass
This provides users with an opt-in mechanism for marking indirect XCTest
subclasses that need to be recognized as test classes.
|
We require contributors to sign our Contributor License Agreement, and we don't have @humblehacker on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
We require contributors to sign our Contributor License Agreement, and we don't have @humblehacker on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
The cla-bot has been summoned, and re-checked this pull request! |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
Add
@XCTestClassComment Annotation for Indirect Test SubclassesThis PR adds support for marking indirect XCTest subclasses using an
@XCTestClasscomment annotation, with comprehensive unit tests to validate the runnables query. Resolves #49.The Problem
Tree-sitter queries cannot traverse inheritance chains beyond the direct parent class. Classes like
class MyTests: BaseTestCase(whereBaseTestCase: XCTestCase) aren't detected as test classes, even though they contain valid test methods.The Solution
Add
@XCTestCasecomment annotation support inlanguages/swift/runnables.scm: