Bug 312797
| Summary: | [Swift Testing] Add Swift-callable wrapper around InstanceMethodSwizzler for TestWebKitAPI | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | zak ridouh <zakr> |
| Component: | Tools / Tests | Assignee: | zak ridouh <zakr> |
| Status: | RESOLVED FIXED | ||
| Severity: | Normal | CC: | webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | WebKit Nightly Build | ||
| Hardware: | Unspecified | ||
| OS: | Unspecified | ||
zak ridouh
The C++ InstanceMethodSwizzler RAII helper is gated behind #ifdef
__cplusplus and is not callable from Swift, so Swift tests in
TestWebKitAPI cannot mock Objective-C runtime behavior. This is the
first piece of infrastructure needed to port AppKit-heavy tests
(NSMenu pop-ups, gesture recognizers, drag-and-drop) to the new
Swift Testing framework.
Add TestMethodSwizzler, a thin @interface around InstanceMethodSwizzler
that takes a block, runs it through imp_implementationWithBlock, and
restores the original implementation in -dealloc. Swift callers hold
the swizzler in a local binding for as long as the swizzle should
remain in effect, mirroring the C++ RAII pattern.
Add a smoke test that swizzles a no-arg Int-returning method on a
Swift @objc class, verifies the replacement IMP is called, and
verifies the original is restored once the swizzler is dropped.
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
Radar WebKit Bug Importer
<rdar://problem/175186623>
zak ridouh
Pull request: https://github.com/WebKit/WebKit/pull/63141
EWS
Committed 312863@main (a41a909424f0): <https://commits.webkit.org/312863@main>
Reviewed commits have been landed. Closing PR #63141 and removing active labels.