All Projects → torokmark → assert.sh

torokmark / assert.sh

Licence: MIT license
❗ Assertion lib for shell script users

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to assert.sh

Expekt
BDD assertion library for Kotlin
Stars: ✭ 163 (+55.24%)
Mutual labels:  assertions
Pester
Pester is the ubiquitous test and mock framework for PowerShell.
Stars: ✭ 2,620 (+2395.24%)
Mutual labels:  assertions
tau
A Micro (1k lines of code) Unit Test Framework for C/C++
Stars: ✭ 121 (+15.24%)
Mutual labels:  assertions
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+68.57%)
Mutual labels:  assertions
Gotest.tools
A collection of packages to augment the go testing package and support common patterns.
Stars: ✭ 205 (+95.24%)
Mutual labels:  assertions
Jest Chain
Chain Jest matchers together to create one powerful assertion 🃏⛓
Stars: ✭ 235 (+123.81%)
Mutual labels:  assertions
Should.js
BDD style assertions for node.js -- test framework agnostic
Stars: ✭ 1,908 (+1717.14%)
Mutual labels:  assertions
jsonassert
A Go test assertion library for verifying that two representations of JSON are semantically equal
Stars: ✭ 102 (-2.86%)
Mutual labels:  assertions
Codejam
Set of handy reusable .NET components that can simplify your daily work and save your time when you copy and paste your favorite helper methods and classes from one project to another
Stars: ✭ 217 (+106.67%)
Mutual labels:  assertions
json matcher
Library for simplifying data verification in functional tests for your JSON-based APIs
Stars: ✭ 24 (-77.14%)
Mutual labels:  assertions
Fluentassertions
A very extensive set of extension methods that allow you to more naturally specify the expected outcome of a TDD or BDD-style unit tests. Targets .NET Framework 4.7, .NET Core 2.1 and 3.0, as well as .NET Standard 2.0 and 2.1. Supports the unit test frameworks MSTest2, NUnit3, XUnit2, MSpec, and NSpec3.
Stars: ✭ 2,449 (+2232.38%)
Mutual labels:  assertions
K9
Rust testing library
Stars: ✭ 194 (+84.76%)
Mutual labels:  assertions
Truss
Assertions API for Clojure/Script
Stars: ✭ 239 (+127.62%)
Mutual labels:  assertions
Checkmate
Fast and versatile argument checks
Stars: ✭ 174 (+65.71%)
Mutual labels:  assertions
chai
BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
Stars: ✭ 7,842 (+7368.57%)
Mutual labels:  assertions
Assertj Core
AssertJ is a library providing easy to use rich typed assertions
Stars: ✭ 2,085 (+1885.71%)
Mutual labels:  assertions
Check Types.js
MOVED TO GITLAB
Stars: ✭ 232 (+120.95%)
Mutual labels:  assertions
kiwi
Fluent assertions for Kotlin
Stars: ✭ 17 (-83.81%)
Mutual labels:  assertions
zerocode-hello-world
Zerocode YAML and JSON based declarative steps hello world rest api testing example - soap, database
Stars: ✭ 18 (-82.86%)
Mutual labels:  assertions
superdeno
Super-agent driven library for testing Deno HTTP servers.
Stars: ✭ 119 (+13.33%)
Mutual labels:  assertions

assert.sh

Build Status

Assert.sh is intended to give the assertion mechanism to shell scripts with well-known assert functions like assert_eq, assert_array_eq, or assert_empty. Inspired by Assert class of JUnit

Install & Usage

> # git clone https://github.com/torokmark/assert.sh.git; cd assert.sh
> # source assert.sh
> # assert_eq "hello" "world"
> # echo "$?"
# => 1

I. Clone the repository

git clone https://github.com/torokmark/assert.sh.git

Or copy the assert.sh where your project is located.

II. Edit the script where you would like to use asserts and paste the next line on the top:

source './assert.sh'

III. Now assert functions are available for use.

assert_eq "hello" "world"

0 return status is considered true and anything else is considered false.

List of assert functions

  • assert_eq takes two strings and checks whether they are the same based on the character strings.
  • assert_not_eq is the opposite of assert_eq.
  • assert_true takes a parameter and returns 0 confirming the parameter is true.
  • assert_false takes a parameter and decides whether it is false.
  • assert_array_eq takes two arrays and compare them by items.
  • assert_array_not_eq takes two arrays and return 0 if the items are not the same on the same index.
  • assert_empty takes a string and returns 0 if it is empty
  • assert_not_empty is the opposite of assert_empty.
  • assert_contain checks whether the first argument contains the second one.
  • assert_not_contain check whether the first argument does not contain the second one.
  • assert_gt checks whether the first param is greater than the second.
  • assert_ge checks whether the first param is greator than or equal to the second one.
  • assert_lt checks whether the first param is less than the second one.
  • assert_le checks whether the first param is less than or equal to the second one.

How to write tests

Example:

source "./assert.sh"

local expected actual
expected="Hello"
actual="World!"
assert_eq "$expected" "$actual" "not equivalent!"
# => x Hello == World :: not equivalent! 
source "./assert.sh"

local expected actual
expected="Hello"
actual="Hello"
assert_eq "$expected" "$actual"
if [ "$?" == 0 ]; then
  log_success "assert_eq returns 0 if two words are equal"
else
  log_failure "assert_eq should return 0"
fi

If the return status ($?) of assert_eq is equal to 0, which is considered true according to the convention. If the assert function returns 1, the expected and actual values are differred.

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