All Projects → erdos → Erdos.assert

erdos / Erdos.assert

Licence: epl-1.0
power assert macro for clojure

Programming Languages

clojure
4091 projects

Projects that are alternatives of or similar to Erdos.assert

Hamkrest
Hamcrest for Kotlin
Stars: ✭ 317 (+340.28%)
Mutual labels:  assertions
Bash unit
bash unit testing enterprise edition framework for professionals
Stars: ✭ 419 (+481.94%)
Mutual labels:  assertions
Should Enzyme
Useful functions for testing React Components with Enzyme.
Stars: ✭ 41 (-43.06%)
Mutual labels:  assertions
Unexpected
Unexpected - the extensible BDD assertion toolkit
Stars: ✭ 349 (+384.72%)
Mutual labels:  assertions
Kotlin Power Assert
Kotlin compiler plugin to enable diagrammed assertions in the Kotlin programming language
Stars: ✭ 370 (+413.89%)
Mutual labels:  assertions
Karate
Test Automation Made Simple
Stars: ✭ 5,497 (+7534.72%)
Mutual labels:  assertions
Tester
Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏
Stars: ✭ 281 (+290.28%)
Mutual labels:  assertions
Lazy Ass
Lazy node assertions without performance penalty
Stars: ✭ 63 (-12.5%)
Mutual labels:  assertions
Enzyme
JavaScript Testing utilities for React
Stars: ✭ 19,781 (+27373.61%)
Mutual labels:  assertions
Clj Fakes
An isolation framework for Clojure/ClojureScript.
Stars: ✭ 26 (-63.89%)
Mutual labels:  assertions
Assertr
Assertive programming for R analysis pipelines
Stars: ✭ 355 (+393.06%)
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 (+402.78%)
Mutual labels:  assertions
Pandera
A light-weight, flexible, and expressive pandas data validation library
Stars: ✭ 506 (+602.78%)
Mutual labels:  assertions
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (+347.22%)
Mutual labels:  assertions
Is
Type check values
Stars: ✭ 1,011 (+1304.17%)
Mutual labels:  assertions
Strikt
An assertion library for Kotlin
Stars: ✭ 310 (+330.56%)
Mutual labels:  assertions
Zerocode
A community-developed, free, open source, microservices API automation and load testing framework built using JUnit core runners for Http REST, SOAP, Security, Database, Kafka and much more. Zerocode Open Source enables you to create, change, orchestrate and maintain your automated test cases declaratively with absolute ease.
Stars: ✭ 482 (+569.44%)
Mutual labels:  assertions
Assert
A collection of convenient assertions for Swift testing
Stars: ✭ 69 (-4.17%)
Mutual labels:  assertions
Aws Testing Library
Chai (https://chaijs.com) and Jest (https://jestjs.io/) assertions for testing services built with aws
Stars: ✭ 52 (-27.78%)
Mutual labels:  assertions
Silk
Markdown based document-driven RESTful API testing.
Stars: ✭ 922 (+1180.56%)
Mutual labels:  assertions

Power Assertion macro for Clojure

The Power Assertions feature in the Groovy language is a strong tool, it makes writing tests and finding bugs easier. This is an implementation for the Clojure programming language with support for macros and lazy sequences.

It prints subexpressions on assert failure.

And each evaluations of subexpressions are shown.

Clojars Project EPL 1.0 contributions welcome HitCount Clojure CI

Usage

This library provides five small macros for easier debugging.

  • The examine macro can be used to trace parts of an evaluated expression. Debug information is printed to the standard output and the value of the expression is returned.
  • The assert macro is similar to clojure.core/assert. It wraps the examined information in the thrown AssertionError instance.
  • The verify macro is just like assert, but it throws an ExceptionInfo instead.
  • The is and are macros are drop-in replacements for clojure.test/is and clojure.test/are used in unit tests.

First, add the dependency to your project.clj.

[io.github.erdos/erdos.assert "0.2.3"]

Second, require the namespace:

(require '[erdos.assert :as ea])

In the REPL, examining simple expressions will print to *out*.

erdos.assert=> (examine (* (+ 19 17) (- 19 17)))

(* (+ 19 17) (- 19 17))
¦  ¦         ¦
72 36        2

You can also write assertions that will wrap examined data as a string in the AssertionError instance.

erdos.assert=> (assert (= 1 (* 3 (/ 1 3)) "") ; does not print anything

erdos.assert=> (assert (= (* 1.0 1) (* 3 (/ 1 3))) "")

; AssertionError
; (= (* 1.0 1) (* 3 (/ 1 3)))
; ¦  ¦         ¦    ¦
; ¦  1.0       1N   1/3
; false

Shown output is arranged to make place for more complex output.

erdos.assert=> (examine (+ (* 12 (- 32 12) 12.2) (- 3 (/ 1 2 3 4) 2.2) (* (- 1 2) 3)))

(+ (* 12 (- 32 12) 12.2) (- 3 (/ 1 2 3 4) 2.2) (* (- 1 2) 3))
¦  ¦     ¦               ¦    ¦                ¦  ¦
¦  ¦     20              ¦    1/24             -3 -1
¦  2928.0                0.7583333333333329
2925.758333333333

Some expressions are evaluated repeatedly, hence all values are shown.

erdos.assert=> (examine (dotimes [i 5] (print (* i i))))

(dotimes [i 5] (print (* i i)))
               ¦      ¦
               ¦      16, 9, 4, 1, 0
               nil, nil, nil, nil, nil

Only the already realized part is printed for lazy sequences.

erdos.assert=> (examine (reduce + (map * (range) (range 0 10 2))))

(reduce + (map * (range) (range 0 10 2)))
¦         ¦      ¦       ¦
60        ()    (0 )   (0 2 4 6 8) 

In such cases you might want to run doall on intermediate lazy sequences.

erdos.assert=> (examine (reduce + (doall (map * (range) (range 0 10 2)))))

(reduce + (doall (map * (range) (range 0 10 2))))
¦         ¦      ¦      ¦       ¦
60        ¦      ()    (0 )   (0 2 4 6 8) 
          (0 2 8 18 32) 

Add the ^:show metadata to function arguments to show the values on every function invocation:

erdos.assert=> (examine (mapv (fn [^:show a] (mod a 3)) (range 10)))

(mapv (fn [a] (mod a 3)) (range 10))
¦          ¦  ¦          ¦
¦          ¦  ¦          (0 1 2 3 4 5 6 7 8 9)
¦          ¦  0, 1, 2, 0, 1, 2, 0, 1, 2, 0
¦          0, 1, 2, 3, 4, 5, 6, 7, 8, 9
[0 1 2 0 1 2 0 1 2 0]

License

Copyright © 2017-2021 Janos Erdos

Distributed under the Eclipse Public License version 1.0.

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