Skip to content

Instantly share code, notes, and snippets.

@mybuddymichael
Last active December 10, 2015 11:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mybuddymichael/4425558 to your computer and use it in GitHub Desktop.
Save mybuddymichael/4425558 to your computer and use it in GitHub Desktop.
Using a String for Clojure test names.
(require 'clojure.test)
(defmacro deftest*
[name-string & body]
(let [name-symbol
(-> name-string
clojure.string/lower-case
(clojure.string/replace #"\W" "-")
(clojure.string/replace #"-+" "-")
(clojure.string/replace #"-$" "")
symbol)]
`(clojure.test/deftest ~name-symbol ~@body)))
(macroexpand-1 '(deftest* "this is a test" (is true)))
;=> (clojure.test/deftest this-is-a-test (is true))
@danielribeiro
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment