Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Add local variables map to 'expect'
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Sierra committed Aug 16, 2010
1 parent 3ebf3ed commit 0b9fc41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/clojure/lazytest/expect.clj
@@ -1,6 +1,12 @@
(ns lazytest.expect
(:import (lazytest ExpectationFailed)))

(defn- local-bindings
"Returns a map of the names of local bindings to their values."
[env]
(reduce (fn [m sym] (assoc m `'~sym sym))
{} (keys env)))

(defn- function-call?
"True if form is a list representing a normal function call."
[form]
Expand Down Expand Up @@ -33,6 +39,7 @@
(merge '~(meta &form)
'~(meta expr)
{:form '~expr
:locals ~(local-bindings &env)
:evaluated (list* f# args#)
:result result#
:file ~*file*
Expand All @@ -45,6 +52,7 @@
(merge '~(meta &form)
'~(meta expr)
{:form '~expr
:locals ~(local-bindings &env)
:result result#
:file ~*file*
:ns *ns*}
Expand Down
8 changes: 8 additions & 0 deletions src/test/clojure/lazytest/expect_asserts.clj
Expand Up @@ -37,3 +37,11 @@
(assert (= '(instance? java.lang.String 42) (:form reason)))
(assert (= (list instance? java.lang.String 42) (:evaluated reason)))
(assert (false? (:result reason)))))

(let [x (+ 3 4)]
(let [e4 (try (expect (zero? (* x 2)))
false
(catch ExpectationFailed err err))]
(assert e4)
(let [reason (.reason e4)]
(assert (= {'x 7} (:locals reason))))))

0 comments on commit 0b9fc41

Please sign in to comment.