Resolve failing test introduced by *warn*.

Also move abort-msg up to leiningen core and call it from the leiningen
test helpers package instead.
This commit is contained in:
Jean Niklas L'orange 2013-02-18 00:07:53 +01:00
parent 55dd6b3fd4
commit 6aed6d377f
3 changed files with 41 additions and 32 deletions

View file

@ -0,0 +1,13 @@
(ns leiningen.core.test.helper)
(defn abort-msg
"Catches main/abort thrown by calling f on its args and returns its error
message."
[f & args]
(with-out-str
(binding [*err* *out*]
(try
(apply f args)
(catch clojure.lang.ExceptionInfo e
(when-not (= "Suppressed exit" (.getMessage e))
(throw e)))))))

View file

@ -4,6 +4,7 @@
[leiningen.core.project :as project])
(:require [leiningen.core.user :as user]
[leiningen.core.classpath :as classpath]
[leiningen.core.test.helper :refer [abort-msg]]
[clojure.java.io :as io]))
(use-fixtures :once
@ -398,40 +399,40 @@
(if (System/getenv "LEIN_SUPPRESS_USER_LEVEL_REPO_WARNINGS")
(testing "no output with suppression"
(is (= ""
(with-out-str
(#'project/warn-user-repos
{:user {:repositories
{"central" {:url "http://repo1.maven.org/maven2/"
:snapshots false}
"clojars" {:url "https://clojars.org/repo/"}}}})))))
(abort-msg
#'project/warn-user-repos
{:user {:repositories
{"central" {:url "http://repo1.maven.org/maven2/"
:snapshots false}
"clojars" {:url "https://clojars.org/repo/"}}}}))))
(testing "with no suppression,"
(testing "no warning without user level repo"
(is (= "" (with-out-str (#'project/warn-user-repos {})))
(is (= "" (abort-msg #'project/warn-user-repos {}))
"No warning in base case"))
(testing "Warning with user level repo"
(is (re-find
#"WARNING: :repositories .* [:user].*"
(with-out-str
(#'project/warn-user-repos
{:user {:repositories
{"central" {:url "http://repo1.maven.org/maven2/"
:snapshots false}
"clojars" {:url "https://clojars.org/repo/"}}}})))))
(abort-msg
#'project/warn-user-repos
{:user {:repositories
{"central" {:url "http://repo1.maven.org/maven2/"
:snapshots false}
"clojars" {:url "https://clojars.org/repo/"}}}}))))
(testing "Warning with user level repo"
(is (re-find
#"WARNING: :repositories .* [:user].*"
(with-out-str
(#'project/warn-user-repos
{:user {:repositories
{"central" "http://repo1.maven.org/maven2/"
"clojars" "https://clojars.org/repo/"}}})))))
(abort-msg
#'project/warn-user-repos
{:user {:repositories
{"central" "http://repo1.maven.org/maven2/"
"clojars" "https://clojars.org/repo/"}}}))))
(testing "Warning with user level repo"
(is (re-find
#"WARNING: :repositories .* [:user].*"
(with-out-str
(#'project/warn-user-repos
{:user
{:repositories
[["central" {:url "http://repo1.maven.org/maven2/"
:snapshots false}]
["clojars" {:url "https://clojars.org/repo/"}]]}}))))))))
(abort-msg
#'project/warn-user-repos
{:user
{:repositories
[["central" {:url "http://repo1.maven.org/maven2/"
:snapshots false}]
["clojars" {:url "https://clojars.org/repo/"}]]}})))))))

View file

@ -1,6 +1,7 @@
(ns leiningen.test.helper
(:require [leiningen.core.project :as project]
[leiningen.core.user :as user]
[leiningen.core.test.helper :as helper]
[clojure.java.io :as io]))
;; TODO: fix
@ -35,13 +36,7 @@
"Catches main/abort thrown by calling f on its args and returns its error
message."
[f & args]
(with-out-str
(binding [*err* *out*]
(try
(apply f args)
(catch clojure.lang.ExceptionInfo e
(when-not (= "Suppressed exit" (.getMessage e))
(throw e)))))))
(apply helper/abort-msg f args))
;; grumble, grumble; why didn't this make it into clojure.java.io?
(defn delete-file-recursively