Skip to content

Commit

Permalink
CLJS-1915: cljs.test: Index out of bounds for stack element w/o line/…
Browse files Browse the repository at this point in the history
…column
  • Loading branch information
mfikes authored and swannodette committed Jan 28, 2017
1 parent 0a99062 commit 2f8a152
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/main/cljs/cljs/test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -364,10 +364,16 @@
;; File, Line, and Column Helpers

(defn js-line-and-column [stack-element]
"Returns a 2-element vector containing the line and
column encoded at the end of a stack element string.
A line or column will be represented as NaN if not
parsesable."
(let [parts (.split stack-element ":")
cnt (count parts)]
[(js/parseInt (nth parts (- cnt 2)) 10)
(js/parseInt (nth parts (dec cnt)) 10)]))
(if (> cnt 1)
[(js/parseInt (nth parts (- cnt 2)) 10)
(js/parseInt (nth parts (dec cnt)) 10)]
[NaN NaN])))

(defn js-filename [stack-element]
(first (.split (last (.split stack-element "/out/")) ":")))
Expand Down
29 changes: 29 additions & 0 deletions src/test/cljs/cljs/test_test.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
(ns cljs.test-test
(:require [cljs.test :refer-macros [deftest testing is] :as ct]
[clojure.string :as s]
[clojure.set :as set]))

(defn- nan?
[x]
(and (number? x)
(js/isNaN x)))

(deftest js-line-and-column-test
(is (= [2 3] (ct/js-line-and-column "foo:bar:2:3")))
(is (= [2 3] (ct/js-line-and-column "foo:2:3")))
(is (= [2 3] (ct/js-line-and-column "2:3")))
(let [[line column] (ct/js-line-and-column "foo:bogus:3")]
(is (nan? line))
(is (== 3 column)))
(let [[line column] (ct/js-line-and-column "foo:2:bogus")]
(is (== 2 line))
(is (nan? column)))
(let [[line column] (ct/js-line-and-column "foo:bogus:bogus")]
(is (nan? line))
(is (nan? column)))
(let [[line column] (ct/js-line-and-column "foo:3")]
(is (nan? line))
(is (== 3 column)))
(let [[line column] (ct/js-line-and-column "foo")]
(is (nan? line))
(is (nan? column))))
6 changes: 4 additions & 2 deletions src/test/cljs/test_runner.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
[cljs.clojure-alias-test]
[cljs.hash-map-test]
[cljs.predicates-test]
[cljs.tagged-literals-test]))
[cljs.tagged-literals-test]
[cljs.test-test]))

(set! *print-newline* false)
(set-print-fn! js/print)
Expand Down Expand Up @@ -74,4 +75,5 @@
'cljs.pprint-test
'cljs.predicates-test
'cljs.syntax-quote-test
'cljs.tagged-literals-test)
'cljs.tagged-literals-test
'cljs.test-test)
6 changes: 4 additions & 2 deletions src/test/self/self_parity/test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@
[cljs.clojure-alias-test]
[cljs.hash-map-test]
[cljs.syntax-quote-test]
[cljs.predicates-test]))
[cljs.predicates-test]
[cljs.test-test]))
(fn [{:keys [value error]}]
(if error
(prn error)
Expand Down Expand Up @@ -315,7 +316,8 @@
'cljs.clojure-alias-test
'cljs.hash-map-test
'cljs.syntax-quote-test
'cljs.predicates-test)
'cljs.predicates-test
'cljs.test-test)
(fn [{:keys [value error]}]
(when error
(prn error)))))))))
Expand Down

0 comments on commit 2f8a152

Please sign in to comment.