diff options
-rw-r--r-- | build.xml | 7 | ||||
-rw-r--r-- | src/clj/clojure/core.clj | 64 | ||||
-rw-r--r-- | src/jvm/clojure/lang/Keyword.java | 8 | ||||
-rw-r--r-- | test/clojure/test_clojure.clj | 20 | ||||
-rw-r--r-- | test/clojure/test_clojure/predicates.clj | 2 | ||||
-rw-r--r-- | test/clojure/test_clojure/reader.clj | 2 | ||||
-rw-r--r-- | test/clojure/test_clojure/test.clj | 6 | ||||
-rw-r--r-- | test/clojure/test_clojure/test_fixtures.clj | 2 | ||||
-rw-r--r-- | test/clojure/test_clojure/vars.clj | 4 |
9 files changed, 80 insertions, 35 deletions
@@ -85,7 +85,8 @@ <target name="compile-clojure" depends="compile-java" description="Compile Clojure sources."> <java classname="clojure.lang.Compile" - classpath="${build}:${cljsrc}"> + classpath="${build}:${cljsrc}" + failonerror="true"> <sysproperty key="clojure.compile.path" value="${build}"/> <arg value="clojure.core"/> <arg value="clojure.main"/> @@ -119,13 +120,13 @@ <target name="test" description="Run clojure tests"> <!-- depends="clojure"> --> - <java classname="clojure.main"> + <java classname="clojure.main" failonerror="true"> <classpath> <path location="${test}"/> <path location="${clojure_jar}"/> </classpath> <arg value="-e"/> - <arg value="(require '(clojure [test-clojure :as main])) (main/run)"/> + <arg value="(require '(clojure [test-clojure :as main])) (main/run-ant)"/> </java> </target> diff --git a/src/clj/clojure/core.clj b/src/clj/clojure/core.clj index ef8b40e2..aaf5eda4 100644 --- a/src/clj/clojure/core.clj +++ b/src/clj/clojure/core.clj @@ -1862,27 +1862,49 @@ (if-not exprs [true `(do ~@body)] (let [k (first exprs) - v (second exprs) - seqsym (when-not (keyword? k) (gensym)) - recform (if (keyword? k) recform `(recur (next ~seqsym))) - steppair (step recform (nnext exprs)) - needrec (steppair 0) - subform (steppair 1)] - (cond - (= k :let) [needrec `(let ~v ~subform)] - (= k :while) [false `(when ~v - ~subform - ~@(when needrec [recform]))] - (= k :when) [false `(if ~v - (do - ~subform - ~@(when needrec [recform])) - ~recform)] - :else [true `(loop [~seqsym (seq ~v)] - (when ~seqsym - (let [~k (first ~seqsym)] - ~subform - ~@(when needrec [recform]))))]))))] + v (second exprs)] + (if (keyword? k) + (let [steppair (step recform (nnext exprs)) + needrec (steppair 0) + subform (steppair 1)] + (cond + (= k :let) [needrec `(let ~v ~subform)] + (= k :while) [false `(when ~v + ~subform + ~@(when needrec [recform]))] + (= k :when) [false `(if ~v + (do + ~subform + ~@(when needrec [recform])) + ~recform)])) + (let [seq- (gensym "seq_") + chunk- (with-meta (gensym "chunk_") + {:tag 'clojure.lang.IChunk}) + count- (gensym "count_") + i- (gensym "i_") + recform `(recur (next ~seq-) nil (int 0) (int 0)) + steppair (step recform (nnext exprs)) + needrec (steppair 0) + subform (steppair 1) + recform-chunk + `(recur ~seq- ~chunk- ~count- (unchecked-inc ~i-)) + steppair-chunk (step recform-chunk (nnext exprs)) + subform-chunk (steppair-chunk 1)] + [true + `(loop [~seq- (seq ~v), ~chunk- nil, + ~count- (int 0), ~i- (int 0)] + (if (< ~i- ~count-) + (let [~k (.nth ~chunk- ~i-)] + ~subform-chunk + ~@(when needrec [recform-chunk])) + (when ~seq- + (if (chunked-seq? ~seq-) + (let [c# (chunk-first ~seq-)] + (recur (seq (chunk-rest ~seq-)) c# + (int (count c#)) (int 0))) + (let [~k (first ~seq-)] + ~subform + ~@(when needrec [recform]))))))])))))] (nth (step nil (seq seq-exprs)) 1))) (defn dorun diff --git a/src/jvm/clojure/lang/Keyword.java b/src/jvm/clojure/lang/Keyword.java index 9b5aea9a..890f14d7 100644 --- a/src/jvm/clojure/lang/Keyword.java +++ b/src/jvm/clojure/lang/Keyword.java @@ -12,10 +12,12 @@ package clojure.lang; +import java.io.ObjectStreamException; +import java.io.Serializable; import java.util.concurrent.ConcurrentHashMap; -public class Keyword implements IFn, Comparable, Named{ +public class Keyword implements IFn, Comparable, Named, Serializable { private static ConcurrentHashMap<Symbol, Keyword> table = new ConcurrentHashMap(); public final Symbol sym; @@ -76,6 +78,10 @@ public String getName(){ return sym.getName(); } +private Object readResolve() throws ObjectStreamException{ + return intern(sym); +} + /** * Indexer implements IFn for attr access * diff --git a/test/clojure/test_clojure.clj b/test/clojure/test_clojure.clj index 8b1e16ae..ac264e0f 100644 --- a/test/clojure/test_clojure.clj +++ b/test/clojure/test_clojure.clj @@ -15,7 +15,7 @@ ;; Created 22 October 2008 (ns clojure.test-clojure - (:use [clojure.test :only (run-tests)]) + (:require [clojure.test :as t]) (:gen-class)) (def test-names @@ -59,7 +59,23 @@ [] (println "Loading tests...") (apply require :reload-all test-namespaces) - (apply run-tests test-namespaces)) + (apply t/run-tests test-namespaces)) + +(defn run-ant + "Runs all defined tests, prints report to *err*, throw if failures. This works well for running in an ant java task." + [] + (let [rpt t/report] + (binding [;; binding to *err* because, in ant, when the test target + ;; runs after compile-clojure, *out* doesn't print anything + *out* *err* + t/*test-out* *err* + t/report (fn report [m] + (if (= :summary (:type m)) + (do (rpt m) + (if (or (pos? (:fail m)) (pos? (:error m))) + (throw (new Exception (str (:fail m) " failures, " (:error m) " errors."))))) + (rpt m)))] + (run)))) (defn -main "Run all defined tests from the command line" diff --git a/test/clojure/test_clojure/predicates.clj b/test/clojure/test_clojure/predicates.clj index 8e68c757..2923ef3d 100644 --- a/test/clojure/test_clojure/predicates.clj +++ b/test/clojure/test_clojure/predicates.clj @@ -137,6 +137,6 @@ ;; http://groups.google.com/group/clojure/browse_thread/thread/537761a06edb4b06/bfd4f0705b746a38 ;; (deftest test-string?-more - (are (not (string? _)) + (are [x] (not (string? x)) (new java.lang.StringBuilder "abc") (new java.lang.StringBuffer "xyz"))) diff --git a/test/clojure/test_clojure/reader.clj b/test/clojure/test_clojure/reader.clj index 20b1bfac..223e9d75 100644 --- a/test/clojure/test_clojure/reader.clj +++ b/test/clojure/test_clojure/reader.clj @@ -297,7 +297,7 @@ ;; Unquote-splicing (~@) (deftest t-Syntax-quote - (are (= _1 _2) + (are [x y] (= x y) `() () ; was NPE before SVN r1337 )) diff --git a/test/clojure/test_clojure/test.clj b/test/clojure/test_clojure/test.clj index 38cf802f..aa1fea2d 100644 --- a/test/clojure/test_clojure/test.clj +++ b/test/clojure/test_clojure/test.clj @@ -6,7 +6,7 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. -;;; test_contrib/test_is.clj: unit tests for test_is.clj +;;; test_clojure/test.clj: unit tests for test.clj ;; by Stuart Sierra ;; January 16, 2009 @@ -83,7 +83,7 @@ (is (does-not-exist) "Should error")) -;; Here, we create an alternate version of test-is/report, that +;; Here, we create an alternate version of test/report, that ;; compares the event with the message, then calls the original ;; 'report' with modified arguments. @@ -105,7 +105,7 @@ (original-report {:type :fail, :message (str msg " but got " event) :expected expected, :actual actual})))) -;; test-ns-hook will be used by test-is/test-ns to run tests in this +;; test-ns-hook will be used by test/test-ns to run tests in this ;; namespace. (defn test-ns-hook [] (binding [original-report report diff --git a/test/clojure/test_clojure/test_fixtures.clj b/test/clojure/test_clojure/test_fixtures.clj index 707dcc38..9a85b58b 100644 --- a/test/clojure/test_clojure/test_fixtures.clj +++ b/test/clojure/test_clojure/test_fixtures.clj @@ -6,7 +6,7 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. ; -;;; test_is_fixtures.clj: unit tests for fixtures in test_is.clj +;;; test_fixtures.clj: unit tests for fixtures in test.clj ;; by Stuart Sierra ;; March 28, 2009 diff --git a/test/clojure/test_clojure/vars.clj b/test/clojure/test_clojure/vars.clj index cbdc72d9..e83c88c2 100644 --- a/test/clojure/test_clojure/vars.clj +++ b/test/clojure/test_clojure/vars.clj @@ -6,7 +6,7 @@ ; the terms of this license. ; You must not remove this notice, or any other, from this software. -; Author: Frantisek Sodomka +; Author: Frantisek Sodomka, Stephen C. Gilardi (ns clojure.test-clojure.vars @@ -21,7 +21,7 @@ (def a) (deftest test-binding - (are [_1 _2] (= _1 _2) + (are [x y] (= x y) (eval `(binding [a 4] a)) 4 ; regression in Clojure SVN r1370 )) |