Skip to content

Commit 4a840d5

Browse files
authored
Capture the current namespace in deftest (#232)
1 parent 3022b7d commit 4a840d5

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

src/basilisp/core/__init__.lpy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -962,14 +962,14 @@
962962
val (second bindings)]
963963
`(try
964964
(do
965-
(.push-bindings (var ~vvar) ~val)
965+
(. (var ~vvar) ~'push-bindings ~val)
966966
~@(if (nthnext bindings 2)
967967
[(concat
968968
(list 'binding (vec (nthrest bindings 2)))
969969
body)]
970970
body))
971971
(finally
972-
(.pop-bindings (var ~vvar))))))
972+
(. (var ~vvar) ~'pop-bindings)))))
973973

974974
(def ^:dynamic *in* sys/stdin)
975975
(def ^:dynamic *out* sys/stdout)

src/basilisp/test.lpy

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

1414
(defmacro is
@@ -62,15 +62,17 @@
6262
runner using Basilisp's builtin PyTest hook."
6363
[name-sym & body]
6464
(let [test-name-sym (with-meta name-sym {:test true})
65-
test-name-str (name test-name-sym)]
65+
test-name-str (name test-name-sym)
66+
test-ns-name `(quote ~(symbol (name *ns*)))]
6667
`(do
6768
(defn ~test-name-sym
6869
[]
69-
(let [~'test-name ~test-name-str
70-
~'test-section nil
71-
~'failures (atom [])]
72-
~@body
73-
{:failures (deref ~'failures)}))
70+
(binding [*ns* (the-ns ~test-ns-name)]
71+
(let [~'test-name ~test-name-str
72+
~'test-section nil
73+
~'failures (atom [])]
74+
~@body
75+
{:failures (deref ~'failures)})))
7476

75-
(add-test! *ns* (var ~test-name-sym))
76-
(reset! current-ns *ns*))))
77+
(add-test! (var ~test-name-sym))
78+
(reset! current-ns (the-ns ~test-ns-name)))))

0 commit comments

Comments
 (0)