Common Lisp Package: CHECKL

README:

CheckL

Why write programs in Common Lisp but tests like Java?

My workflow for writing Common Lisp tends to be like this:

  • Write a bit of lisp, perhaps a function, class, or structure
  • Write a snippet in a scratch buffer to test
  • Fix if necessary and repeat

Testing is already inherent in this process, all we need is a little bit of Common Lisp magic to take advantage of it. Thus, CheckL:

`lisp (defun foo () (+ 1 1))

(check () (foo)) ;; => 2

(defun foo () (+ 1 2))

(check () (foo))

|  
v 

Result 0 has changed: 3 Previous result: 2 [Condition of type CHECKL::RESULT-ERROR]

Restarts: 0: [USE-NEW-VALUE] The new value is correct, use it from now on. 1: [SKIP-TEST] Skip this, leaving the old value, but continue testing 2: [RETRY] Retry SLIME interactive evaluation request. 3: [*ABORT] Return to SLIME's top level. 4: [TERMINATE-THREAD] Terminate this thread (#<THREAD "worker" RUNNING >) `

See the full documentation for more details!

FUNCTION

Public

CHECKL-LOAD (&OPTIONAL FILESPEC)

Load package test results from `FILESPEC`

CHECKL-STORE (&OPTIONAL FILESPEC)

Store package test results to `FILESPEC`

CLEAR (&REST NAMES)

Clear the test results from the tests `NAMES`. For clearing anonymous test results, see `CLEAR-ANONYMOUS`.

CLEAR-ANONYMOUS

Clear anonymous test results. For clearing named tests, see `CLEAR`.

RUN (&REST NAMES)

=> test-results Run tests named `NAMES`, collecting their results.

RUN-ALL (&OPTIONAL (CATEGORY DEFAULT) &REST CATEGORIES)

=> test-results Run all tests, optionally specifying categories.

Private

PACKAGE-TESTS-CATEGORIES (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PACKAGE-TESTS-DEFAULT-CHECKL-STORE (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PACKAGE-TESTS-LAMBDAS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

PACKAGE-TESTS-RESULTS (INSTANCE)

@arg[extid]{A @class{extid}} @return[sytemid]{puri:uri or nil} Returns the System ID part of this External ID.

Undocumented

COPY-PACKAGE-TESTS (INSTANCE)

CURRENT-TESTS

ENSURE-TEST (TEST-NAME TEST-CATEGORY TEST-BODY FUNCTION)

MAKE-PACKAGE-TESTS (&KEY ((RESULTS DUM0) (MAKE-HASH-TABLE TEST 'EQUALP)) ((CATEGORIES DUM1) (MAKE-HASH-TABLE TEST 'EQUALP)) ((LAMBDAS DUM2) (MAKE-HASH-TABLE TEST 'EQUALP)) ((DEFAULT-CHECKL-STORE DUM3) NIL))

SETFPACKAGE-TESTS-CATEGORIES (NEW-VALUE INSTANCE)

SETFPACKAGE-TESTS-DEFAULT-CHECKL-STORE (NEW-VALUE INSTANCE)

SETFPACKAGE-TESTS-LAMBDAS (NEW-VALUE INSTANCE)

PACKAGE-TESTS-P (OBJECT)

SETFPACKAGE-TESTS-RESULTS (NEW-VALUE INSTANCE)

VERIFY-RESULT (NAME RESULT)

MACRO

Public

CHECK ((&KEY NAME (CATEGORY DEFAULT) (OUTPUT-P NIL)) &BODY BODY)

=> test-results Run `BODY`. Check resulting values against the last run using `CHECKL:RESULT-EQUALP`, or store them if this is the first run. Sameness of the test is determined by comparing the body with `EQUALP`, or by `NAME`. `NAME` may be specified to name a test. If the test exists but is anonymous (i.e., `NAME` has not been specified), specifying `NAME` will name the test and it will no longer be anonymous. `CATEGORY` may be specified for running groups of tests. If `OUTPUT-P` is `t`, the results will be printed to `*standard-output*` as well as returned. This may be helpful if the results are too long to see in your emacs minibuffer.

CHECK-OUTPUT (&BODY BODY)

Use this within a `CHECK` block. Rebind `*standard-output*` and `*error-output*` and return a `CHECK`-able result.

RESULTS (&REST VALUES)

=> VALUES This will evaluate each subform in order and call RESULT-TRANSLATE on the result. This is especially useful if subforms repeatedly modify and return the object, e.g. `(results (incf *x*) (incf *x*))`. If multiple values are returned, each value is mapped via RESULT-TRANSLATE and the result is returned as a list of the translated values.

Private

Undocumented

DO-CATEGORIES ((VAR TESTS) &BODY BODY)

GENERIC-FUNCTION

Public

RESULT-EQUALP (O1 O2)

Generic function to compare test results `O1` to `O2`. Defaults to `EQUALP`.

RESULT-TRANSLATE (RESULT)

RESULT-TRANSLATE is called on RESULT before calling RESULT-EQUALP and before storing RESULT. This defaults to RESULT, but may be useful for converting more complex objects into simpler objects. For sequences and structures, COPY-SEQ and COPY-STRUCTURE are called. For STANDARD-OBJECT instances, (MS:UNMARSHAL (MS:MARSHAL OBJECT)) is called.

Private

Undocumented

RESULT-ERROR-INDEX (CONDITION)

RESULT-ERROR-LAST (CONDITION)

RESULT-ERROR-VALUE (CONDITION)

SLOT-ACCESSOR

Private

Undocumented

TEST-VALUES-PACKAGE (OBJECT)

SETFTEST-VALUES-PACKAGE (NEW-VALUE OBJECT)

VARIABLE

Private

Undocumented

*ALL-TESTS*

*DEFINITIONS-ONLY*

CLASS

Public

TEST-VALUES

An ASDF component for loading CheckL test values.

TESTS

Load a file with CHECK or CHECK-FORMAL tests.

Private

Undocumented

PACKAGE-TESTS

CONDITION

Private

Undocumented

RESULT-ERROR