Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Tighten up existing tests for recur across try boundaries.

Some were syntactically incorrect (e.g. loop [x]) and were detecting
exceptions thrown that weren't from the compiler.

Tests for code that should compile cleanly was ignoring the value
returned and wrapping them in another try unnecessarily.  I simply
changed them to check that the eval of the expression returned the
only correct value that should ever be produced.

All updated tests pass.

Signed-off-by: Stuart Halloway <>
  • Loading branch information...
commit 7c9ff0a80c5b716ed92de6c5d6a1146b9a6ae6b1 1 parent 085712b
@jafingerhut jafingerhut authored stuarthalloway committed
Showing with 20 additions and 16 deletions.
  1. +20 −16 test/clojure/test_clojure/compilation.clj
36 test/clojure/test_clojure/compilation.clj
@@ -10,6 +10,7 @@
(ns clojure.test-clojure.compilation
+ (:import (clojure.lang Compiler Compiler$CompilerException))
(:use clojure.test
[clojure.test-helper :only (should-not-reflect should-print-err-message)]))
@@ -54,26 +55,29 @@
(deftest test-no-recur-across-try
(testing "don't recur to function from inside try"
- (is (thrown? Exception (eval '(fn [x] (try (recur 1)))))))
+ (is (thrown? Compiler$CompilerException
+ (eval '(fn [x] (try (recur 1)))))))
(testing "don't recur to loop from inside try"
- (is (thrown? Exception (eval '(loop [x] (try (recur 1)))))))
+ (is (thrown? Compiler$CompilerException
+ (eval '(loop [x 5]
+ (try (recur 1)))))))
(testing "don't get confused about what the recur is targeting"
- (is (thrown? Exception (eval '(loop [x] (try (fn [x]) (recur 1)))))))
- (testing "don't allow recur accross binding"
- (is (thrown? Exception (eval '(fn [x] (binding [+ *] (recur 1)))))))
+ (is (thrown? Compiler$CompilerException
+ (eval '(loop [x 5]
+ (try (fn [x]) (recur 1)))))))
+ (testing "don't allow recur across binding"
+ (is (thrown? Compiler$CompilerException
+ (eval '(fn [x] (binding [+ *] (recur 1)))))))
(testing "allow loop/recur inside try"
- (is (try
- (eval '(try (loop [x 3] (if (zero? x) x (recur (dec x))))))
- (catch Exception _))))
+ (is (= 0 (eval '(try (loop [x 3]
+ (if (zero? x) x (recur (dec x)))))))))
(testing "allow fn/recur inside try"
- (is (try
- (eval '(try
- ((fn [x]
- (if (zero? x)
- x
- (recur (dec x))))
- 3)))
- (catch Exception _)))))
+ (is (= 0 (eval '(try
+ ((fn [x]
+ (if (zero? x)
+ x
+ (recur (dec x))))
+ 3)))))))
;; disabled until build box can call java from mvn
#_(deftest test-numeric-dispatch

0 comments on commit 7c9ff0a

Please sign in to comment.
Something went wrong with that request. Please try again.