{"id":13479949,"url":"https://github.com/kishikawakatsumi/swift-power-assert","last_synced_at":"2025-10-25T00:41:10.627Z","repository":{"id":157611833,"uuid":"613204525","full_name":"kishikawakatsumi/swift-power-assert","owner":"kishikawakatsumi","description":"Power Assert in Swift.","archived":false,"fork":false,"pushed_at":"2024-04-30T22:04:07.000Z","size":1332,"stargazers_count":480,"open_issues_count":10,"forks_count":11,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-05-02T00:32:52.835Z","etag":null,"topics":["power-assert","swift","testing"],"latest_commit_sha":null,"homepage":"https://power-assert.swiftfiddle.com/","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/kishikawakatsumi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"kishikawakatsumi"}},"created_at":"2023-03-13T05:33:17.000Z","updated_at":"2024-05-07T04:33:20.477Z","dependencies_parsed_at":"2023-10-14T23:17:13.064Z","dependency_job_id":"66a3785d-5fc6-4926-a94e-695ab93ee3d1","html_url":"https://github.com/kishikawakatsumi/swift-power-assert","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kishikawakatsumi%2Fswift-power-assert","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kishikawakatsumi%2Fswift-power-assert/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kishikawakatsumi%2Fswift-power-assert/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kishikawakatsumi%2Fswift-power-assert/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kishikawakatsumi","download_url":"https://codeload.github.com/kishikawakatsumi/swift-power-assert/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271530,"owners_count":20911587,"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","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":["power-assert","swift","testing"],"created_at":"2024-07-31T17:00:28.831Z","updated_at":"2025-10-25T00:41:10.549Z","avatar_url":"https://github.com/kishikawakatsumi.png","language":"Swift","funding_links":["https://github.com/sponsors/kishikawakatsumi"],"categories":["Macros","Swift"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg width=\"640px\" src=\"https://user-images.githubusercontent.com/40610/235353186-552ae826-c981-422d-8e75-e6b487a00bbd.png\" /\u003e\n\u003c/p\u003e\n\n# Swift Power Assert\n\n![test workflow](https://github.com/kishikawakatsumi/swift-power-assert/actions/workflows/test.yml/badge.svg)\n[![Build Status](https://app.bitrise.io/app/4018c2f1-9f94-4913-8a4c-deb1a8e1410a/status.svg?token=weITzhYlOhv2XfaNU41GkQ\u0026branch=main)](https://app.bitrise.io/app/4018c2f1-9f94-4913-8a4c-deb1a8e1410a)\n[![codecov](https://codecov.io/gh/kishikawakatsumi/swift-power-assert/branch/main/graph/badge.svg?token=rPTZiZLsmo)](https://codecov.io/gh/kishikawakatsumi/swift-power-assert)\n\nPower 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](https://github.com/spockframework/spock) (and later the entire [Groovy](https://github.com/apache/groovy) language independent of Spock), [ScalaTest](http://www.scalatest.org/) and [Expecty](https://github.com/pniederw/expecty).\n\nPower asserts provide descriptive assertion messages for your tests, like the following examples:\n\n```\n#assert(numbers[2] == 4)\n        │       ││ │  │\n        │       │3 │  4\n        │       2  false\n        [1, 2, 3, 4, 5]\n\n--- [Int] numbers[2]\n+++ [Int] 4\n–3\n+4\n\n[Int] numbers[2]\n=\u003e 3\n[Int] 4\n=\u003e 4\n\n#assert(numbers.contains(6))\n        │       │        │\n        │       false    6\n        [1, 2, 3, 4, 5]\n\n#assert(string1 == string2)\n        │       │  │\n        │       │  \"Hello, Swift!\"\n        │       false\n        \"Hello, world!\"\n\n--- [String] string1\n+++ [String] string2\nHello, {+S+}w[-orld-]{+ift+}!\n\n[String] string1\n=\u003e \"Hello, world!\"\n[String] string2\n=\u003e \"Hello, Swift!\"\n```\n\n## Online Playground\n\n[**Experience the library in action with our online playground!** :sparkles: Click here to access the interactive demo.](https://power-assert.swiftfiddle.com/)\n\n## Why Power Assert?\n\nWhen writing tests, we need to use different assertion functions. With Power Assert you only use the `#assert()` function. There are many\nAssertion APIs, no need to remember them. Just create an expression that returns a boolean value and Power Assert will automatically display rich error information.\n\n## Getting Started\n\nRequirements:\n\n- Swift 5.9 or later\n- Xcode 15.0 or later\n\n### For Xcode Project\n\nTo see PowerAssert in action, go to the Examples directory and run `xcodebuild test ...`.\n\n```\n$ cd Examples/XcodeProject/\n$ xcodebuild test -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=17.0' -parallel-testing-enabled NO\n```\n\nThe 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.\n\nOr set the following UserDefaults. This option allows console output even if parallel testing is enabled.\n\n```shell\ndefaults write com.apple.dt.xcodebuild ParallelTestRunnerStdoutMirroringEnabled -bool YES\n```\n\n### For Swift Package Manager\n\nTo see PowerAssert in action, go to the Examples directory and run `swift test`.\n\n```\n$ cd Examples/SwiftPackage/\n$ swift test\n```\n\nSee the following results?\n\n```\n...\nTest Suite 'All tests' started at 2023-04-05 07:17:58.800\nTest Suite 'swift-power-assert-examplePackageTests.xctest' started at 2023-04-05 07:17:58.801\nTest Suite 'PowerAssertTests' started at 2023-04-05 07:17:58.801\nTest Case '-[ExampleTests.PowerAssertTests testExample]' started.\n/swift-power-assert/Example/\"ExampleTests/ExampleTests.swift\":8: error: -[ExampleTests.PowerAssertTests testExample] : failed -\n#assert(a * b == 91)\n        │ │ │ │  │\n        │ │ 9 │  91\n        │ 90  false\n        10\n\n[Int] a\n=\u003e 10\n[Int] b\n=\u003e 9\n[Int] a * b\n=\u003e 90\n[Int] 91\n=\u003e 91\n/swift-power-assert/Example/\"ExampleTests/ExampleTests.swift\":11: error: -[ExampleTests.PowerAssertTests testExample] : failed -\n#assert(xs.contains(4))\n        │  │        │\n        │  false    4\n        [1, 2, 3]\n...\n```\n\nModify the code in `Example/Tests/ExampleTests.swift` to try different patterns you like.\n\n## Usage\n\nTo use Swift Power Assert in your library or application, first add swift-power-assert to your project.\n\nFor the Xcode project, add the swift-power-assert library as a package dependency.\n\n\u003cimg width=\"600\" src=\"https://github.com/kishikawakatsumi/swift-power-assert/assets/40610/75e9698b-1cf1-4bdb-9670-c3e7a2ebe1b4\"\u003e\n\nSelect PowerAssert as the Package Product and specify the **Test Bundle** as the target to add.\n\n\u003cimg width=\"400\" src=\"https://github.com/kishikawakatsumi/swift-power-assert/assets/40610/5075d2b9-0b32-4a16-9794-a38f7d4c9412\"\u003e\n\nFor the Swift package, configure Package.swift as follows:\n\n```swift\n// swift-tools-version:5.9\nimport PackageDescription\n\nlet package = Package(\n  name: \"MyLibrary\",\n  dependencies: [\n    ...,\n    .package(\n      url: \"https://github.com/kishikawakatsumi/swift-power-assert.git\",\n      from: \"0.12.0\"\n    ),\n  ],\n  targets: [\n    ...,\n    .testTarget(\n      name: \"MyLibraryTests\",\n      dependencies: [\n        ...,\n        .product(name: \"PowerAssert\", package: \"swift-power-assert\"),\n      ]\n    ),\n  ]\n)\n```\n\nNext, you can use Power Assert in your tests with the `#assert()` macro.\n\n```swift\n// MyLibraryTests.swift\nimport XCTest\nimport PowerAssert\n@testable import MyLibrary\n\nfinal class MyLibraryTests: XCTestCase {\n  func testExample() {\n    let a = 7\n    let b = 4\n    let c = 12\n\n    #assert(max(a, b) == c)\n  }\n}\n```\n\n### Concurrency (async/await) support\n\nSwift 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`:\n\n```swift\nfunc testConcurrency() async {\n  let ok = \"OK\"\n  #assert(await upload(content: \"example\") == ok)\n}\n```\n\n## For use on CI\n\nFor unattended use (e.g. on CI), you can disable the package validation dialog by\n\n- individually passing `-skipMacroValidation` to `xcodebuild` or\n- globally setting `defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES`\n  for that user.\n\n## Frequently Asked Questions\n\n**Q: Assert failure messages are not displayed.**\n\nIf 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\n\n```\n-parallel-testing-enabled NO\n```\n\nAlternatively, set the following UserDefaults. This option enables detailed messages to be output to the console even parallel testing enabled.\n\n```\ndefaults write com.apple.dt.xcodebuild ParallelTestRunnerStdoutMirroringEnabled -bool YES\n```\n\n**Q: I want to display the result even if the test is successful (i.e. the expression in the `#assert()` function evaluates to `true`).**\n\nA: 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.\n\nFor example:\n\n```swift\n#assert(x == y, verbose: true)\n```\n\n**Q: I want to know how the compiler actually expanded the macro.**\n\nA: You can use the `-dump-macro-expansions` option to dump the macro expansion.\n\nFor example:\n\n```\n$ cd Examples/SwiftPackage/\n$ swift test -Xswiftc -Xfrontend -Xswiftc -dump-macro-expansions\n```\n\nIf you run the above with the `-dump-macro-expansions` option, you will get the following output.\n\n```\n...\n@__swiftmacro_12ExampleTests011PowerAssertB0C04testA0yyF6assertfMf_.swift as ()\n------------------------------\nPowerAssert.Assertion(\"#assert(a * b == 91)\", message: \"\", file: #\"\"ExampleTests/ExampleTests.swift\"\"#, line: 8, verbose: false, binaryExpressions: [0: \"a\", 2: \"a * b\", 3: \"91\", 1: \"b\"]) {\n    $0.capture($0.capture($0.capture(a .self, column: 8, id: 0) * $0.capture(b .self, column: 12, id: 1), column: 10, id: 2) == $0.capture(91, column: 17, id: 3), column: 14, id: 4)\n}\n.render()\n------------------------------\n...\n```\n\n## Supporters \u0026 Sponsors\n\nOpen 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.\n\nTo support this project, you can become a sponsor through [GitHub Sponsors](https://github.com/sponsors/kishikawakatsumi). Your contribution will be greatly appreciated and will help keep the project alive and thriving. Thanks for your consideration! :heart:\n\n## Author\n\n[Kishikawa Katsumi](https://github.com/kishikawakatsumi)\n\n## License\n\nThe project is released under the [MIT License](https://github.com/kishikawakatsumi/swift-power-assert/blob/main/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkishikawakatsumi%2Fswift-power-assert","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkishikawakatsumi%2Fswift-power-assert","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkishikawakatsumi%2Fswift-power-assert/lists"}