Permalink
Browse files

Add some basic config tests. Issue #70.

  • Loading branch information...
1 parent 3db0757 commit efeeafaaa047df17abfcd3309a2b6841826a26c3 @emezeske committed Apr 8, 2012
Showing with 70 additions and 3 deletions.
  1. +4 −3 plugin/src/leiningen/cljsbuild/config.clj
  2. +66 −0 plugin/test/leiningen/test/cljsbuild/config.clj
@@ -54,7 +54,7 @@
(assoc no-crossovers
:crossovers all-crossovers))))
-(defn- backwards-compat [options]
+(defn backwards-compat [options]
(-> options
backwards-compat-builds
backwards-compat-crossovers))
@@ -99,11 +99,12 @@
build
(assoc-in build output-dir-key
(str compiler-output-dir-base counter))))]
- (if (apply distinct? (map #(get-in % output-dir-key) builds))
+ (if (or (empty? builds)
+ (apply distinct? (map #(get-in % output-dir-key) builds)))
(assoc options :builds builds)
(throw (Exception. (str "All " output-dir-key " options must be distinct."))))))
-(defn- set-default-options [options]
+(defn set-default-options [options]
(set-default-output-dirs
(deep-merge default-global-options
(assoc options :builds
@@ -0,0 +1,66 @@
+(ns leiningen.test.cljsbuild.config
+ (:use
+ leiningen.cljsbuild.config
+ clojure.test))
+
+(deftest test-backwards-compatibility
+ (let [config-0-0-x-early {:source-path "a"
+ :compiler {:output-to "hello.js"}}
+ config-0-0-x-late [{:source-path "a"
+ :compiler {:output-to "hello.js"}}]
+ config-backwards {:builds
+ [{:source-path "a"
+ :compiler {:output-to "hello.js"}}]}]
+ (is (= config-backwards (backwards-compat config-0-0-x-early)))
+ (is (= config-backwards (backwards-compat config-0-0-x-late)))))
+
+(deftest test-ids
+ (let [config-vec {:builds [{:id "a"} {:id "b"}]}
+ config-map {:builds {:a {} :b {}}}]
+ (is (= config-vec (convert-builds-map config-vec)))
+ (is (= config-vec (convert-builds-map config-map)))))
+
+(deftest test-shell-command
+ (is (= {:shell []}
+ (parse-shell-command [])))
+ (is (= {:shell ["a"]}
+ (parse-shell-command ["a"])))
+ (is (= {:shell ["a" "b" "c"] :x 1 :y 2}
+ (parse-shell-command ["a" "b" "c" :x 1 :y 2]))))
+
+(deftest test-default-options
+ (let [config-in {:repl-launch-commands {:a ["a"]}
+ :repl-listen-port 10000
+ :test-commands {:b ["b"]}
+ :crossover-path "c"
+ :crossover-jar true
+ :crossovers ["d" "e"]
+ :builds
+ '({:source-path "f"
+ :jar true
+ :notify-command ["g"]
+ :warn-on-undeclared false
+ :compiler
+ {:output-to "h"
+ :output-dir "i"
+ :optimizations :advanced
+ :pretty-print false}})}]
+ ; Ensure that none of our custom settings are overwritten by defaults.
+ (is (= config-in (set-default-options config-in)))
+ ; Ensure that if any custom setting is missing, a default is provided.
+ (doseq [option (keys config-in)]
+ (is (contains? (set-default-options (dissoc config-in option)) option)))
+ (let [build (first (:builds config-in))]
+ (doseq [build-option (keys build)]
+ (let [defaulted (set-default-options
+ (assoc config-in :builds
+ (list (dissoc build build-option))))]
+ (is (contains? (first (:builds defaulted)) build-option))))
+ (let [compiler (:compiler build)]
+ (doseq [compiler-option (keys compiler)]
+ (let [defaulted (set-default-options
+ (assoc config-in :builds
+ (list
+ (assoc build :compiler
+ (dissoc compiler :compiler-option)))))]
+ (is (contains? (:compiler (first (:builds defaulted))) compiler-option))))))))

0 comments on commit efeeafa

Please sign in to comment.