Skip to content

Commit 9b63f9a

Browse files
author
dnolen
committed
refactor so we can do infer tests with core loaded
1 parent b471421 commit 9b63f9a

1 file changed

Lines changed: 40 additions & 11 deletions

File tree

src/test/clojure/cljs/analyzer_tests.clj

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -857,21 +857,33 @@
857857
))))
858858
)
859859

860-
(defn infer-test-helper [{:keys [forms externs warnings warn]}]
860+
(def core-inferred
861+
["var setTimeout;" "var process;" "process.hrtime;"
862+
"goog.isArrayLike;" "Java.type;" "Object.out;" "Object.out.println;"
863+
"Object.error;" "Object.error.println;"])
864+
865+
(defn infer-test-helper [{:keys [forms externs warnings warn with-core?]}]
861866
(let [test-cenv (atom {::a/externs
862867
(externs/externs-map
863-
(closure/load-externs {:externs (or externs [])}))})]
868+
(closure/load-externs {:externs (or externs [])}))})
869+
wrap (if with-core?
870+
#(comp/with-core-cljs nil %)
871+
#(do (%)))]
864872
(a/with-warning-handlers [(collecting-warning-handler (or warnings (atom [])))]
865-
(binding [a/*cljs-ns* a/*cljs-ns*
866-
a/*cljs-warnings* (assoc a/*cljs-warnings*
867-
:infer-warning (if (nil? warn) true warn))]
873+
(binding [a/*analyze-deps* false
874+
a/*cljs-ns* a/*cljs-ns*]
868875
(e/with-compiler-env test-cenv
869-
(a/analyze-form-seq forms)
870-
(with-out-str
871-
(comp/emit-externs
872-
(reduce util/map-merge {}
873-
(map (comp :externs second)
874-
(get @test-cenv ::a/namespaces))))))))))
876+
(wrap
877+
(fn []
878+
(binding [a/*cljs-warnings*
879+
(assoc a/*cljs-warnings*
880+
:infer-warning (if (nil? warn) true warn))]
881+
(a/analyze-form-seq forms))
882+
(with-out-str
883+
(comp/emit-externs
884+
(reduce util/map-merge {}
885+
(map (comp :externs second)
886+
(get @test-cenv ::a/namespaces))))))))))))
875887

876888
(deftest test-basic-infer
877889
(let [res (infer-test-helper
@@ -985,3 +997,20 @@
985997
(is (string/blank? res))
986998
(is (= 1 (count @ws)))
987999
(is (string/starts-with? (first @ws) "Cannot infer target type"))))
1000+
1001+
(comment
1002+
1003+
(deftest test-cljs-1970-infer-with-cljs-literals
1004+
(let [ws (atom [])
1005+
res (infer-test-helper
1006+
{:forms '[(ns cjls-1970.core)
1007+
(set! *warn-on-infer* true)
1008+
(defn foo [] (list))
1009+
(defn bar [] (vector))]
1010+
:externs ["src/test/externs/test.js"]
1011+
:warnings ws
1012+
:with-core? true})]
1013+
(println @ws)
1014+
(is (zero? (count @ws)))))
1015+
1016+
)

0 commit comments

Comments
 (0)