Skip to content
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

[SR-5262] XCTest should have a way to validate assertions (e.g. assert()) #370

Open
phausler opened this issue Jun 19, 2017 · 1 comment

Comments

@phausler
Copy link
Member

Previous ID SR-5262
Radar None
Original Reporter @phausler
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s XCTest
Labels New Feature
Assignee None
Priority Medium

md5: 45492463837a5115b54a5e4cdffbc273

Issue Description:

Often times when testing code it is helpful to validate assertion cases that have preconditions or fatalErrors. A method that would aide in this endeavor would be something along the lines of XCTAssertIsFatal where a block of code is passed in that is expected to trigger a fatalError.

Normally this would mean that the code would crash. However if a signal handler for SIGILL is installed we can validate if an assertion is tripped.

See https://github.com/phausler/swift-corelibs-xctest/tree/assert_fatal for a rough draft at handling fatal assertions (note this only works in a non attached debugger mode and has only been written for Darwin, however a linux port should be trivial)

@belkadan
Copy link

This has been discussed before. StdlibUnittest takes a different approach: fork off a child process, and check its output. That's a little less dangerous—recovering from a fatalError means leaking memory at the very least.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
@grynspan grynspan changed the title [SR-5262] XCTest should have a way to validate assertions [SR-5262] XCTest should have a way to validate assertions (e.g. assert()) Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants