{"id":16755776,"url":"https://github.com/norio-nomura/xctassertcrash","last_synced_at":"2025-08-02T09:14:41.455Z","repository":{"id":63919328,"uuid":"198034542","full_name":"norio-nomura/XCTAssertCrash","owner":"norio-nomura","description":"Asserts that an expression crashes by using Mach Exception Handler or POSIX Signal Handler.","archived":false,"fork":false,"pushed_at":"2019-11-04T10:21:56.000Z","size":65,"stargazers_count":51,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-29T12:41:06.983Z","etag":null,"topics":["ios","linux","macos","swift","testing","xctassert","xctest"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/norio-nomura.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-07-21T08:55:47.000Z","updated_at":"2023-07-06T14:33:38.000Z","dependencies_parsed_at":"2022-11-29T10:45:07.417Z","dependency_job_id":null,"html_url":"https://github.com/norio-nomura/XCTAssertCrash","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/norio-nomura/XCTAssertCrash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norio-nomura%2FXCTAssertCrash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norio-nomura%2FXCTAssertCrash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norio-nomura%2FXCTAssertCrash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norio-nomura%2FXCTAssertCrash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/norio-nomura","download_url":"https://codeload.github.com/norio-nomura/XCTAssertCrash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/norio-nomura%2FXCTAssertCrash/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266404941,"owners_count":23923492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","linux","macos","swift","testing","xctassert","xctest"],"created_at":"2024-10-13T03:23:45.120Z","updated_at":"2025-07-22T00:32:48.547Z","avatar_url":"https://github.com/norio-nomura.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XCTAssertCrash\nAsserts that an expression crashes by using Mach Exception Handler or POSIX Signal Handler.\n\nOn Apple Platforms except tvOS, it uses Mach Exception Handler.  \nOn other Platforms like Linux or tvOS, it uses POSIX Signal Handler. \n\n[![SwiftPM](https://github.com/norio-nomura/XCTAssertCrash/workflows/SwiftPM/badge.svg)](https://launch-editor.github.com/actions?workflowID=SwiftPM\u0026event=pull_request\u0026nwo=norio-nomura%2FXCTAssertCrash)\n[![xcodebuild](https://github.com/norio-nomura/XCTAssertCrash/workflows/xcodebuild/badge.svg)](https://launch-editor.github.com/actions?workflowID=xcodebuild\u0026event=pull_request\u0026nwo=norio-nomura%2FXCTAssertCrash)\n[![Nightly](https://github.com/norio-nomura/XCTAssertCrash/workflows/Nightly/badge.svg)](https://launch-editor.github.com/actions?workflowID=Nightly\u0026event=pull_request\u0026nwo=norio-nomura%2FXCTAssertCrash)\n\n## Usage\n\n```swift\n/// Asserts that an expression crashes.\n/// - Parameters:\n///     - expression: An `expression` that can crash.\n///     - message: An optional description of the failure.\n///     - file: The file in which failure occurred.\n///             Defaults to the file name of the test case in which this function was called.\n///     - line: The line number on which failure occurred.\n///             Defaults to the line number on which this function was called.\n///     - signalHandler: An optional handler for signal that are produced by `expression`.\n///                      `SIGILL`, `SIGABRT` or `0` (if `expression` did not crash)\n///     - stdoutHandler: An optional handler for stdout that are produced by `expression`.\n///     - stderrHandler: An optional handler for stderr that are produced by `expression`.\n///     - skipIfBeingDebugged: Skip `expression` if process is being debugged.\n///                            Use `skipXCTAssertCrashIfIsBeingDebugged` as default.\n/// - Returns: A value of type `T?`, the result of evaluating the given `expression`.\n///            `nil` if `expression` crashed.\n@discardableResult\npublic func XCTAssertCrash\u003cT\u003e(\n    _ expression: @escaping @autoclosure () -\u003e T,\n    _ message: @autoclosure () -\u003e String = \"\",\n    file: StaticString = #file,\n    line: UInt = #line,\n    signalHandler: (Int32) -\u003e Void = { _ in },\n    stdoutHandler: (String) -\u003e Void = { _ in },\n    stderrHandler: (String) -\u003e Void = { _ in },\n    skipIfBeingDebugged: Bool = skipXCTAssertCrashIfIsBeingDebugged\n) -\u003e T?\n```\n\n## Limitations\n\n### Mach Exception Handler\n- `XCTAssertCrash` can not handle crashes caused by `abort()`.\n- `XCTAssertCrash` can not handle a breakpoint set in expression. On detecting a stop at a breakpoint set by the debugger, `XCTAssertCrash` generates `assertionFailure()`.\n\n### POSIX Signal Handler\n-  `lldb` will catch the signal and stop on crash before `XCTAssertCrash` detects it.\n- **So, if the process is being debugged, `XCTAssertCrash` will skip the evaluation of the expression by default.**  \n    To avoid this behavior,\n    - Set `skipXCTAssertCrashIfIsBeingDebugged` to `false`.  \n    or  \n    - Disable debug.  \n        e.g. In Xcode, go to 'Edit Scheme \u003e Test \u003e Info' and uncheck 'Debug Executable'.\n\n\n## Author\n\nNorio Nomura\n\n## License\n\nThis package is available under the MIT license. See the LICENSE file for more info.\n\n## References\n- [Partial functions in Swift, Part 2: Catching precondition failures](http://www.cocoawithlove.com/blog/2016/02/02/partial-functions-part-two-catching-precondition-failures.html) by Matt Gallagher\n- [Friday Q\u0026A 2013-01-11: Mach Exception Handlers](https://www.mikeash.com/pyblog/friday-qa-2013-01-11-mach-exception-handlers.html) by Landon Fuller\n- Mac OS X and iOS Internals by Jonathan Levin\n- [The Darwin Kernel](https://github.com/apple/darwin-xnu) by Apple\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorio-nomura%2Fxctassertcrash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnorio-nomura%2Fxctassertcrash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnorio-nomura%2Fxctassertcrash/lists"}