Skip to content

Commit

Permalink
TMP: Improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
simendsjo committed Mar 11, 2024
1 parent 0ba32f9 commit 44367d0
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/doctest.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@

(in-package :sijo-doctest/tests)

(defun assert-doctest (expected documentation)
(assert-equalp expected (doctest:test documentation)))
(defun assert-doctest (expected documentation &key (expected-output ""))
(let ((*standard-output* (make-string-output-stream)))
(assert-equalp expected (doctest:test documentation))
(let* ((actual-output (get-output-stream-string *standard-output*))
(expected-output (if (string-equal "" actual-output)
expected-output
;; The output always ends in a newline, so we inject it to simplify the
;; tests
(format nil "~a~%" expected-output))))
(assert-equalp expected-output actual-output))))

(define-test doctest ()
;; Test the documentation for the library itself
Expand All @@ -20,18 +28,18 @@
;; Single pass
(assert-doctest (values 0 1) ">> t t")
;; Single fail
(assert-doctest (values 1 0) ">> t nil")
(assert-doctest (values 1 0) ">> t nil" :expected-output "[1] T returned T, expected NIL.")
;; Error
(assert-doctest (values 0 1) ">> (error 'foo) 'error")
;; Catches subtypes
(assert-doctest (values 0 1) ">> (error 'foo) 'condition")
;; Ok output, ok result
(assert-doctest (values 0 1) ">> (format t \"foo\") -> \"foo\" nil")
;; Ok output, fail result
(assert-doctest (values 1 0) ">> (format t \"foo\") -> \"foo\" t")
(assert-doctest (values 1 0) ">> (format t \"foo\") -> \"foo\" t" :expected-output "[1] (FORMAT T foo) returned NIL, expected T.")
;; Fails output, ok result
(assert-doctest (values 1 0) ">> (format t \"foo\") -> \"bar\" nil")
(assert-doctest (values 1 0) ">> (format t \"foo\") -> \"bar\" nil" :expected-output "[1] (FORMAT T foo) printed \"foo\", expected \"bar\".")
;; Fails output, fail result
(assert-doctest (values 1 0) ">> (format t \"foo\") -> \"bar\" t")
(assert-doctest (values 1 0) ">> (format t \"foo\") -> \"bar\" t" :expected-output "[1] (FORMAT T foo) printed \"foo\", expected \"bar\".")
;; Output can test using symbols
(assert-doctest (values 0 1) ">> (format t \"foo\") -> |foo| nil"))

0 comments on commit 44367d0

Please sign in to comment.