Yet another doctest implementation in Clojure
testdoc extends clojure.test/is
macro.
=> (require '[clojure.test :as t]
=> 'testdoc.core)
nil
=> (defn myplus
=> "Add a and b
=>
=> => (myplus 1 2)
=> 3
=> => (myplus 2
=> => 3)
=> 5"
=> [a b]
=> (+ a b))
var?
=> (t/deftest myplus-test
=> (t/is (testdoc #'myplus)))
var?
=> (t/test-var *1)
nil
;; Other examples
=> (hash-map :multiple "lines")
{:multiple
"lines"}
(defn mymulti
"Multiply a and b
(mymulti 1 2)
;; => 2
(mymulti 2
3)
;; => 6"
[a b]
(* a b))
;; => var?
(t/deftest mymulti-test
(t/is (testdoc #'mymulti)))
;; => var?
(t/test-var *1)
;; => nil
;; Other examples
(hash-map :multiple "lines")
;; => {:multiple
;; => "lines"}
This document is tested by this library, of course!
(require '[clojure.java.io :as io])
;; => nil
(t/deftest external-document-test
(t/is (testdoc (slurp (io/file "test/resources/README.adoc")))))
;; => var?
(t/test-var *1)
;; => nil
testdoc will add a line number information to a error message text.
For example, you have a test code like below:
(t/deftest error-test
(t/is (testdoc "=> (unresolved-symbol)
:failure")))
Then, lein test
will show you errors like below:
(= (unresolved-symbol) :failure), [line: 1]
When you see Unresolved symbol: testdoc
error with clj-kondo,
you can import a config file for this library by the following command.
clj-kondo --copy-configs --dependencies --lint "$(shell clojure -A:dev -Spath)"
# .clj-kondo/com.github.liquidz/testdoc/config.edn should be created
Copyright © 2018-2022 Masashi Iizuka
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation? These fine people already did:
liquidz, Masashi Iizuka & Iizuka MasashiEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close