Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Provide middleware point to handle *cljs-warnings*
* Add in a default warning middleware with that same behavior as the current warning handler. * Centralize the default warning behavior, make side-effects from each invocation of warning controllable through middleware. * fix no-warn macro, make sure undeclared-ns-form is passed to warning for the right forms * Make analyzer default-warning-handler respect *cljs-warnings* * Fix default-warning-handler implementation and all the callers * Change cljs.analyzer/confirm-var-exists: Don't call warning unless :undeclared-var warning is set, AND the var hasn't been def'd * Add some basic all-warn no-warn analyzer tests
- Loading branch information
1 parent
69f0060
commit abd4450
Showing
5 changed files
with
107 additions
and
48 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
@@ -1,2 +1,33 @@ | ||
(ns cljs.analyzer-tests | ||
(:require [cljs.analyzer :as a]) | ||
(:use clojure.test)) | ||
|
||
;;****************************************************************************** | ||
;; cljs-warnings tests | ||
;;****************************************************************************** | ||
|
||
(defn make-counter [] | ||
(let [counter (atom 0)] | ||
{:counter counter | ||
:f (fn [& args] | ||
(swap! counter inc))})) | ||
|
||
(def warning-forms | ||
{:undeclared-var (let [v (gensym)] `(~v 1 2 3)) | ||
:fn-arity '(do (defn x [a b] (+ a b)) | ||
(x 1 2 3 4))}) | ||
|
||
(defn warn-count [form] | ||
(let [{:keys [counter f]} (make-counter) | ||
tracker (fn [warning-type env & [extra]] | ||
(println "Warning: " warning-type) | ||
(println "\tenabled? " (warning-type a/*cljs-warnings*)))] | ||
(a/with-warning-handlers [f] | ||
(a/analyze (a/empty-env) form)) | ||
@counter)) | ||
|
||
(deftest no-warn | ||
(is (every? zero? (map (fn [[name form]] (a/no-warn (warn-count form))) warning-forms)))) | ||
|
||
(deftest all-warn | ||
(is (every? #(= 1 %) (map (fn [[name form]] (a/all-warn (warn-count form))) warning-forms)))) |