Description
Annotation Syntax Test Library.
Examples
1. tests
(in-package :cl-user)
(defpackage sample
(:use :cl
:cl-annot-prove
:prove))
(in-package :sample)
;; Have to load systems: cl-syntax and cl-syntax-annot.
(syntax:use-syntax :annot)
@tests
((is (add 1 2) 3))
(defun add (a b)
(+ a b))
(render-symbol-tests (car (query-symbol-tests :symbol-name "ADD")))
#|
"(ADD 1 2)
;; => 3"
|#
@tests.before
(print "Before tests.")
@tests.after
(print "After tests.")
@tests.around
(let ((int1 1)) (call-tests))
@tests.before.each
(print "Before each tests.")
@tests.after.each
(print "After each tests.")
@tests.around.each
(let ((int2 2)) (call-tests))
@tests
((let ((int3 3))
(is (add int1 int2) int3))
(let ((int4 1))
(is (add int1 int4) int2)))
(defun add (a b)
(+ a b))
(render-symbol-tests (car (query-symbol-tests :symbol-name "ADD")))
#|
"(LET ((INT1 1))
(PRINT \"Before tests.\")
(LET ((INT2 2))
(PRINT \"Before each tests.\")
(LET ((INT3 3))
(ADD INT1 INT2)
;; => 3)
(PRINT \"After each tests.\")
(PRINT \"Before each tests.\")
(LET ((INT4 1))
(ADD INT1 INT4)
;; => 2)
(PRINT \"After each tests.\"))
(PRINT \"After tests.\"))"
|#
(run-symbol-tests (car (query-symbol-tests :symbol-name "ADD")))
#|
"Before tests."
"Before each tests."
✓ 3 is expected to be 3
"After each tests."
"Before each tests."
✓ 2 is expected to be 2
"After each tests."
"After tests."
"After tests."
|#
(run-package-tests *package*)
#|
PACKAGE: #<PACKAGE "SAMPLE">
1..1
SYMBOL: ADD
"Before tests."
✓ 3 is expected to be 3
"After tests."
"Before tests."
✓ 2 is expected to be 2
"After tests."
✓ 1 test completed (0ms)
T
|#
2. query-symbol-tests
(in-package :cl-user)
(defpackage sample
(:use :cl
:cl-annot-prove
:prove))
(in-package :sample)
(syntax:use-syntax :annot)
@tests
((is (add 1 2) 3))
(defun add (a b)
(+ a b))
(query-symbol-tests :symbol 'add)
;; => (list #S(SYMBOL-TESTS ...) ...)
(query-symbol-tests :symbol-name "ADD")
;; => (list #S(SYMBOL-TESTS ...) ...)
(query-symbol-tests :symbol-package (symbol-package 'add))
;; => (list #S(SYMBOL-TESTS ...) ...)
(query-symbol-tests :symbol-package :sample)
;; => (list #S(SYMBOL-TESTS ...) ...)
(query-symbol-tests :symbol-package "SAMPLE")
;; => (list #S(SYMBOL-TESTS ...) ...)
3. asdf
(in-package :cl-user)
(defpackage sample-asd
(:use :cl :asdf))
(in-package :sample-asd)
(defsystem sample
:version "0.1"
:author "Rudolph Miller"
:license "MIT"
:depends-on (:cl-syntax
:cl-syntax-annot
:cl-annot-prove)
:components ((:module "src"
:serial t
:components
((:file "sample"))))
:description "Sample asd."
:perform (test-op (op c)
(uiop:symbol-call :cl-annot-prove :run-system-tests c)))
;; Add two lines from the bottom.
;; Run test.
(asdf:test-system :sample)
#|
...
✓ 1 test completed (0ms)
T
|#
;; From console.
;; ros -s cl-annot-prove -e '(or (annot.prove:run-system-tests :elb-log) (uiop:quit -1))'
4. run-system-tests
(asdf:load-system :sample)
(annot.prove:run-system-tests :sample)
#|
...
✓ 1 test completed (0ms)
T
|#
;; or you can use roswell script
;; $ ros install cl-annot-prove
;; $ run-annot-prove *.asd
Source
CL-ANNOT-PROVEAuthor
Rudolph MillerLicence
MIT