Skip to content
Error pattern for assertion libraries in Common Lisp.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
test
LICENSE
README.md
assertion-error.asd

README.md

assertion-error

Error pattern for assertion libraries in Common Lisp.

Getting Started in assertion-error

Installation

The assertion-error system has only one dependency, which is the dissect system, I do not know if it will depend forever on this library, but for now it is necessary, since Common Lisp does not have a standard to get the stack trace.

1 - Download the dissect system

By quicklisp:

http://quickdocs.org/dissect/

or directly from github:

git clone https://github.com/Shinmera/dissect.git

2 - Download assertion-error system

By quicklisp:

IN PROGRESS...

or directly from github:

git clone https://github.com/noloop/assertion-error.git

3 - Install assertion-error

By quicklisp:

IN PROGRESS...

or directly from asdf:

(asdf:load-system :assertion-error)

Note: Remember to configure asdf to find your directory where you downloaded the libraries (asdf call them "systems") above, if you do not know how to make a read at: https://common-lisp.net/project/asdf/asdf/Configuring-ASDF-to-find-your-systems.html or https://lisp-lang.org/learn/writing-libraries.

Create assertion with assertion-error

Use assertion-error when constructing your assertion library:

(defun is-t? (actual)
  (assertion (equal t actual) actual t 'equal))

(defun is-nil? (actual)
  (assertion (equal nil actual) actual nil 'equal))

(defun assertion (result actual expected operator)
  (unless result
    (error 'assertion-error
           :assertion-error-message (concatenate 'string (string actual) " " (string operator) " " (string expected))
           :assertion-error-result result
           :assertion-error-actual actual
           :assertion-error-expected expected
           :assertion-error-stack (get-stack-trace))))

Catch assertion-error

Use assertion-error to build your test runner, where it can capture the errors of your assertion library which one also uses assertion-error:

(handler-case (assert:is-t? nil)
   (assertion-error:assertion-error (c)
         (format t "~a" (assertion-error:assertion-error-actual c))))

API

All generic functions below returns some information from the assertion-error condition. They have a required argument that is the assertion-error condition. Check out the catch assertion-error example to understand how to use them.

condition assertion-error

function (get-stack-trace)

condition :reader (assertion-error-message c)

condition :reader (assertion-error-result c)

condition :reader (assertion-error-actual c)

condition :reader (assertion-error-expected c)

condition :reader (assertion-error-stack c)

You can’t perform that action at this time.