Skip to content

Commit

Permalink
[#384] defn should not introduce local for name in body (tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Aug 25, 2020
1 parent 0fdb958 commit ccdc866
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
19 changes: 0 additions & 19 deletions test/sci/callstack_test.cljc

This file was deleted.

35 changes: 35 additions & 0 deletions test/sci/error_test.cljc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(ns sci.error-test
(:require [clojure.test :as t :refer [deftest testing is]]
[sci.core :as sci :refer [eval-string]]
[sci.impl.callstack :as cs]
[sci.impl.namespaces :refer [sci-ns-name]]))

(deftest callstack-test
(let [stacktrace
(try (eval-string "
(defn bar [] (/ 1 0))
(defn foo [] (bar))
(foo)"
)
(catch #?(:clj Exception
:cljs js/Error) e
(map #(-> %
(select-keys [:ns :name :line :column])
(update :ns sci-ns-name))
(cs/stacktrace (:callstack (ex-data e))))))]
(is (= '({:ns clojure.core, :name /}
{:ns user, :name bar, :line 2, :column 14}
{:ns user, :name bar, :line 2, :column 1}
{:ns user, :name foo, :line 3, :column 14}
{:ns user, :name foo, :line 3, :column 1}
{:ns user, :name nil, :line 4, :column 1})
stacktrace))))

(deftest locals-test
(testing "defn does not introduce fn-named local binding"
(let [locals
(try (eval-string "(defn foo [x] (/ 1 0)) (foo :x)")
(catch #?(:clj clojure.lang.ExceptionInfo :cljs cljs.core/ExceptionInfo) e
(:locals (ex-data e))))
ks (keys locals)]
(is (= '[x] ks)))))

0 comments on commit ccdc866

Please sign in to comment.