Repository navigation
Add MockView and SplitTreeTests - #10778
Merged
Merged
Conversation
jparise
reviewed
Feb 17, 2026
|
|
||
| // @preconcurrency suppresses Sendable errors from Codable on NSView | ||
| // but the Swift compiler still complains about it. | ||
| class MockView: NSView, @preconcurrency Codable, Identifiable { |
Contributor
There was a problem hiding this comment.
macos/Tests/Helpers/ currently contains tests for files under macos/Sources/Helpers/ rather than test helpers.
I don't have a strong opinion where this class should ultimately live, but it could start within SplitTreeTests.swift and move later once we have more use cases for it. Other options:
macos/Tests/macos/Tests/Mocks/
Contributor
Author
There was a problem hiding this comment.
Yeah, moving the Mock into SplitTreeTests makes a lot of sense to me. Done in ce66bea.
For the same logic, I think macos/Tests/Mocks/ would be a good home once it's reused since that path makes it clear they aren't tests either just mocks?
Contributor
There was a problem hiding this comment.
Yes, that makes sense to me.
jparise
approved these changes
Feb 17, 2026
Contributor
Author
Thanks! Huge fan of Ghostty and happy to help :) |
mitchellh
approved these changes
Feb 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces unit tests and a supporting Mock NSView for testing the SplitTree implementation in Swift. It includes 51 tests which achieve approximately 93.13% (949/1019) coverage of SplitTree.swift's branches.
Coverage
I chose this as a good place to start contributing to Ghostty because I was curious about the macOS implementation, and there was a specific request for help with testing (#7879).
My process for writing the tests was basically reading SplitTree.swift to understand it, then writing tests for each high-level method and checking against code coverage to capture all the code paths:
Running
rm -rf /tmp/ghostty-test.xcresult xcodebuild -project macos/Ghostty.xcodeproj \ -scheme GhosttyTest \ -configuration Debug \ test \ -destination 'platform=macOS' \ -enableCodeCoverage YES \ -resultBundlePath /tmp/ghostty-test.xcresult \ -only-testing:GhosttyTests/SplitTreeTests \ 2>&1 | xcbeautifyCoverage
This was originally implemented in ~38 commits, but I squashed them down to 1 commit for easier review.
AI Disclosure
The tests were written by me, but I used Opus 4.6 to explain some parts of the code, and then finally to provide feedback on the tests. It suggested tests for
nodeStructuralIdentityInSetandnodeStructuralIdentityDistinguishesLeavesas well as the Parameterized test,resizingAdjustsRatio, which seemed like a clever way to collapse 12 individual tests into 3 parameterized ones that still run 12 cases total. I didn't know this feature existed, and it seems like a great way to write tests that are more maintainable. I read this relatively new feature in the Swift Docs. I find this to be a particularly useful feature of Claude/related agents, where it can suggest better ways of writing something in a more idiomatic way, and it taught me something new, which is always fun.I'm more than happy to continue work on tests for #7879 and always welcome to any feedback you have.