The cl-naive-tests Reference Manual

This is the cl-naive-tests Reference Manual, version 2023.12.10, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 05:11:40 2024 GMT+0.

Table of Contents


1 Systems

The main system appears first, followed by any subsystem dependency.


1.1 cl-naive-tests

A test framework that is not based on any of the mainstream popular testing frameworks. It has a very simple api, so the learning curve should be considerably less than for most other frameworks. It is also designed to work well with gitlab CI.

Author

Phil Marneweck <>

License

MIT

Version

2023.12.10

Dependency

cl-who (system).

Source

cl-naive-tests.asd.

Child Components

2 Files

Files are sorted by type and then listed depth-first from the systems components trees.


2.1 Lisp


2.1.1 cl-naive-tests/cl-naive-tests.asd

Source

cl-naive-tests.asd.

Parent Component

cl-naive-tests (system).

ASDF Systems

cl-naive-tests.


2.1.2 cl-naive-tests/src/package.lisp

Source

cl-naive-tests.asd.

Parent Component

cl-naive-tests (system).

Packages

cl-naive-tests.


2.1.3 cl-naive-tests/src/color.lisp

Dependency

src/package.lisp (file).

Source

cl-naive-tests.asd.

Parent Component

cl-naive-tests (system).

Public Interface

*use-color* (special variable).

Internals

2.1.4 cl-naive-tests/src/utility.lisp

Dependency

src/package.lisp (file).

Source

cl-naive-tests.asd.

Parent Component

cl-naive-tests (system).

Internals

2.1.5 cl-naive-tests/src/naive-tests.lisp

Dependencies
Source

cl-naive-tests.asd.

Parent Component

cl-naive-tests (system).

Public Interface
Internals

3 Packages

Packages are listed by definition order.


3.1 cl-naive-tests

Source

src/package.lisp.

Use List

common-lisp.

Public Interface
Internals

4 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


4.1 Public Interface


4.1.1 Special variables

Special Variable: *debug*

Set to true to break into the debugger on errors.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *junit-no-properties*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *suites-results*

The result of the last testsuites.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *test-suites*

Tests are stored in here when registered.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *use-color*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *verbose*

When true, the success testcases are also printed.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.


4.1.2 Macros

Macro: define-suite ((name) &body body)

Define a CREATE-SUITE method on the NAME (eql specializer), to define the test suite at run-time.
The name of the test suite is registered immediately in *TEST-SUITE-NAMES* for reference by RUN.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Macro: testcase (identifier &key disabled test-func test-data equal expected actual info)

The TEST macro evaluates the ACTUAL expression and compare its result with the EXPECTED expression.

The comparison is done either with the TEST-FUNC if provided, with the
EQUAL function. If the comparison returns true, the test is
successful, otherwise it’s a failure. Test runs the test func
returning a plist with information about the result and test.

A plist containing the test info and results is returned. It should
be used in the lambda that is registered with register-test.

IDENTIFIER must be a symbol naming the testcase.

DISABLED is a generalized-boolean expression, evaluated. If the result
is true, then the test is marked disabled, and not run.

The ACTUAL code, or the TEST-FUNC code can also disable the testcase
by signaling a DISABLE-TESTCASE condition, or skip the testcase with a
message by signaling a SKIP-TESTCASE condition. (Functions are
provided to easily signal those conditions).

TEST-FUNC is the function that is run to determine the result of the
test. If none is supplied, then the EQUAL function is used to compare
the EXPECTED and the ACTUAL values. The TEST-FUNC returns a
failure-type: T or :SUCCESS in case of success, NIL or :FAILURE in
case of failure, or some other keyword if the test wasn’t run
successfully, but this shouldn’t be counted as a failure. The
TEST-FUNC is given two arguments: a plist containing :TEST-DATA
:EXPECTED :ACTUAL :EXPRESSION :ERROR, and the INFO. (:ACTUAL is the
value of the :EXPRESSION that is tested; if an error is signaled, it’s
passed in :ERROR).

TEST-DATA is a convenient place to store data the test relies on, this
can be used during the test and later in reporting on test results.
You can put what ever you want to in it.

INFO is a string to be read by the human that is digging into the
tests results, describing the test.

EXAMPLE:

(test (division non-zero-dividend)
:equal ’=
:expected 3/2
:actual (/ 3 2)
:info "Integer division by non-zero, giving a ratio.")

