EXC_BAD_ACCESS crash in some Swift Testing test on a macro

Hi,

I'm trying to test a view model that conforms to ObservableObject with swift testing.

My test looks like

@Test("When a filter is selected the 'save search' button is enabled")
    func testWhenAFilterIsSelectedTheSaveButtonIsEnabled() {
        let viewModel = GxClassSearchFormViewModel(
            filterSelection: .init(),
            currentSavedSearch: nil
        )

        // when
        viewModel.filterSelection.clubs.select(hasle)

        // then
        #expect(viewModel.savedSearchState == .active)
        #expect(viewModel.isSavedSearchButtonDisabled)
    }

Interestingly, this test crashes on the iOS 16.2 Simulator. I'm using Version 16.2 (16C5032a)

It crashes at the macro level like:

And I don't understand what's wrong really. Maybe a concurrency issue? not sure.

Xcode stops the execution and the debug navigator shows and incredibly long stack trace. I add images from the top and bottom of it as it's too long to add it all

Has anyone experience a similar issue? It has happened to me in other tests too, sometimes when using #required

As extra context.

I realized the test was "wrong", instead of testing

#expect(viewModel.isSavedSearchButtonDisabled)

I needed to test

#expect(viewModel.isSavedSearchButtonDisabled == false)

With this change, the test passed correctly without crashing. This implies that this crash happens on test failures

Also, If I wrote the expectation like

#expect(viewModel.savedSearchState == .active && viewModel.isSavedSearchButtonDisabled)

The test would fail (as per logic), but it wouldn't crash.

huh?

EXC_BAD_ACCESS crash in some Swift Testing test on a macro
 
 
Q