Skip to content

TestFoundation: Add infrastructure to assert that a test should crash #2270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2019
Merged

TestFoundation: Add infrastructure to assert that a test should crash #2270

merged 1 commit into from
May 15, 2019

Conversation

millenomi
Copy link
Contributor

You can now define tests as follows:

func testCrashes() {
     assertCrashes {
          fatalError()
     }
}

These tests will spawn a child process and will assert that the child process crashes while executing the code in the block. Wrap the entire body of the test this way.

You can now define tests as follows:

```
func testCrashes() {
     assertCrashes {
          fatalError()
     }
}
```

These tests will spawn a child process and will assert that the child process crashes while executing the code in the block.
@millenomi
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@millenomi
Copy link
Contributor Author

@swift-ci please test

@@ -521,3 +521,38 @@ func testExpectedToFail<T>(_ test: @escaping (T) -> () throws -> Void, _ reason
return { _ in return { } }
}
}

extension XCTest {
func assertCrashes(within block: () throws -> Void) rethrows {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@airspeedswift This might interest you.

@gottesmm
Copy link
Contributor

Also +1 Lily! = ). You are awesome!

@millenomi millenomi merged commit be1cf86 into swiftlang:master May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants