Skip to content

Commit

Permalink
Add guard rails for lein new newline handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
hypirion committed Mar 26, 2013
1 parent 4e77b0d commit dba0815
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions test/leiningen/test/new/templates.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,42 @@
(:use clojure.test
leiningen.new.templates)
(:require [leiningen.test.helper :refer [abort-msg]]
[leiningen.core.user :as user]
[clojure.java.io :as io]))

(defn- getenv [s]
(System/getenv s))

(deftest line-separators
(testing "that nothing changes when we're on unix systems"
(with-redefs [user/getprop (constantly "\n")]
(is (= (fix-line-separators "foo") "foo"))
(is (= (fix-line-separators "bar\nbaz") "bar\nbaz"))
(is (= (fix-line-separators "quux\n\n\nsycorax") "quux\n\n\nsycorax"))))

(testing "that newlines are correctly converted on '\\r\\n' systems"
(with-redefs [user/getprop (constantly "\r\n")]
(is (= (fix-line-separators "foo") "foo"))
(is (= (fix-line-separators "bar\nbaz") "bar\r\nbaz"))
(is (= (fix-line-separators "quux\n\n\nsycorax")
"quux\r\n\r\n\r\nsycorax"))))

(testing "that other bizarre systems get same treatment"
(with-redefs [user/getprop (constantly "\t\t")]
(is (= (fix-line-separators "foo") "foo"))
(is (= (fix-line-separators "bar\nbaz") "bar\t\tbaz"))
(is (= (fix-line-separators "quux\n\n\nsycorax")
"quux\t\t\t\t\t\tsycorax"))))

(testing "that one can override the normal system newline"
(with-redefs [user/getprop (constantly "\r\n")
user/getenv (fn [s] (if (= s "LEIN_NEW_UNIX_NEWLINES")
"y"
(getenv s)))]
(is (= (fix-line-separators "foo") "foo"))
(is (= (fix-line-separators "bar\nbaz") "bar\nbaz"))
(is (= (fix-line-separators "quux\n\n\nsycorax") "quux\n\n\nsycorax")))))

(deftest project-names
(is (= (project-name "org.example/foo.bar") "foo.bar"))
(is (= (project-name "example") "example"))
Expand Down

0 comments on commit dba0815

Please sign in to comment.