-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert all tests to use Midje (Issue #70).
- Loading branch information
Showing
15 changed files
with
233 additions
and
118 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
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,66 +1,84 @@ | ||
(ns leiningen.test.cljsbuild.config | ||
(:use | ||
leiningen.cljsbuild.config | ||
clojure.test)) | ||
midje.sweet)) | ||
|
||
(deftest test-backwards-compatibility | ||
(fact | ||
(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))))) | ||
(backwards-compat config-0-0-x-early) => config-backwards | ||
(backwards-compat config-0-0-x-late) => config-backwards)) | ||
|
||
(deftest test-ids | ||
(fact | ||
(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))))) | ||
(convert-builds-map config-vec) => config-vec | ||
(convert-builds-map config-map) => config-vec)) | ||
|
||
(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])))) | ||
(fact | ||
(parse-shell-command []) => {:shell []} | ||
(parse-shell-command ["a"]) => {:shell ["a"]} | ||
(parse-shell-command ["a" "b" "c" :x 1 :y 2]) => {:shell ["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)))))))) | ||
(def 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}})}) | ||
|
||
(fact "custom settings are not overwritten by defaults" | ||
(set-default-options config-in) => config-in) | ||
|
||
(fact "missing settings have defaults provided" | ||
(doseq [option (keys config-in)] | ||
(set-default-options (dissoc config-in option)) => (contains {option anything}))) | ||
|
||
(defn- get-build [config] | ||
(first (:builds config))) | ||
|
||
(defn- default-build-option [config build option] | ||
(set-default-options | ||
(assoc config :builds | ||
(list (dissoc build option))))) | ||
|
||
(fact "missing build settings have defaults provided" | ||
(let [build (get-build config-in)] | ||
(doseq [build-option (keys build)] | ||
(let [defaulted (default-build-option config-in build build-option)] | ||
(get-build defaulted) => (contains {build-option anything}))))) | ||
|
||
(defn- get-compiler [config] | ||
(:compiler (get-build config))) | ||
|
||
(defn- default-compiler-option [config compiler option] | ||
(set-default-options | ||
(assoc config :builds | ||
(list | ||
(assoc compiler :compiler | ||
(dissoc compiler option)))))) | ||
|
||
(fact "missing compiler settings have defaults provided" | ||
(let [compiler (:compiler (get-build config-in))] | ||
(doseq [compiler-option (keys compiler)] | ||
(let [defaulted (default-compiler-option config-in compiler compiler-option)] | ||
(get-compiler defaulted) => (contains {compiler-option anything}))))) | ||
|
||
(fact | ||
(extract-options {:cljsbuild config-in}) => config-in) |
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,12 +1,12 @@ | ||
(ns leiningen.test.cljsbuild.jar | ||
(:use | ||
leiningen.cljsbuild.jar | ||
clojure.test)) | ||
midje.sweet)) | ||
|
||
(deftest test-relative-path | ||
(is (= "a" (relative-path "/" "/a"))) | ||
(is (= "d/e" (relative-path "/a/b/c" "/a/b/c/d/e"))) | ||
(is (thrown? Exception (relative-path "" "a"))) | ||
(is (thrown? Exception (relative-path "/a/b/c" "/a/b")))) | ||
(fact | ||
(relative-path "/" "/a") => "a" | ||
(relative-path "/a/b/c" "/a/b/c/d/e") => "d/e" | ||
(relative-path "" "a") => (throws Exception) | ||
(relative-path "/a/b/c" "/a/b") => (throws Exception)) | ||
|
||
; TODO: More tests! |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(ns cljsbuild.test.clean | ||
(:use | ||
cljsbuild.clean | ||
midje.sweet) | ||
(:require | ||
[fs.core :as fs])) | ||
|
||
(fact | ||
(let [output-to "a" | ||
output-dir "b"] | ||
(cleanup-files {:output-to output-to :output-dir output-dir}) => nil | ||
(provided (fs/delete output-to) => nil :times 1) | ||
(provided (fs/delete-dir output-dir) => nil :times 1))) |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(ns cljsbuild.test.test | ||
(:use | ||
cljsbuild.test | ||
midje.sweet) | ||
(:require | ||
[cljsbuild.util :as util])) | ||
|
||
(fact | ||
(let [command-1 {:shell ["command1"]} | ||
command-2 {:shell ["command2"]} | ||
command-3 {:shell ["command3"]} | ||
commands [command-1 command-2 command-3]] | ||
(run-tests commands) => nil | ||
(provided (util/sh command-1) => 0 :times 1) | ||
(provided (util/sh command-2) => 0 :times 1) | ||
(provided (util/sh command-3) => 0 :times 1))) | ||
|
||
(fact | ||
(let [command-1 {:shell ["command1"]} | ||
command-2 {:shell ["command2"]} | ||
commands [command-1 command-2]] | ||
(run-tests commands) => (throws Exception) | ||
(provided (util/sh command-1) => 0 :times 1) | ||
(provided (util/sh command-2) => 1 :times 1))) |
Oops, something went wrong.