-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#384] defn should not introduce local for name in body (tests)
- Loading branch information
Showing
2 changed files
with
35 additions
and
19 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -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))))) |