Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
71 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,47 @@ | ||
(ns north.core) | ||
(set! *warn-on-reflection* true) | ||
|
||
(def ^:dynamic test-map {}) | ||
|
||
(defmacro describe [description & body] | ||
`(do | ||
(in-ns 'north.core) | ||
(def test-map (assoc test-map (keyword ~description) {})) | ||
(println test-map) | ||
(println (format "before %s" test-map)) | ||
|
||
(println (format "description %s" ~description)) | ||
|
||
(def test-map | ||
(assoc test-map | ||
(keyword ~description) {})) | ||
|
||
(println (format "after %s" test-map)) | ||
~body)) | ||
|
||
(defmacro context [description & body] | ||
`(do | ||
())) | ||
~body)) | ||
|
||
(defmacro it [description & body] | ||
`(defn (symbol ~description) [] | ||
~body)) | ||
|
||
(defn should | ||
([result matcher] | ||
(matcher result)) | ||
([result matcher expectation] | ||
(matcher result expectation))) | ||
|
||
(defn- verify [result expectation operation description] | ||
(assert (operation result expectation) (format "Assertion failed. %s was expected to be %s %s" result description expectation))) | ||
|
||
(defn be-not-equals [result expectation] | ||
(verify result expectation not= "different than")) | ||
|
||
(defn be-equals [result expectation] | ||
(assert (= result expectation) (format "Assertion failed. %s was expected to be %s" result expectation))) | ||
|
||
(defn be-true [result] | ||
(be-equals result true)) | ||
|
||
(defn be-false [result] | ||
(be-equals result false)) |
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 |
---|---|---|
@@ -1,10 +1,37 @@ | ||
(ns north.test.core | ||
(:use [north.core])) | ||
|
||
(describe "North" | ||
(context "using context" | ||
(it "should test simple assertions" | ||
(should (= 1 1) be-true) | ||
(should (= 1 0) be-false) | ||
(should (+ 1 1) be-equals 2) | ||
(should (+ 1 1) be-not-equals 1)))) | ||
(println | ||
(macroexpand | ||
'(describe "North" | ||
(context "using context" | ||
(it "should test simple assertions" | ||
(should (= 1 1) be-true) | ||
(should (= 1 0) be-false) | ||
(should (+ 1 1) be-equals 2) | ||
(should (+ 1 1) be-not-equals 1)))))) | ||
|
||
(do | ||
(clojure.core/in-ns | ||
(quote north.core)) | ||
(clojure.core/println | ||
(clojure.core/format "before %s" north.core/test-map)) | ||
(clojure.core/println | ||
(clojure.core/format "description %s" "North")) | ||
(def north.core/test-map | ||
(clojure.core/assoc north.core/test-map | ||
(clojure.core/keyword "North") {})) | ||
(clojure.core/println | ||
(clojure.core/format "after %s" north.core/test-map)) | ||
((context "using context" | ||
(it "should test simple assertions" | ||
(should (= 1 1) be-true) | ||
(should (= 1 0) be-false) | ||
(should (+ 1 1) be-not-equals 1) | ||
(should (+ 1 1) be-equals 2) | ||
|
||
true | ||
) | ||
) | ||
) | ||
) |