(test (division by-zero)
:test-func (lambda (result info)
(let ((actual (getf result :actual)))
(cond ((eql (getf result :expected) :success)
((typep actual ’error)
(setf (aref (getf result :test-data) 0)
(list ’unexpected-error (type-of actual))) :failure)
(t
(setf (aref (getf result :test-data) 0)
(list ’unexpected-result actual)) :failure))))
:test-data (vector nil)
:expected ’division-by-zero
:actual (handler-case (/ 3 0)
(:no-error (result) result)
(division-by-zero () ’division-by-zero)
(error (err) err))
:info "Integer division by zero, giving a DIVISION-BY-ZERO error.")

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Macro: testsuite (identifier &body body)

Defines a TESTSUITE.
The IDENTIFIER is a symbol identifying the testsuite.
The BODY is a list of lisp forms or TESTCASE forms.
The results of the TESTCASE are collected as results of the TESTSUITE.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.


4.1.3 Ordinary functions

Function: calc-stats (suites &optional stats)

Calculates stats. Stats are simple counts of tests, passed and failed per level.
Stats are stored in a hashtable per identifier level, which makes it easy to get to in format-results if needed.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: disable-testcase ()
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: find-testcase (test-identifier suites &key test)

Finds a result in the suites.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: report (&optional suites-results)

Reports on the pass or failure of the results set over all. This does not do any pretty printing etc because it needs to be machine readable. If you want pretty reporting look at format-results or do your own.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: run (&key suites name keep-stats-p debug verbose)

Runs all the testcases in all the SUITES passed in or all testsuites registered.
Statistics can be calculated during a test run, but the default is to use statistics after a test run to calculate stats.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: save-results (suites-results &key file format)

Writes results to file. Formats the results using FORMAT-RESULT.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: skip-testcase (&optional message)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: statistics (suites-results)

Can be used to calculate statistics post tests if *keep-stats-p* was nil.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: testsuite-names (&optional *test-suites*)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: testsuite-selection (names &optional *test-suites*)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: write-results (suites-results &key stream format)

Writes results to STREAM. Formats the results using FORMAT-RESULT.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.


4.1.4 Generic functions

Generic Function: create-suite (test-name)

Specialize to define test suite. This is run before a test is run. Was introduced so that test can be created in synq with setup-test code and any infrastructure created during setup-test.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Methods
Method: create-suite (test-name)

Default method, does nothing.

Generic Function: format-results (format results)

Formats the results according to format.
The default method just outputs the results using lisp format string.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Methods
Method: format-results ((format (eql :junit)) suites)

Formats then results as Junit XML, junits only allows 3 levels nl. suites, suite and testcase. If your identifiers are not 1 or 3 levels this wont work for you.

Method: format-results ((format (eql :text)) suites-results)
Method: format-results (format suites-results)
Generic Function: setup-suite (test-name)

Used to setup the multiverse, universe and other infrastructure for a test.

Implement the method to add any custom initialization.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Methods
Method: setup-suite (test-name)

Default does nothing.

Generic Reader: skip-testcase-reason (condition)
Package

cl-naive-tests.

Methods
Reader Method: skip-testcase-reason ((condition skip-testcase))
Source

src/naive-tests.lisp.

Target Slot

reason.

Generic Function: tear-down-suite (test-name)

This is run after an individual test, specialize to clean up any test infrastructure created by the setup-test or the tests them selves.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Methods
Method: tear-down-suite (test-name)

Default does nothing.


4.1.5 Conditions

Condition: disable-testcase
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Direct superclasses

condition.

Condition: skip-testcase
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Direct superclasses

condition.

Direct methods

skip-testcase-reason.

Direct slots
Slot: reason
Initargs

:reason

Readers

skip-testcase-reason.

Writers

This slot is read-only.


4.2 Internals


4.2.1 Special variables

Special Variable: *black*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *black-back*
Package

cl-naive-tests.

Source

src/color.lisp.

Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *blue*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *blue-back*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *bold*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *cyan*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *cyan-back*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *disabled-count*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *error-count*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *failure-count*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *green*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *green-back*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *invert*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *magenta*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *magenta-back*
Package

cl-naive-tests.

Source

src/color.lisp.

Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *no-bold*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *no-invert*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *no-underline*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *normal*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *red*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *red-back*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *skipped-count*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *suite-id*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *suite-name*

Current testsuite name.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *suite-results*

The results of the last testsuite ran.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *test-count*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *test-package*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *test-suite-names*
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *testcase-results*

The current testcase results (plist).

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *testsuite-name*

The current testsuite name.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Special Variable: *underline*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *white*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *white-back*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *yellow*
Package

cl-naive-tests.

Source

src/color.lisp.

Special Variable: *yellow-back*
Package

cl-naive-tests.

Source

src/color.lisp.


4.2.2 Macros

Macro: with-test-error-handler ((result error &key on-error) &body body)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.


4.2.3 Ordinary functions

Function: %run-suite (suite-identifier &optional test-function)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: %testcase (identifier disabled test-func test-data equal expected actual expression info package)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: call-with-test-error-handler (doit set-result set-error on-error)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: ensure-list (item)
Package

cl-naive-tests.

Source

src/utility.lisp.

Function: error-color ()
Package

cl-naive-tests.

Source

src/color.lisp.

Function: failure-color ()
Package

cl-naive-tests.

Source

src/color.lisp.

Function: iso8601-time-stamp (&optional time)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: junit-format-testcase (testcase)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: junit-format-testsuite (suite)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: junit-format-testsuites (suites)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: normal-color ()
Package

cl-naive-tests.

Source

src/color.lisp.

Function: prepare-filename (pathname)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: prepare-testsuite-name (name)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: print-testcase-result (testcase &key verbose output)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: print-testsuites-results (suites &key verbose output)

When VERBOSE is NIL don’t report the successes.

Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: readable-string (string)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: run-suite (suite)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: run-suites-hashtable (suites)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: run-suites-list (suites)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: sgr (code)
Package

cl-naive-tests.

Source

src/color.lisp.

Function: split-lines (text)
Package

cl-naive-tests.

Source

src/naive-tests.lisp.

Function: success-color ()
Package

cl-naive-tests.

Source

src/color.lisp.


4.2.4 Generic functions

Generic Function: hash-table-projection (keys table)

Returns a new hash-table containing the same values as in TABLE but only for the given keys. KEYS can be a list of keys, or a generalized boolean function called with key and value.

Package

cl-naive-tests.

Source

src/utility.lisp.

Methods
Method: hash-table-projection ((keys function) table)
Method: hash-table-projection ((keys cons) table)
Method: hash-table-projection ((keys null) (table hash-table))

Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   %  
C   D   E   F   G   H   I   J   M   N   P   R   S   T   W  
Index Entry  Section

%
%run-suite: Private ordinary functions
%testcase: Private ordinary functions

C
calc-stats: Public ordinary functions
call-with-test-error-handler: Private ordinary functions
create-suite: Public generic functions
create-suite: Public generic functions

D
define-suite: Public macros
disable-testcase: Public ordinary functions

E
ensure-list: Private ordinary functions
error-color: Private ordinary functions

F
failure-color: Private ordinary functions
find-testcase: Public ordinary functions
format-results: Public generic functions
format-results: Public generic functions
format-results: Public generic functions
format-results: Public generic functions
Function, %run-suite: Private ordinary functions
Function, %testcase: Private ordinary functions
Function, calc-stats: Public ordinary functions
Function, call-with-test-error-handler: Private ordinary functions
Function, disable-testcase: Public ordinary functions
Function, ensure-list: Private ordinary functions
Function, error-color: Private ordinary functions
Function, failure-color: Private ordinary functions
Function, find-testcase: Public ordinary functions
Function, iso8601-time-stamp: Private ordinary functions
Function, junit-format-testcase: Private ordinary functions
Function, junit-format-testsuite: Private ordinary functions
Function, junit-format-testsuites: Private ordinary functions
Function, normal-color: Private ordinary functions
Function, prepare-filename: Private ordinary functions
Function, prepare-testsuite-name: Private ordinary functions
Function, print-testcase-result: Private ordinary functions
Function, print-testsuites-results: Private ordinary functions
Function, readable-string: Private ordinary functions
Function, report: Public ordinary functions
Function, run: Public ordinary functions
Function, run-suite: Private ordinary functions
Function, run-suites-hashtable: Private ordinary functions
Function, run-suites-list: Private ordinary functions
Function, save-results: Public ordinary functions
Function, sgr: Private ordinary functions
Function, skip-testcase: Public ordinary functions
Function, split-lines: Private ordinary functions
Function, statistics: Public ordinary functions
Function, success-color: Private ordinary functions
Function, testsuite-names: Public ordinary functions
Function, testsuite-selection: Public ordinary functions
Function, write-results: Public ordinary functions

G
Generic Function, create-suite: Public generic functions
Generic Function, format-results: Public generic functions
Generic Function, hash-table-projection: Private generic functions
Generic Function, setup-suite: Public generic functions
Generic Function, skip-testcase-reason: Public generic functions
Generic Function, tear-down-suite: Public generic functions

H
hash-table-projection: Private generic functions
hash-table-projection: Private generic functions
hash-table-projection: Private generic functions
hash-table-projection: Private generic functions

I
iso8601-time-stamp: Private ordinary functions

J
junit-format-testcase: Private ordinary functions
junit-format-testsuite: Private ordinary functions
junit-format-testsuites: Private ordinary functions

M
Macro, define-suite: Public macros
Macro, testcase: Public macros
Macro, testsuite: Public macros
Macro, with-test-error-handler: Private macros
Method, create-suite: Public generic functions
Method, format-results: Public generic functions
Method, format-results: Public generic functions
Method, format-results: Public generic functions
Method, hash-table-projection: Private generic functions
Method, hash-table-projection: Private generic functions
Method, hash-table-projection: Private generic functions
Method, setup-suite: Public generic functions
Method, skip-testcase-reason: Public generic functions
Method, tear-down-suite: Public generic functions

N
normal-color: Private ordinary functions

P
prepare-filename: Private ordinary functions
prepare-testsuite-name: Private ordinary functions
print-testcase-result: Private ordinary functions
print-testsuites-results: Private ordinary functions

R
readable-string: Private ordinary functions
report: Public ordinary functions
run: Public ordinary functions
run-suite: Private ordinary functions
run-suites-hashtable: Private ordinary functions
run-suites-list: Private ordinary functions

S
save-results: Public ordinary functions
setup-suite: Public generic functions
setup-suite: Public generic functions
sgr: Private ordinary functions
skip-testcase: Public ordinary functions
skip-testcase-reason: Public generic functions
skip-testcase-reason: Public generic functions
split-lines: Private ordinary functions
statistics: Public ordinary functions
success-color: Private ordinary functions

T
tear-down-suite: Public generic functions
tear-down-suite: Public generic functions
testcase: Public macros
testsuite: Public macros
testsuite-names: Public ordinary functions
testsuite-selection: Public ordinary functions

W
with-test-error-handler: Private macros
write-results: Public ordinary functions


A.3 Variables

Jump to:   *  
R   S  
Index Entry  Section

*
*black*: Private special variables
*black-back*: Private special variables
*blink*: Private special variables
*blue*: Private special variables
*blue-back*: Private special variables
*bold*: Private special variables
*cyan*: Private special variables
*cyan-back*: Private special variables
*debug*: Public special variables
*disabled-count*: Private special variables
*error-count*: Private special variables
*failure-count*: Private special variables
*green*: Private special variables
*green-back*: Private special variables
*invert*: Private special variables
*junit-no-properties*: Public special variables
*magenta*: Private special variables
*magenta-back*: Private special variables
*no-blink*: Private special variables
*no-bold*: Private special variables
*no-invert*: Private special variables
*no-underline*: Private special variables
*normal*: Private special variables
*red*: Private special variables
*red-back*: Private special variables
*skipped-count*: Private special variables
*suite-id*: Private special variables
*suite-name*: Private special variables
*suite-results*: Private special variables
*suites-results*: Public special variables
*test-count*: Private special variables
*test-package*: Private special variables
*test-suite-names*: Private special variables
*test-suites*: Public special variables
*testcase-results*: Private special variables
*testsuite-name*: Private special variables
*underline*: Private special variables
*use-color*: Public special variables
*verbose*: Public special variables
*white*: Private special variables
*white-back*: Private special variables
*yellow*: Private special variables
*yellow-back*: Private special variables

R
reason: Public conditions

S
Slot, reason: Public conditions
Special Variable, *black*: Private special variables
Special Variable, *black-back*: Private special variables
Special Variable, *blink*: Private special variables
Special Variable, *blue*: Private special variables
Special Variable, *blue-back*: Private special variables
Special Variable, *bold*: Private special variables
Special Variable, *cyan*: Private special variables
Special Variable, *cyan-back*: Private special variables
Special Variable, *debug*: Public special variables
Special Variable, *disabled-count*: Private special variables
Special Variable, *error-count*: Private special variables
Special Variable, *failure-count*: Private special variables
Special Variable, *green*: Private special variables
Special Variable, *green-back*: Private special variables
Special Variable, *invert*: Private special variables
Special Variable, *junit-no-properties*: Public special variables
Special Variable, *magenta*: Private special variables
Special Variable, *magenta-back*: Private special variables
Special Variable, *no-blink*: Private special variables
Special Variable, *no-bold*: Private special variables
Special Variable, *no-invert*: Private special variables
Special Variable, *no-underline*: Private special variables
Special Variable, *normal*: Private special variables
Special Variable, *red*: Private special variables
Special Variable, *red-back*: Private special variables
Special Variable, *skipped-count*: Private special variables
Special Variable, *suite-id*: Private special variables
Special Variable, *suite-name*: Private special variables
Special Variable, *suite-results*: Private special variables
Special Variable, *suites-results*: Public special variables
Special Variable, *test-count*: Private special variables
Special Variable, *test-package*: Private special variables
Special Variable, *test-suite-names*: Private special variables
Special Variable, *test-suites*: Public special variables
Special Variable, *testcase-results*: Private special variables
Special Variable, *testsuite-name*: Private special variables
Special Variable, *underline*: Private special variables
Special Variable, *use-color*: Public special variables
Special Variable, *verbose*: Public special variables
Special Variable, *white*: Private special variables
Special Variable, *white-back*: Private special variables
Special Variable, *yellow*: Private special variables
Special Variable, *yellow-back*: Private special variables