All Projects → bnorm → Kotlin Power Assert

bnorm / Kotlin Power Assert

Licence: apache-2.0
Kotlin compiler plugin to enable diagrammed assertions in the Kotlin programming language

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Kotlin Power Assert

cxx-tap
Test Anything Protocol (TAP) Producer for C++
Stars: ✭ 22 (-94.05%)
Mutual labels:  assertions
crotest
A tiny and simple test framework for crystal
Stars: ✭ 24 (-93.51%)
Mutual labels:  assertions
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (-12.97%)
Mutual labels:  assertions
tester
Lightweight test utilities to use with Go's testing package
Stars: ✭ 43 (-88.38%)
Mutual labels:  assertions
belay
Robust error-handling for Kotlin and Android
Stars: ✭ 35 (-90.54%)
Mutual labels:  assertions
Kotest
Powerful, elegant and flexible test framework for Kotlin with additional assertions, property testing and data driven testing
Stars: ✭ 3,234 (+774.05%)
Mutual labels:  assertions
phpsemver
Check if your changes are a major change, minor change or just a patch.
Stars: ✭ 28 (-92.43%)
Mutual labels:  assertions
Atrium
A multiplatform assertion library for Kotlin
Stars: ✭ 359 (-2.97%)
Mutual labels:  assertions
util
The util project, packed with common goodies.
Stars: ✭ 61 (-83.51%)
Mutual labels:  assertions
Hamkrest
Hamcrest for Kotlin
Stars: ✭ 317 (-14.32%)
Mutual labels:  assertions
beJS
Simple, light-weight assertions framework for javascript
Stars: ✭ 12 (-96.76%)
Mutual labels:  assertions
Light.GuardClauses
A lightweight .NET library for expressive Guard Clauses.
Stars: ✭ 68 (-81.62%)
Mutual labels:  assertions
Tester
Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏
Stars: ✭ 281 (-24.05%)
Mutual labels:  assertions
karma-expect
Expect.js adapter for Karma test runner
Stars: ✭ 12 (-96.76%)
Mutual labels:  assertions
Unexpected
Unexpected - the extensible BDD assertion toolkit
Stars: ✭ 349 (-5.68%)
Mutual labels:  assertions
codeceptjs-bdd
Javascript BDD UI Automation Framework. Exclusive LWC Shadow DOM Support. Playwright, Webdriver.io, Appium, Saucelabs.
Stars: ✭ 35 (-90.54%)
Mutual labels:  assertions
iutest
c++ testing framework
Stars: ✭ 58 (-84.32%)
Mutual labels:  assertions
Luaunit
LuaUnit is a popular unit-testing framework for Lua, with an interface typical of xUnit libraries (Python unittest, Junit, NUnit, ...). It supports several output formats (Text, TAP, JUnit, ...) to be used directly or work with Continuous Integration platforms (Jenkins, Maven, ...).
Stars: ✭ 362 (-2.16%)
Mutual labels:  assertions
Assertr
Assertive programming for R analysis pipelines
Stars: ✭ 355 (-4.05%)
Mutual labels:  assertions
Strikt
An assertion library for Kotlin
Stars: ✭ 310 (-16.22%)
Mutual labels:  assertions

kotlin-power-assert

Maven Central

Kotlin Compiler Plugin which high-jacks Kotlin assert function calls and transforms them similar to Groovy's Power Assert feature. This plugin uses the IR backend for the Kotlin compiler and supports all platforms: JVM, JS, and Native!

Example

Given following code:

val hello = "Hello"
assert(hello.length == "World".substring(1, 4).length)

Normally the assertion message would look like:

java.lang.AssertionError: Assertion failed
	at <stacktrace>

A custom assertion message can be provided:

val hello = "Hello"
assert(hello.length == "World".substring(1, 4).length) { "Incorrect length" }

But this just replaces the message:

java.lang.AssertionError: Incorrect length
	at <stacktrace>

With kotlin-power-assert included, the error message for the previous example will be transformed:

java.lang.AssertionError: Incorrect length
assert(hello.length == "World".substring(1, 4).length)
       |     |      |          |               |
       |     |      |          |               3
       |     |      |          orl
       |     |      false
       |     5
       Hello
	at <stacktrace>

Complex, multi-line, boolean expression are also supported:

Assertion failed
assert(
  (text != null && text.toLowerCase() == text) ||
   |    |
   |    false
   null
      text == "Hello"
      |    |
      |    false
      null
)

Gradle Plugin

Builds of the Gradle plugin are available through the Gradle Plugin Portal.

plugins {
  kotlin("multiplatform") version "1.4.30"
  id("com.bnorm.power.kotlin-power-assert") version "0.7.0"
}

The plugin by default will transform assert function call but can also transform other functions like require, check, and/or assertTrue. The function needs to validate the Boolean expression evaluates to true and has a form which also takes a String or String producing lambda.

configure<com.bnorm.power.PowerAssertGradleExtension> {
  functions = listOf("kotlin.assert", "kotlin.test.assertTrue")
}

Kotlin IR

Using this compiler plugin only works if the code is compiled using Kotlin 1.4.30 and IR is enabled. This plugin supports all IR based compiler backends: JVM, JS, and Native!

Kotlin/JVM
tasks.withType<KotlinCompile>().configureEach {
  kotlinOptions {
    useIR = true
  }
}
Kotlin/JS
target {
  js(IR) {
  }
}
Kotlin/Native

IR already enabled by default!

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].