Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

swift-testable-fatal-error

How to use expectFatalError()

func test_empty_MyCollection_raises_fatalError_when_accessing_element_before_startIndex() {
  let collection: MyCollection = []
 
  expectFatalError {
    // closure that should produce a fatalError()
    let _ = collection.index(before: collection.startIndex)
  } withMessage: {message, error in

    if let message = message {
      XCTAssertEqual(
      message,
      "Index out of bounds."
      )
    }
 
    if let error = error {
      XCTFail("\(error)")
    }
  }
}

NB

Testing Swift standard library does not seem to work as it must be ensuring that it calls Swift.fatalError preventing expectFatalError() from replacing the fatalError implementation.

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages