kishikawakatsumi/swift-power-assert is one of the mobile-focused repositories TopGit tracks, currently at 493 stars, written primarily in Swift. Power Assert in Swift.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Power asserts (also known as diagrammed assertions) augment your assertion failures with information about the values produced during evaluation of a condition, and present it in an easily digestible form. Power asserts are a popular feature of Spock (and later the entire Groovy language independent of Spock), ScalaTest and Expecty.
Power asserts provide descriptive assertion messages for your tests, like the following examples:
Experience the library in action with our online playground! :sparkles: Click here to access the interactive demo.
Why Power Assert?
When writing tests, we need to use different assertion functions. With Power Assert you only use the #assert() function. There are many
Assertion APIs, no need to remember them. Just create an expression that returns a boolean value and Power Assert will automatically display rich error information.
Getting Started
Requirements:
Swift 5.9 or later
Xcode 15.0 or later
For Xcode Project
To see PowerAssert in action, go to the Examples directory and run xcodebuild test ....
$ cd Examples/XcodeProject/
$ xcodebuild test -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=17.0' -parallel-testing-enabled NO
The parameter -parallel-testing-enabled NO is required. Due to recent changes in Xcode, parallel testing is now turned on by default and test messages are no longer output to the console. Therefore, to see assertion messages in the console, disable parallel testing. When parallel testing is enabled, all console logs can be viewed from the result bundle.
Or set the following UserDefaults. This option allows console output even if parallel testing is enabled.
To see PowerAssert in action, go to the Examples directory and run swift test.
$ cd Examples/SwiftPackage/
$ swift test
See the following results?
...
Test Suite 'All tests' started at 2023-04-05 07:17:58.800
Test Suite 'swift-power-assert-examplePackageTests.xctest' started at 2023-04-05 07:17:58.801
Test Suite 'PowerAssertTests' started at 2023-04-05 07:17:58.801
Test Case '-[ExampleTests.PowerAssertTests testExample]' started.
/swift-power-assert/Example/"ExampleTests/ExampleTests.swift":8: error: -[ExampleTests.PowerAssertTests testExample] : failed -
#assert(a * b == 91)
│ │ │ │ │
│ │ 9 │ 91
│ 90 false
10
[Int] a
=> 10
[Int] b
=> 9
[Int] a * b
=> 90
[Int] 91
=> 91
/swift-power-assert/Example/"ExampleTests/ExampleTests.swift":11: error: -[ExampleTests.PowerAssertTests testExample] : failed -
#assert(xs.contains(4))
│ │ │
│ false 4
[1, 2, 3]
...
Modify the code in Example/Tests/ExampleTests.swift to try different patterns you like.
Usage
To use Swift Power Assert in your library or application, first add swift-power-assert to your project.
For the Xcode project, add the swift-power-assert library as a package dependency.
Select PowerAssert as the Package Product and specify the Test Bundle as the target to add.
For the Swift package, configure Package.swift as follows:
Next, you can use Power Assert in your tests with the #assert() macro.
// MyLibraryTests.swift
import XCTest
import PowerAssert
@testable import MyLibrary
final class MyLibraryTests: XCTestCase {
func testExample() {
let a = 7
let b = 4
let c = 12
#assert(max(a, b) == c)
}
}
Concurrency (async/await) support
Swift Power Assert library allows you to write assertions with async/await expressions directly. Here's a sample code demonstrating its seamless support for async/await:
func testConcurrency() async {
let ok = "OK"
#assert(await upload(content: "example") == ok)
}
For use on CI
For unattended use (e.g. on CI), you can disable the package validation dialog by
individually passing -skipMacroValidation to xcodebuild or
globally setting defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES
for that user.
Frequently Asked Questions
Q: Assert failure messages are not displayed.
If you are running your tests from the command line using the xcodebuild test ... command, disable parallel testing. Due to recent changes in Xcode, detailed test logs are not output to the console when parallel testing is enabled. Use the following options to disable parallel testing
-parallel-testing-enabled NO
Alternatively, set the following UserDefaults. This option enables detailed messages to be output to the console even parallel testing enabled.
Q: I want to display the result even if the test is successful (i.e. the expression in the #assert() function evaluates to true).
A: By default, the #assert() function does not display the result if the expression evaluates to true, because the test was successful. To always print the result, set the verbose argument to true.
For example:
#assert(x == y, verbose: true)
Q: I want to know how the compiler actually expanded the macro.
A: You can use the -dump-macro-expansions option to dump the macro expansion.
For example:
$ cd Examples/SwiftPackage/
$ swift test -Xswiftc -Xfrontend -Xswiftc -dump-macro-expansions
If you run the above with the -dump-macro-expansions option, you will get the following output.
Open source projects thrive on the generosity and support of people like you. If you find this project valuable, please consider extending your support. Contributing to the project not only sustains its growth, but also helps drive innovation and improve its features.
To support this project, you can become a sponsor through GitHub Sponsors. Your contribution will be greatly appreciated and will help keep the project alive and thriving. Thanks for your consideration! :heart:
How active is development on kishikawakatsumi/swift-power-assert?
The most recent commit recorded on kishikawakatsumi/swift-power-assert was 4 days ago, based on the GitHub push timestamp. The repository has 12 forks — one of the better signals of community interest.
How many stars does kishikawakatsumi/swift-power-assert have?
kishikawakatsumi/swift-power-assert has 493 GitHub stars — refresh the page for the live number, or check github.com/kishikawakatsumi/swift-power-assert. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is kishikawakatsumi/swift-power-assert open source?
Yes — kishikawakatsumi/swift-power-assert ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/kishikawakatsumi/swift-power-assert.
What else is in the Mobile space?
kishikawakatsumi/swift-power-assert is tracked by TopGit under the Mobile category, alongside 3 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What topics is kishikawakatsumi/swift-power-assert associated with?
GitHub's repository topics for kishikawakatsumi/swift-power-assert: "power-assert", "swift", "testing". TopGit's editorial category is Mobile.
Where can I see kishikawakatsumi/swift-power-assert in action?
The project maintains a homepage at https://power-assert.swiftfiddle.com/. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about kishikawakatsumi/swift-power-assert?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/kishikawakatsumi/swift-power-assert is the definitive source.
Read full README in the tab above.
Curious whether swift-power-assert is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about swift-power-assert.