Swiftpack.co - StanfordBDHG/XCTRuntimeAssertions as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by StanfordBDHG.
StanfordBDHG/XCTRuntimeAssertions 1.0.1
XCTest extensions to test runtime assertions and preconditions
⭐️ 1
🕓 9 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/StanfordBDHG/XCTRuntimeAssertions.git", from: "1.0.1")

XCTRuntimeAssertions

Build and Test codecov DOI

Test assertions and preconditions using XCTest.

Overview

This package allows developers to test assertions and preconditions in tests using XCTest. This is done by overloading Swifts runtime assertions with functions provided by XCTRuntimeAssertions. These are always called in your System under Test. Only if requested within a unit test, their implementations are swapped to assert a runtime assertion.

Configure your System under Test

To configure your System under Test, you just need to import the XCTRuntimeAssertion package and call your runtime assertions functions as usual.

import XCTRuntimeAssertions

func foo() {
    precondition(someFooCondition, "Foo condition is unmet.")
    // ...
}

Testing Runtime Assertions

In your unit tests you can use the XCTRuntimeAssertion and XCTRuntimePrecondition functions to test a block of code for which you expect a runtime assertion to occur.

Below is a short code example demonstrating this for assertions:

try XCTRuntimeAssertion {
    assertionFailure()
}

Below is a short code example demonstrating this for preconditions:

try XCTRuntimePrecondition {
    preconditionFailure()
}

[!TIP] XCTRuntimeAssertion and XCTRuntimePrecondition also support the execution of async code.

Contributing

Contributions to this project are welcome. Please make sure to read the contribution guidelines and the contributor covenant code of conduct first.

License

This project is licensed under the MIT License. See Licenses for more information.

Stanford Byers Center for Biodesign Logo Stanford Byers Center for Biodesign Logo

GitHub

link
Stars: 1
Last commit: 9 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.1
9 weeks ago

What's Changed

Full Changelog: https://github.com/StanfordBDHG/XCTRuntimeAssertions/compare/1.0.0...1.0.1

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics