All Projects β†’ kishikawakatsumi β†’ Swiftpowerassert

kishikawakatsumi / Swiftpowerassert

Licence: apache-2.0
Power Assert in Swift. Provides descriptive assertion messages.

Programming Languages

swift
15916 projects

Labels

Projects that are alternatives of or similar to Swiftpowerassert

underscore.haz
πŸ” _.haz() is like _.has() but this underscore and/or lodash mixin lets you do deep object key existence checking with a dot denoted string, for example 'a.b.c'
Stars: ✭ 13 (-93.19%)
Mutual labels:  assert
Node Deep Equal
node's assert.deepEqual algorithm
Stars: ✭ 577 (+202.09%)
Mutual labels:  assert
Gopwt
PowerAssert library for golang
Stars: ✭ 137 (-28.27%)
Mutual labels:  assert
Commonjs Assert
Node.js's require('assert') for all engines
Stars: ✭ 255 (+33.51%)
Mutual labels:  assert
Ava
Node.js test runner that lets you develop with confidence πŸš€
Stars: ✭ 19,458 (+10087.43%)
Mutual labels:  assert
Regex Assert Symfony
Common Regex to use with Assert in Symfony's entity
Stars: ✭ 5 (-97.38%)
Mutual labels:  assert
php-assert
Fast flexible php assert
Stars: ✭ 18 (-90.58%)
Mutual labels:  assert
Ppk assert
PPK_ASSERT is a cross platform drop-in & self-contained C++ assertion library
Stars: ✭ 164 (-14.14%)
Mutual labels:  assert
Validator.js
β‰οΈθ½»ι‡ηΊ§ηš„ JavaScript 葨单ιͺŒθ―οΌŒε­—符串ιͺŒθ―γ€‚ζ²‘ζœ‰δΎθ΅–οΌŒζ”―ζŒ UMD ,~3kb。
Stars: ✭ 486 (+154.45%)
Mutual labels:  assert
Expect More
Curried Type Testing library, and Test Matchers for Jest
Stars: ✭ 124 (-35.08%)
Mutual labels:  assert
Strikt
An assertion library for Kotlin
Stars: ✭ 310 (+62.3%)
Mutual labels:  assert
Static Assertions Rs
Ensure correct assumptions about constants, types, and more in Rust
Stars: ✭ 363 (+90.05%)
Mutual labels:  assert
Testify
A unit testing framework written in bash for bash scripts
Stars: ✭ 45 (-76.44%)
Mutual labels:  assert
Naza
πŸ€ Go basic library. || Goθ―­θ¨€εŸΊη‘€εΊ“
Stars: ✭ 253 (+32.46%)
Mutual labels:  assert
Earl
β˜• Ergonomic, modern and type-safe assertion library for TypeScript
Stars: ✭ 153 (-19.9%)
Mutual labels:  assert
openapi-assert
Asserting data against OpenAPI docs.
Stars: ✭ 17 (-91.1%)
Mutual labels:  assert
Baloo
Expressive end-to-end HTTP API testing made easy in Go
Stars: ✭ 702 (+267.54%)
Mutual labels:  assert
Debug assert
Simple, flexible and modular assertion macro.
Stars: ✭ 181 (-5.24%)
Mutual labels:  assert
Resumable Assert
Assert replacement to continue execution in debugger
Stars: ✭ 157 (-17.8%)
Mutual labels:  assert
Assert
A collection of convenient assertions for Swift testing
Stars: ✭ 69 (-63.87%)
Mutual labels:  assert

Power Assertions for Swift

Build Status codecov

Power assertions (a.k.a. diagrammed assertions) augment your assertion failures with information about values produced during the evaluation of a condition, and presents them in an easily digestible form. Power assertions are a popular feature of Spock (and later the whole Groovy language independently of Spock), ScalaTest, and Expecty.

Power assertions provide descriptive assertion messages for your tests, like this.

XCTAssert(max(a, b) == c)
          |   |  |  |  |
          7   4  7  |  12
                    false

XCTAssert(xs.contains(4))
          |  |        |
          |  false    4
          [1, 2, 3]

XCTAssert("hello".hasPrefix("h") && "goodbye".hasSuffix("y"))
          |       |         |    |  |         |         |
          "hello" true      "h"  |  "goodbye" false     "y"
                                 false

