forked from marick/Midje
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:marick/Midje
- Loading branch information
Showing
8 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
;; -*- indent-tabs-mode: nil -*- | ||
|
||
(ns leiningen.timings | ||
(:refer-clojure :exclude [test]) | ||
(:use [leiningen.util.ns :only [namespaces-in-dir]] | ||
[leiningen.test :only [*exit-after-tests*]] | ||
[leiningen.compile :only [eval-in-project]] | ||
[clojure.set :only [difference]])) | ||
|
||
(defn require-namespaces-form [namespaces] | ||
`(let [array# (doall (map (fn [_#] (let [start# (.getTime (java.util.Date.))] | ||
(when (= clojure.lang.MultiFn (type clojure.test/report)) | ||
(defmethod clojure.test/report :begin-test-ns [m#])) | ||
|
||
(alter-var-root (var clojure.test/*report-counters*) | ||
(fn [_#] (ref clojure.test/*initial-report-counters*))) | ||
|
||
(dosync (alter @#'clojure.core/*loaded-libs* difference (set '~namespaces))) | ||
(doseq [n# '~namespaces] (require n# :reload)) | ||
|
||
(- (.getTime (java.util.Date.)) start#))) | ||
(range 7)))] | ||
(println (sort array#)))) | ||
|
||
(defn timings | ||
"Run both Midje and clojure.test tests. | ||
Namespaces are looked up in both the src/ and test/ subdirectories. | ||
If no namespaces are given, runs tests in all namespaces." | ||
[project & namespaces] | ||
(let [desired-namespaces (if (empty? namespaces) | ||
(concat (namespaces-in-dir (:test-path project)) | ||
(namespaces-in-dir (:source-path project))) | ||
(map symbol namespaces))] | ||
(eval-in-project project | ||
(require-namespaces-form desired-namespaces) | ||
nil | ||
nil | ||
'(require '[clojure walk template stacktrace test string set])))) | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(ns behaviors.t-macros | ||
(:use [midje sweet test-util])) | ||
|
||
;; Example from wiki | ||
(defmacro my-if [test true-branch false-branch] | ||
`(cond ~test ~true-branch :else ~false-branch)) | ||
|
||
(fact | ||
(my-if (odd? 1) 1 2) =expands-to=> (clojure.core/cond (odd? 1) 1 :else 2)) | ||
|
||
|
||
|
||
(defmacro macro-with-expander [arg1 & other-args] | ||
(let [modified (str arg1 "-suffix")] | ||
`(str ~modified "(was " ~arg1 ")" | ||
(apply + '~other-args)))) | ||
|
||
(defn times-ten [arg] (* 10 arg)) | ||
|
||
(defmacro macro-with-only-expansion [& args] | ||
`(map times-ten ~@args)) | ||
|
||
(defmacro macro-calling-other-macro [arg others] | ||
`(str ~arg (first (macro-with-only-expansion (list ~@others))))) | ||
|
||
(facts "about expecting on macro expansion" | ||
(fact "macros with expansion code only work" | ||
(macro-with-only-expansion (list 1 2 3)) => (list 10 20 30) | ||
(macro-with-only-expansion (list 1 2 3)) =expands-to=> (clojure.core/map behaviors.t-macros/times-ten (list 1 2 3))) | ||
|
||
(fact "macros with expander code work" | ||
(macro-with-expander 666 10 20 30) => "666-suffix(was 666)60" | ||
(macro-with-expander 666 10 20 30) =expands-to=> (clojure.core/str "666-suffix" "(was " 666 ")" (clojure.core/apply clojure.core/+ '(10 20 30)))) | ||
|
||
(fact "macros calling other macros are macroexpand-1" | ||
(macro-calling-other-macro 999 [ 10 20 30]) => "999100" | ||
(macro-calling-other-macro 999 [ 10 20 30]) =expands-to=> (clojure.core/str 999 (clojure.core/first (behaviors.t-macros/macro-with-only-expansion (clojure.core/list 10 20 30)))))) | ||
|
This file contains 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