mattgallagher / CwlPreconditionTesting

A Mach exception handler that allows Swift precondition failures to be caught and tested.
ISC License
174 stars 45 forks source link

Xcode 15 hangs indefinitely when an exception is catched #32

Closed foleblanc-ceridian closed 9 months ago

foleblanc-ceridian commented 10 months ago

The unit tests that take advantage of the catchBadInstruction method run indefinitely using Xcode 15, making the IDE unresponsive (in some aspects* ). I am left having to force quit and try again.

In the example below, "Reached point 1" prints to the console, but not the second one.

        let keyDecoder = JSONDecoder.KeyDecodingStrategy.customKeyDecoder

        guard case .custom(let block) = keyDecoder else {
            XCTFail("customKeyDecoder should be custom")
            return
        }

        let result = catchBadInstruction {
           print("Reached point 1")
            _ = block([])
           print("Reached point 2")
       }

The expectation is for result to hold the exception thrown.

mattgallagher commented 9 months ago

@foleblanc-ceridian I'm not seeing any specific problems with the Mach exception handler. I suspect you're using the POSIX handler.

As noted in the "Update: an alternative using a POSIX signal handler" section from the original article:

The biggest problem is straightforward: it won’t run with lldb attached since lldb catches the EXC_BAD_INSTRUCTION, preventing the SIGILL from ever occurring (you must run without a debugger attached). For my typical “testing from within Xcode” usage scenario (where I always run with lldb attached) this point alone entirely rules out the signal handler version.

If you're running the LLDB version, you'll need to edit your "Scheme" (Xcode menubar -> Product -> Scheme -> Edit Scheme) and select "Test" from the left and uncheck "Debug executable".