Online Playground

Live demo for SwiftPowerAssert

https://swift-power-assert.kishikawakatsumi.com/

screen shot 2018-01-23 at 0 13 28

Installation

$ git clone https://github.com/kishikawakatsumi/SwiftPowerAssert
$ cd SwiftPowerAssert
$ swift build -c release

Copy the file (.build/release/swift-power-assert) to your binary location.

Getting Started

For XCTest

Replace xcodebuild test... command with swift-power-assert xctest -Xxcodebuild test ...

$ /path/to/swift-power-assert xctest -Xxcodebuild test -scheme Atlas-Package

For swift test

Replace swift test... command with swift-power-assert test -Xswift test ...

$ /path/to/swift-power-assert test -Xswift test

Note: SwiftPowerAssert injects instrument code into the family of XCTAssert() methods during tests. SwiftPowerAssert back up the source files before executing tests and restore automatically when the tests finished. However, the original files may not be restored due to an unexpected crash or something wrong. Please use it for the project under Git.

Run Sample Project

You can run the sample project with the following command:

$ swift build -c release
$ (cd Fixtures/Atlas && ../../.build/release/swift-power-assert test -Xswift test)

Usage

USAGE: swift-power-assert [options] subcommand [options]

OPTIONS:
  --verbose   Show more debugging information
  --help      Display available options

SUBCOMMANDS:
  test        Run swift test with power assertion
  xctest      Run XCTest with power assertion.

You can pass any xcodebuild or swift options after -Xxcodebuild or -Xswift.

$ /path/to/swift-power-assert xctest -Xxcodebuild test -project Atlas.xcodeproj \
  -scheme Atlas-Package -sdk iphonesimulator \
  -destination "name=iPhone X,OS=11.2"
$ /path/to/swift-power-assert test -Xswift test -c release -Xswiftc -enable-testing

Nothing happens? If the test succeeds, nothing is output. If you always want to see rich ASCII art, enable the --verbose option. always output a diagram regardless of the success or failure of assertions.

$ /path/to/swift-power-assert --verbose xctest -Xxcodebuild test -project Atlas.xcodeproj -scheme Atlas-Package
$ /path/to/swift-power-assert --verbose test -Xswift test

Examples

let a = 10
let b = 9
XCTAssert(a * b == 91)

// Output:
// XCTAssert(a * b == 91)
//           | | | |  |
//           | | 9 |  91
//           | 90  false
//           10
let xs = [1, 2, 3]
XCTAssert(xs.contains(4))

// Output:
// XCTAssert(xs.contains(4))
//           |  |        |
//           |  false    4
//           [1, 2, 3]
XCTAssert("hello".hasPrefix("h") && "goodbye".hasSuffix("y"))

// Output:
// XCTAssert("hello".hasPrefix("h") && "goodbye".hasSuffix("y"))
//           |       |         |    |  |         |         |
//           "hello" true      "h"  |  "goodbye" false     "y"
//                                  false
let d = 4
let e = 7
let f = 12

XCTAssert(max(d, e) == f)
XCTAssert(d + e > f)

// Output:
// XCTAssert(max(d, e) == f)
//           |   |  |  |  |
//           7   4  7  |  12
//                     false
// XCTAssert(d + e > f)
//           | | | | |
//           4 | 7 | 12
//             11  false
struct Person {
  let name: String
  let age: Int

  var isTeenager: Bool {
    return age <= 12 && age >= 20
  }
}

let john = Person(name: "John", age: 42)
let mike = Person(name: "Mike", age: 13)

XCTAssert(john.isTeenager)
XCTAssert(mike.isTeenager && john.age < mike.age)

// Output:
// XCTAssert(john.isTeenager)
//           |    |
//           |    false
//           Person(name: "John", age: 42)
// XCTAssert(mike.isTeenager && john.age < mike.age)
//           |    |          |  |    |   | |    |
//           |    false      |  |    42  | |    13
//           |               |  |        | Person(name: "Mike", age: 13)
//           |               |  |        false
//           |               |  Person(name: "John", age: 42)
//           |               false
//           Person(name: "Mike", age: 13)

Author

Kishikawa Katsumi, [email protected]

License

SwiftPowerAssert is available under the Apache 2.0 license. See the LICENSE file for more info.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].