Skip to content

Capture the current namespace in deftest #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/basilisp/core/__init__.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -962,14 +962,14 @@
val (second bindings)]
`(try
(do
(.push-bindings (var ~vvar) ~val)
(. (var ~vvar) ~'push-bindings ~val)
~@(if (nthnext bindings 2)
[(concat
(list 'binding (vec (nthrest bindings 2)))
body)]
body))
(finally
(.pop-bindings (var ~vvar))))))
(. (var ~vvar) ~'pop-bindings)))))

(def ^:dynamic *in* sys/stdin)
(def ^:dynamic *out* sys/stdout)
Expand Down
20 changes: 11 additions & 9 deletions src/basilisp/test.lpy
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

(defn ^:private add-test!
"Add the test named by test-var to the test suite for ns."
[ns test-var]
[test-var]
(swap! collected-tests conj test-var))

(defmacro is
Expand Down Expand Up @@ -62,15 +62,17 @@
runner using Basilisp's builtin PyTest hook."
[name-sym & body]
(let [test-name-sym (with-meta name-sym {:test true})
test-name-str (name test-name-sym)]
test-name-str (name test-name-sym)
test-ns-name `(quote ~(symbol (name *ns*)))]
`(do
(defn ~test-name-sym
[]
(let [~'test-name ~test-name-str
~'test-section nil
~'failures (atom [])]
~@body
{:failures (deref ~'failures)}))
(binding [*ns* (the-ns ~test-ns-name)]
(let [~'test-name ~test-name-str
~'test-section nil
~'failures (atom [])]
~@body
{:failures (deref ~'failures)})))

(add-test! *ns* (var ~test-name-sym))
(reset! current-ns *ns*))))
(add-test! (var ~test-name-sym))
(reset! current-ns (the-ns ~test-ns-name)))))