Skip to content

Commit 2f8a152

Browse files
mfikesswannodette
authored andcommitted
CLJS-1915: cljs.test: Index out of bounds for stack element w/o line/column
1 parent 0a99062 commit 2f8a152

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/main/cljs/cljs/test.cljs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,16 @@
364364
;; File, Line, and Column Helpers
365365

366366
(defn js-line-and-column [stack-element]
367+
"Returns a 2-element vector containing the line and
368+
column encoded at the end of a stack element string.
369+
A line or column will be represented as NaN if not
370+
parsesable."
367371
(let [parts (.split stack-element ":")
368372
cnt (count parts)]
369-
[(js/parseInt (nth parts (- cnt 2)) 10)
370-
(js/parseInt (nth parts (dec cnt)) 10)]))
373+
(if (> cnt 1)
374+
[(js/parseInt (nth parts (- cnt 2)) 10)
375+
(js/parseInt (nth parts (dec cnt)) 10)]
376+
[NaN NaN])))
371377

372378
(defn js-filename [stack-element]
373379
(first (.split (last (.split stack-element "/out/")) ":")))

src/test/cljs/cljs/test_test.cljs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
(ns cljs.test-test
2+
(:require [cljs.test :refer-macros [deftest testing is] :as ct]
3+
[clojure.string :as s]
4+
[clojure.set :as set]))
5+
6+
(defn- nan?
7+
[x]
8+
(and (number? x)
9+
(js/isNaN x)))
10+
11+
(deftest js-line-and-column-test
12+
(is (= [2 3] (ct/js-line-and-column "foo:bar:2:3")))
13+
(is (= [2 3] (ct/js-line-and-column "foo:2:3")))
14+
(is (= [2 3] (ct/js-line-and-column "2:3")))
15+
(let [[line column] (ct/js-line-and-column "foo:bogus:3")]
16+
(is (nan? line))
17+
(is (== 3 column)))
18+
(let [[line column] (ct/js-line-and-column "foo:2:bogus")]
19+
(is (== 2 line))
20+
(is (nan? column)))
21+
(let [[line column] (ct/js-line-and-column "foo:bogus:bogus")]
22+
(is (nan? line))
23+
(is (nan? column)))
24+
(let [[line column] (ct/js-line-and-column "foo:3")]
25+
(is (nan? line))
26+
(is (== 3 column)))
27+
(let [[line column] (ct/js-line-and-column "foo")]
28+
(is (nan? line))
29+
(is (nan? column))))

src/test/cljs/test_runner.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
[cljs.clojure-alias-test]
3939
[cljs.hash-map-test]
4040
[cljs.predicates-test]
41-
[cljs.tagged-literals-test]))
41+
[cljs.tagged-literals-test]
42+
[cljs.test-test]))
4243

4344
(set! *print-newline* false)
4445
(set-print-fn! js/print)
@@ -74,4 +75,5 @@
7475
'cljs.pprint-test
7576
'cljs.predicates-test
7677
'cljs.syntax-quote-test
77-
'cljs.tagged-literals-test)
78+
'cljs.tagged-literals-test
79+
'cljs.test-test)

src/test/self/self_parity/test.cljs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,8 @@
280280
[cljs.clojure-alias-test]
281281
[cljs.hash-map-test]
282282
[cljs.syntax-quote-test]
283-
[cljs.predicates-test]))
283+
[cljs.predicates-test]
284+
[cljs.test-test]))
284285
(fn [{:keys [value error]}]
285286
(if error
286287
(prn error)
@@ -315,7 +316,8 @@
315316
'cljs.clojure-alias-test
316317
'cljs.hash-map-test
317318
'cljs.syntax-quote-test
318-
'cljs.predicates-test)
319+
'cljs.predicates-test
320+
'cljs.test-test)
319321
(fn [{:keys [value error]}]
320322
(when error
321323
(prn error)))))))))

0 commit comments

Comments
 (0)