Permalink
Browse files

test for test command aborting on invalid namespace

move abort-msg to helper and ensure it only catches main/abort
  • Loading branch information...
1 parent d5ec46e commit 2e349c61e3ffa4b81d941faad1094b19006fa9d2 @cldwalker cldwalker committed Feb 11, 2013
Showing with 21 additions and 9 deletions.
  1. +12 −0 test/leiningen/test/helper.clj
  2. +2 −8 test/leiningen/test/new/templates.clj
  3. +7 −1 test/leiningen/test/test.clj
@@ -31,6 +31,18 @@
(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?
(defn delete-file-recursively
"Delete file f. If it's a directory, recursively delete all its contents.
@@ -1,6 +1,7 @@
(ns leiningen.test.new.templates
(:use clojure.test
- leiningen.new.templates))
+ leiningen.new.templates)
+ (:require [leiningen.test.helper :refer [abort-msg]]))
(deftest project-names
(is (= (project-name "org.example/foo.bar") "foo.bar"))
@@ -17,13 +18,6 @@
(deftest paths
(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
(is (= (abort-msg (renderer "my-template") "boom" {})
"Template resource 'leiningen/new/my_template/boom' not found.\n"))
@@ -2,7 +2,7 @@
(:refer-clojure :exclude [test])
(:use [clojure.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]))
(use-fixtures :each
@@ -53,6 +53,12 @@
(test sample-no-aot-project "selectors")
(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))
(defmethod clojure.test/report :begin-test-ns [_]

0 comments on commit 2e349c6

Please sign in to comment.