Skip to content

Commit

Permalink
test for test command aborting on invalid namespace
Browse files Browse the repository at this point in the history
move abort-msg to helper and ensure it only catches main/abort
  • Loading branch information
cldwalker committed Feb 12, 2013
1 parent d5ec46e commit 2e349c6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
12 changes: 12 additions & 0 deletions test/leiningen/test/helper.clj
Expand Up @@ -31,6 +31,18 @@


(def overlapped-sourcepaths-project (read-test-project "overlapped-sourcepaths")) (def overlapped-sourcepaths-project (read-test-project "overlapped-sourcepaths"))


(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)))))))

;; grumble, grumble; why didn't this make it into clojure.java.io? ;; grumble, grumble; why didn't this make it into clojure.java.io?
(defn delete-file-recursively (defn delete-file-recursively
"Delete file f. If it's a directory, recursively delete all its contents. "Delete file f. If it's a directory, recursively delete all its contents.
Expand Down
10 changes: 2 additions & 8 deletions test/leiningen/test/new/templates.clj
@@ -1,6 +1,7 @@
(ns leiningen.test.new.templates (ns leiningen.test.new.templates
(:use clojure.test (:use clojure.test
leiningen.new.templates)) leiningen.new.templates)
(:require [leiningen.test.helper :refer [abort-msg]]))


(deftest project-names (deftest project-names
(is (= (project-name "org.example/foo.bar") "foo.bar")) (is (= (project-name "org.example/foo.bar") "foo.bar"))
Expand All @@ -17,13 +18,6 @@
(deftest paths (deftest paths
(is (= (name-to-path "foo-bar.baz") "foo_bar/baz"))) (is (= (name-to-path "foo-bar.baz") "foo_bar/baz")))


(defn- abort-msg [f & args]
(with-out-str
(binding [*err* *out*]
(try
(apply f args)
(catch clojure.lang.ExceptionInfo e)))))

(deftest renderers (deftest renderers
(is (= (abort-msg (renderer "my-template") "boom" {}) (is (= (abort-msg (renderer "my-template") "boom" {})
"Template resource 'leiningen/new/my_template/boom' not found.\n")) "Template resource 'leiningen/new/my_template/boom' not found.\n"))
Expand Down
8 changes: 7 additions & 1 deletion test/leiningen/test/test.clj
Expand Up @@ -2,7 +2,7 @@
(:refer-clojure :exclude [test]) (:refer-clojure :exclude [test])
(:use [clojure.test] (:use [clojure.test]
[leiningen.test] [leiningen.test]
[leiningen.test.helper :only [tmp-dir sample-no-aot-project]]) [leiningen.test.helper :only [tmp-dir sample-no-aot-project abort-msg]])
(:require [clojure.java.io :as io])) (:require [clojure.java.io :as io]))


(use-fixtures :each (use-fixtures :each
Expand Down Expand Up @@ -53,6 +53,12 @@
(test sample-no-aot-project "selectors") (test sample-no-aot-project "selectors")
(is (= (ran?) #{:regular :not-custom :int2}))) (is (= (ran?) #{:regular :not-custom :int2})))


(deftest test-invalid-namespace-argument
(is (.contains
(abort-msg
test sample-no-aot-project "boom")
"java.io.FileNotFoundException: Could not locate")))

(def called? (atom false)) (def called? (atom false))


(defmethod clojure.test/report :begin-test-ns [_] (defmethod clojure.test/report :begin-test-ns [_]
Expand Down

0 comments on commit 2e349c6

Please sign in to comment.