Permalink
Browse files

Merge pull request #177 from naiquevin/helpful-exception

Make form-reader fail with a helpful exception
  • Loading branch information...
2 parents 9ff18cc + 2bf79a8 commit 49f63dbfed7c7453a2a8671028a4a7fbb5faaf0e @lvh lvh committed on GitHub May 23, 2017
@@ -123,8 +123,7 @@
(is (thrown? Exception (transaction-fn 1))))
(letfn [(covered [] (+ 2 3))
- (not-covered []
- {:and :not-tracked})
+ (not-covered [] {:and :not-tracked})
(not-covered [] ({:preimage :image} :preimage))]
(covered))
@@ -29,9 +29,12 @@
(throw (IllegalArgumentException. (str "Cannot find resource " resource)))))
(defn form-reader [ns-symbol]
- (rt/indexing-push-back-reader
- (java.io.PushbackReader.
- (resource-reader (resource-path ns-symbol)))))
+ (if-let [res-path (resource-path ns-symbol)]
+ (rt/indexing-push-back-reader
+ (java.io.PushbackReader.
+ (resource-reader res-path)))
+ (throw (ex-info (format "Resource path not found for namespace: %s" (name ns-symbol))
+ {:ns-symbol ns-symbol}))))
(defn forms [ns-symbol]
(let [src (form-reader ns-symbol)]
@@ -8,3 +8,10 @@
(t/is (= (sut/forms 'cloverage.sample.multibyte-sample)
'((ns cloverage.sample.multibyte-sample)
(def a "")))))
+
+(t/deftest form-reader-test
+ "Useful exception is thrown if resource-path not found for a ns"
+ (with-redefs [sut/resource-path (constantly nil)]
+ (t/is (thrown-with-msg? clojure.lang.ExceptionInfo
+ #"Resource path not found for namespace: foo.bar"
+ (sut/form-reader 'foo.bar)))))

0 comments on commit 49f63db

Please sign in to comment.