Created
September 1, 2011 05:31
-
-
Save michalmarczyk/1185513 to your computer and use it in GitHub Desktop.
A nestable with-test-tags macro to tag clojure.test tests for use with external tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; See | |
;;; http://stackoverflow.com/questions/7240947/is-a-transparent-macrolet-possible | |
;;; for a discussion. | |
;;; src/deftest_magic/core.clj | |
(ns deftest-magic.core | |
(:use [clojure.tools.macro :only [macrolet]])) | |
(comment | |
(def ^:dynamic *tags* #{}) | |
(defmacro with-test-tags [tags & body] | |
`(binding [*tags* (into *tags* ~tags)] | |
~@body)) | |
(defmacro deftest [name & body] | |
`(let [n# (vary-meta '~name update-in [:tags] (fnil into #{}) *tags*) | |
form# (list* 'clojure.test/deftest n# '~body)] | |
(eval form#))) | |
) | |
(def ^:dynamic *tags* #{}) | |
(defmacro with-test-tags [tags & body] | |
`(macrolet [~'(deftest [name & body] | |
`(let [n# (vary-meta '~name update-in [:tags] (fnil into #{}) *tags*) | |
form# (list* 'clojure.test/deftest n# '~body)] | |
(eval form#)))] | |
(binding [*tags* (into *tags* ~tags)] | |
~@body))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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"]]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; test/deftest_magic/test/core.clj | |
(ns deftest-magic.test.core | |
(:use [deftest-magic.core :only [with-test-tags]]) | |
(:use [clojure.test]) | |
) | |
(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))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment