All Projects → aw → picolisp-unit

aw / picolisp-unit

Licence: MIT license
Unit Testing framework for PicoLisp

Programming Languages

PicoLisp
9 projects
common lisp
692 projects
Makefile
30231 projects

Projects that are alternatives of or similar to picolisp-unit

toUUID
Simple integer to UUID generator for unit and integration tests written in Java or Kotlin
Stars: ✭ 12 (-45.45%)
Mutual labels:  unit-testing, testing-library
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 (+1545.45%)
Mutual labels:  unit-testing, assertions
concise
✅ Concise is test framework for using plain English and minimal code, built on PHPUnit.
Stars: ✭ 47 (+113.64%)
Mutual labels:  unit-testing, assertions
vim-UT
Unit Testing plugin for Vim
Stars: ✭ 18 (-18.18%)
Mutual labels:  unit-testing, 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 (+11031.82%)
Mutual labels:  unit-testing, assertions
Tester
Tester: enjoyable unit testing in PHP with code coverage reporter. 🍏🍏🍎🍏
Stars: ✭ 281 (+1177.27%)
Mutual labels:  unit-testing, assertions
Sazerac
Data-driven unit testing for Jasmine, Mocha, and Jest
Stars: ✭ 322 (+1363.64%)
Mutual labels:  unit-testing, assertions
Bash unit
bash unit testing enterprise edition framework for professionals
Stars: ✭ 419 (+1804.55%)
Mutual labels:  unit-testing, assertions
Redux Actions Assertions
Simplify testing of redux action and async action creators
Stars: ✭ 177 (+704.55%)
Mutual labels:  unit-testing, assertions
Zunit
A powerful testing framework for ZSH projects
Stars: ✭ 140 (+536.36%)
Mutual labels:  unit-testing, assertions
tau
A Micro (1k lines of code) Unit Test Framework for C/C++
Stars: ✭ 121 (+450%)
Mutual labels:  unit-testing, assertions
Truth
Fluent assertions for Java and Android
Stars: ✭ 2,359 (+10622.73%)
Mutual labels:  unit-testing, testing-library
toster
DSL framework for testing Android apps
Stars: ✭ 31 (+40.91%)
Mutual labels:  unit-testing, testing-library
FactoryOrchestrator
A cross-platform system service which provides a simple way to run and manage factory line validation, developer inner-loop, diagnostics, and fault analysis workflows.
Stars: ✭ 36 (+63.64%)
Mutual labels:  testing-library
react-router-testing-utils
A collection of utilities to test React Router with React Testing Library (Work in progress 🚧)
Stars: ✭ 34 (+54.55%)
Mutual labels:  testing-library
zerocode-hello-world
Zerocode YAML and JSON based declarative steps hello world rest api testing example - soap, database
Stars: ✭ 18 (-18.18%)
Mutual labels:  assertions
FRUITPy
Python interface for the FRUIT Fortran unit testing framework
Stars: ✭ 39 (+77.27%)
Mutual labels:  unit-testing
kiwi
Fluent assertions for Kotlin
Stars: ✭ 17 (-22.73%)
Mutual labels:  assertions
babel-plugin-rewire-exports
Babel plugin for stubbing [ES6, ES2015] module exports
Stars: ✭ 62 (+181.82%)
Mutual labels:  unit-testing
eslint-config-galex
hopefully the last eslint config you'll ever need - customizable & modern best practices for JS, TS, Node, React, Remix, Next, Jest, testing-library & storybook
Stars: ✭ 166 (+654.55%)
Mutual labels:  testing-library

Unit Testing framework for PicoLisp

GitHub release Build status

This library can be used for Unit Testing your PicoLisp code.

picolisp-unit

Please read EXPLAIN.md to learn more about PicoLisp and this Unit Testing framework.

  1. Requirements
  2. Getting Started
  3. Usage
  4. Examples
  5. Testing
  6. Reporters
  7. Alternatives
  8. Contributing
  9. Changelog
  10. License

Requirements

  • PicoLisp 32-bit or 64-bit v3.1.9+, or pil21
  • Tested up to PicoLisp v20.6.29, see test runs

Getting Started

This is a pure PicoLisp library with no external dependencies. You can either copy unit.l into your project(s), or add it as a git submodule to stay up-to-date (recommended).

Add submodule to your project

  1. git submodule add https://github.com/aw/picolisp-unit vendor/picolisp-unit
  2. Include unit.l in your test file
  3. See the examples below

Usage

Here are some guidelines on how to use unit.l, but you're free to poke around the code and use it as you wish.

There exists a few public functions: (execute), (report), and a bunch of (assert-X) where X is a type of assertion.

  • (execute arg1 ..) Executes arg1 to argN tests
    • arg1 Quoted List: a list of assertions, example '(assert-nil NIL "I AM NIL")
  • (report) Prints a report of failed tests, and exits with 1 if there is a failure
  • (assert-X) Various assertions for testing

Assertions table

Only a few assertions exist for the moment; more can/will be added.

Assertion Arguments Example
(assert-equal) Expected Result Message (assert-equal 0 0 "It must be zero")
(assert-nil) Result Message (assert-nil NIL "It must be NIL")
(assert-t) Result Message (assert-t T "I pity the fool!")
(assert-includes) String List Message (assert-includes "abc" '("def") "It includes abc")
(assert-kind-of) Type Value Message (assert-kind-of 'Number 42 "The answer..")
(assert-throws) Type Error 'Result Message (assert-throws 'Err "fail" '(throw 'Err "fail") "Throws a fail")

(assert-kind-of) types

