Skip to content

@michalmarczyk /core.clj
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A nestable with-test-tags macro to tag clojure.test tests for use with external tools.
;;; See
;;; http://stackoverflow.com/questions/7240947/is-a-transparent-macrolet-possible
;;; for a discussion.
;;; Also see
;;; https://gist.github.com/1185513
;;; for an earlier approach.
;;; src/deftest-magic/core.clj
(ns deftest-magic.core
(:use [clojure.tools.macro :only [macrolet]]))
(defmacro with-test-tags [tags & body]
(let [deftest-decl
(list 'deftest ['name '& 'body]
(list 'let ['n `(vary-meta ~'name update-in [:tags]
(fnil into #{}) ~tags)
'form `(list* '~'clojure.test/deftest ~'n ~'body)]
'form))
with-test-tags-decl
(list 'with-test-tags ['tags '& 'body]
`(list* 'with-test-tags
(into ~tags ~'tags) ~'body))]
`(macrolet [~deftest-decl
~with-test-tags-decl]
~@body)))
(defproject deftest-magic "0.1.0-SNAPSHOT"
:description "A nestable with-test-tags macro to tag clojure.test tests for use with external tools."
:dependencies [[org.clojure/clojure "1.3.0-beta2"]
[org.clojure/tools.macro "0.1.1"]])
;;; test/deftest-magic/test/core.clj
(ns deftest-magic.test.core
(:use [deftest-magic.core :only [with-test-tags #_deftest]])
(:use [clojure.test #_:exclude #_[deftest]])
)
(deftest plain-deftest
(is (= :foo :foo)))
(with-test-tags #{:foo}
(deftest foo
(is true))
(with-test-tags #{:bar}
(deftest foo-bar
(is true))))
(deftest test-tags
(let [plaintest-tags (:tags (meta #'plain-deftest))]
(is (or (nil? plaintest-tags) (empty? plaintest-tags))))
(is (= #{:foo} (:tags (meta #'foo))))
(is (= #{:foo :bar} (:tags (meta #'foo-bar)))))
(let [x 1]
(deftest lexical-bindings-no-tags
(is (= x 1))))
(with-test-tags #{:foo}
(let [x 1]
(deftest easy (is true))
(deftest lexical-bindings-with-tags
(is (= #{:foo} (:tags (meta #'easy))))
(is (= x 1)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.