diff options
author | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-07 14:22:56 -0400 |
---|---|---|
committer | Stuart Halloway <stu@thinkrelevance.com> | 2010-04-16 15:35:50 -0400 |
commit | 86eab09c6c16c66a6add465a1d8f964764c612ad (patch) | |
tree | aa3b666021c893a3662135521b7297f95801959d | |
parent | b8e04fdc8f72157f3a6f825247ecfc97c86aff91 (diff) |
added build step to compile things for test purposes, initial tests
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r-- | build.xml | 14 | ||||
-rw-r--r-- | test/clojure/test_clojure/protocols.clj | 40 | ||||
-rw-r--r-- | test/clojure/test_clojure/protocols/examples.clj | 10 |
3 files changed, 64 insertions, 0 deletions
@@ -13,6 +13,7 @@ <property name="jsrc" location="${src}/jvm"/> <property name="cljsrc" location="${src}/clj"/> <property name="build" location="classes"/> + <property name="test-classes" location="test-classes"/> <property name="dist" location="dist"/> <!-- version related properties --> @@ -105,6 +106,17 @@ </java> </target> + <target name="compile-tests" + description="Compile the subset of tests that require compilation."> + <mkdir dir="${test-classes}"/> + <java classname="clojure.lang.Compile" + classpath="${test-classes}:${test}:${build}:${cljsrc}" + failonerror="true"> + <sysproperty key="clojure.compile.path" value="${test-classes}"/> + <arg value="clojure.test-clojure.protocols.examples"/> + </java> + </target> + <target name="clojure" depends="compile-clojure" description="Create clojure jar file."> <jar jarfile="${clojure_jar}" basedir="${build}"> @@ -125,6 +137,7 @@ <!-- depends="clojure"> --> <java classname="clojure.main" failonerror="true"> <classpath> + <path location="${test-classes}"/> <path location="${test}"/> <path location="${clojure_jar}"/> </classpath> @@ -167,6 +180,7 @@ <target name="clean" description="Remove autogenerated files and directories."> <delete dir="${build}"/> + <delete dir="${test-classes}"/> <delete dir="${dist}"/> <delete file="pom.xml"/> </target> diff --git a/test/clojure/test_clojure/protocols.clj b/test/clojure/test_clojure/protocols.clj new file mode 100644 index 00000000..8b5adc71 --- /dev/null +++ b/test/clojure/test_clojure/protocols.clj @@ -0,0 +1,40 @@ +; Copyright (c) Rich Hickey. All rights reserved. +; The use and distribution terms for this software are covered by the +; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php) +; which can be found in the file epl-v10.html at the root of this distribution. +; By using this software in any fashion, you are agreeing to be bound by +; the terms of this license. +; You must not remove this notice, or any other, from this software. + +; Author: Stuart Halloway + +(ns clojure.test-clojure.protocols + (:use clojure.test clojure.test-clojure.protocols.examples)) + +(defn method-names + "return sorted list of method names on a class" + [c] + (->> (.getMethods c) + (map #(.getName %)) + (sort))) + +(deftest protocols-test + (testing "protocol fns throw IllegalArgumentException if no impl matches" + (is (thrown-with-msg? + IllegalArgumentException + #"No implementation of method: :foo of protocol: #'clojure.test-clojure.protocols.examples/AnExampleProtocol found for class: nil" + (foo nil)))) + (testing "protocols generate a corresponding interface using _ instead of - for method names" + (is (= ["bar" "baz" "baz" "foo" "with_quux"] (method-names clojure.test_clojure.protocols.examples.AnExampleProtocol)))) + (testing "protocol will work with instances of its interface (use for interop, not in Clojure!)" + (let [obj (proxy [clojure.test_clojure.protocols.examples.AnExampleProtocol] [] + (foo [] "foo!"))] + (is (= "foo!" (.foo obj)) "call through interface") + (is (= "foo!" (foo obj)) "call through protocol"))) + (testing "you can implement just part of a protocol if you want" + (let [obj (reify AnExampleProtocol + (baz [a b] "two-arg baz!"))] + (is (= "two-arg baz!" (baz obj nil))) + (is (thrown? AbstractMethodError (baz obj)))))) + + diff --git a/test/clojure/test_clojure/protocols/examples.clj b/test/clojure/test_clojure/protocols/examples.clj new file mode 100644 index 00000000..8104a26e --- /dev/null +++ b/test/clojure/test_clojure/protocols/examples.clj @@ -0,0 +1,10 @@ +(ns clojure.test-clojure.protocols.examples) + +(defprotocol AnExampleProtocol + "example protocol used by clojure tests" + + (foo [a] "method with one arg") + (bar [a b] "method with two args") + (baz [a] [a b] "method with multiple arities") + (with-quux [a] "method name with a hyphen")) + |