There are 5 types currently defined:

  • 'Flag Uses flg? to test if the value is T or NIL.
  • 'String Uses str? to test if the value is a string.
  • 'Number Uses num? to test if a value is a number.
  • 'List Uses lst? to test if a value is a list.
  • 'Atom Uses atom to test if a value is an atom.

Warning: NIL is also list, but will be asserted as a 'Flag when using (assert-kind-of). Use (assert-nil) if you specifically want to know if the value is NIL.

Notes

  • Use (execute) at the start of your tests (see examples)
  • Unit Tests are run in RANDOM order.
  • If your tests are order dependent, then you can: (setq *My_tests_are_order_dependent T)
  • Colours and bold text are only displayed if your terminal supports it, and if your system has the tput command.
  • The (assert-includes) function uses sub? to find a substring in a string or list.
  • The (assert-throws) function requires the (throw) to be quoted.
  • Assertions return T if the test passed, and NIL if the test failed
  • Results of all tests are accumulated in the *Results global variable

Test results

The *Results global variable is a list of lists, which will have one of two formats:

((NIL 1 "should be NIL" NIL T) (T 2 "should be NIL"))
  1. NIL or T in the (car) if the test failed or passed, respectively
  2. Number indicating the counter for the test
  3. Message of the test
  4. Expected result (only when the test failed)
  5. Actual result (only when the test failed)

Examples

It is recommended to create a "test runner" similar to what's found in test.l.

Tests should be placed in a test/ directory, and the test files should be prefixed with test_.

A simple unit test

pil +

(load "unit.l")

(setq *My_tests_are_order_dependent NIL)

[execute
  '(assert-equal 0 0 "(assert-equal) should assert equal values")
  '(assert-nil   NIL "(assert-nil) should assert NIL")
  '(assert-t     T   "(assert-t) should assert T")
  '(assert-includes "abc" '("xyzabcdef")  "(assert-includes) should assert includes")
  '(assert-kind-of  'Flag NIL  "(assert-kind-of) should assert a Flag (NIL)")
  '(assert-kind-of  'Flag T    "(assert-kind-of) should assert a Flag (T)")
  '(assert-kind-of  'String "picolisp"  "(assert-kind-of) should assert a String")
  '(assert-kind-of  'Number 42  "(assert-kind-of) should assert a Number")
  '(assert-kind-of  'List (1 2 3 4)  "(assert-kind-of) should assert a List")
  '(assert-kind-of  'Atom 'atom  "(assert-kind-of) should assert a Atom") ]

# output

  1) ✓  (assert-kind-of) should assert a List
  2) ✓  (assert-kind-of) should assert a Flag (T)
  3) ✓  (assert-includes) should assert includes
  4) ✓  (assert-t) should assert T
  5) ✓  (assert-kind-of) should assert a Number
  6) ✓  (assert-nil) should assert NIL
  7) ✓  (assert-equal) should assert equal values
  8) ✓  (assert-kind-of) should assert a Flag (NIL)
  9) ✓  (assert-kind-of) should assert a Atom
 10) ✓  (assert-kind-of) should assert a String

-> (T T T T T T T T T T)

When tests fail

pil +

(load "unit.l")

[execute
  '(assert-equal 0 1 "(assert-equal) should assert equal values")
  '(assert-nil   NIL "(assert-nil) should assert NIL")
  '(assert-t     NIL   "(assert-t) should assert T")
  '(assert-includes "abc" '("hello")  "(assert-includes) should assert includes")
  '(assert-kind-of  'Flag "abc"  "(assert-kind-of) should assert a Flag (NIL)") ]

(report)

# output

-> (T NIL NIL NIL NIL)

  1) ✓  (assert-nil) should assert NIL
  2) ✕  (assert-kind-of) should assert a Flag (NIL)
  3) ✕  (assert-includes) should assert includes
  4) ✕  (assert-t) should assert T
  5) ✕  (assert-equal) should assert equal values

-> ----
1 test passed, 4 tests failed

  Failed tests: 

  - 2)  (assert-kind-of) should assert a Flag (NIL)
        Expected: "abc should be of type Flag"
          Actual: String

  - 3)  (assert-includes) should assert includes
        Expected: "abc in hello"
          Actual: "abc"

  - 4)  (assert-t) should assert T
        Expected: T
          Actual: NIL

  - 5)  (assert-equal) should assert equal values
        Expected: 0
          Actual: 1

Testing

This testing library has its own set of tests (hehe). You can use those as examples as well. To run them type:

./test.l

or

make check

Reporters

If you don't call (report), the test results will not be printed to the screen.

This allows you to create your own custom reporter and use it to output the test results however you like.

There are two existing reporters, to use one set the TEST_REPORTER environment variable:

TEST_REPORTER=plain ./test.l

or

TEST_REPORTER=default ./test.l

Creating a custom reporter

Your custom reporter only needs to implement the (print-report) function. This gets called by the public (report) function.

Add a file to the reporters/ directory (ex: custom.l). The filename (without .l extension) will be the name of your reporter.

You can use any of the following helper functions/variables:

  • (colour)
  • (plural?)
  • (get-results)
  • *Results global variable

Note: Avoid using the internal functions as they might change without notice.

  • All test results can be obtained with the *Results global variable.
  • All failed results can be obtained with (get-results NIL).
  • All passed results can be obtained with (get-results T).

Please make a pull-request if you would like your custom reporter to be added to this library.

Alternatives

The alternative approaches to testing in PicoLisp involve the use of test and assert.

Contributing

If you find any bugs or issues, please create an issue.

If you want to improve this library, please make a pull-request.

Contributors

Changelog

License

MIT License

Copyright (c) 2015-2020 Alexander Williams, Unscramble [email protected]

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