From bb681d83d6220a13b4c403b8f09482357ae113fa Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Tue, 21 Aug 2012 23:16:59 -0400 Subject: [PATCH 1/3] remove tests that cannot be loaded and prevent walk of test directory --- test/clojure/test_clojure/load.clj | 38 ---------------------------- test/clojure/test_clojure/load/cyclic0.clj | 12 --------- test/clojure/test_clojure/load/cyclic1.clj | 12 --------- test/clojure/test_clojure/load/cyclic2.clj | 12 --------- test/clojure/test_clojure/load/cyclic3.clj | 12 --------- test/clojure/test_clojure/load/cyclic4.clj | 12 --------- test/clojure/test_clojure/load/cyclic5.clj | 12 --------- test/clojure/test_clojure/load/cyclic6.clj | 12 --------- test/clojure/test_clojure/load/invalid.clj | 11 -------- 9 files changed, 0 insertions(+), 133 deletions(-) delete mode 100644 test/clojure/test_clojure/load.clj delete mode 100644 test/clojure/test_clojure/load/cyclic0.clj delete mode 100644 test/clojure/test_clojure/load/cyclic1.clj delete mode 100644 test/clojure/test_clojure/load/cyclic2.clj delete mode 100644 test/clojure/test_clojure/load/cyclic3.clj delete mode 100644 test/clojure/test_clojure/load/cyclic4.clj delete mode 100644 test/clojure/test_clojure/load/cyclic5.clj delete mode 100644 test/clojure/test_clojure/load/cyclic6.clj delete mode 100644 test/clojure/test_clojure/load/invalid.clj diff --git a/test/clojure/test_clojure/load.clj b/test/clojure/test_clojure/load.clj deleted file mode 100644 index bb9d514..0000000 --- a/test/clojure/test_clojure/load.clj +++ /dev/null @@ -1,38 +0,0 @@ -; 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. - -(ns clojure.test-clojure.load - (:use clojure.test)) - -(deftest test-load - (testing "Should ignore self-loads without comment" - (is (nil? (require 'clojure.test-clojure.load.cyclic0)))) - (testing "Should reject cyclic dependencies" - (testing "a->b->a" - (is (thrown-with-msg? Exception #".*Cyclic load dependency.*" - (require 'clojure.test-clojure.load.cyclic1)))) - (testing "a->b->c->d->b" - (is (thrown-with-msg? Exception #".*Cyclic load dependency.*" - (require 'clojure.test-clojure.load.cyclic3)))))) - -(deftest test-load-lib - (testing "Shouldn't leak failed namespace" - (try (require 'clojure.test-clojure.load.invalid) - (catch Exception _)) - (is (nil? (find-ns 'clojure.test-clojure.load.invalid))))) - -(deftest test-require-refer - (try - (binding [*ns* *ns*] - (ns clojure.test-clojure.require-scratch - (:require [clojure.set :refer [difference]] - [clojure.walk :refer :all])) - (is (fn? (eval 'difference))) - (is (every? fn? (map eval '[postwalk-replace prewalk-replace walk])))) - (finally - (remove-ns 'clojure.test-clojure.require-scratch)))) \ No newline at end of file diff --git a/test/clojure/test_clojure/load/cyclic0.clj b/test/clojure/test_clojure/load/cyclic0.clj deleted file mode 100644 index 66a3cc1..0000000 --- a/test/clojure/test_clojure/load/cyclic0.clj +++ /dev/null @@ -1,12 +0,0 @@ -; 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: Stephen C. Gilardi - -(ns clojure.test-clojure.load.cyclic0 - (:require clojure.test-clojure.load.cyclic0)) diff --git a/test/clojure/test_clojure/load/cyclic1.clj b/test/clojure/test_clojure/load/cyclic1.clj deleted file mode 100644 index bf341f7..0000000 --- a/test/clojure/test_clojure/load/cyclic1.clj +++ /dev/null @@ -1,12 +0,0 @@ -; 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: Stephen C. Gilardi - -(ns clojure.test-clojure.load.cyclic1 - (:require clojure.test-clojure.load.cyclic2)) diff --git a/test/clojure/test_clojure/load/cyclic2.clj b/test/clojure/test_clojure/load/cyclic2.clj deleted file mode 100644 index 180a162..0000000 --- a/test/clojure/test_clojure/load/cyclic2.clj +++ /dev/null @@ -1,12 +0,0 @@ -; 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: Stephen C. Gilardi - -(ns clojure.test-clojure.load.cyclic2 - (:require clojure.test-clojure.load.cyclic1)) diff --git a/test/clojure/test_clojure/load/cyclic3.clj b/test/clojure/test_clojure/load/cyclic3.clj deleted file mode 100644 index 51a8e45..0000000 --- a/test/clojure/test_clojure/load/cyclic3.clj +++ /dev/null @@ -1,12 +0,0 @@ -; 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: Stephen C. Gilardi - -(ns clojure.test-clojure.load.cyclic3 - (:require clojure.test-clojure.load.cyclic4)) diff --git a/test/clojure/test_clojure/load/cyclic4.clj b/test/clojure/test_clojure/load/cyclic4.clj deleted file mode 100644 index d66a0fc..0000000 --- a/test/clojure/test_clojure/load/cyclic4.clj +++ /dev/null @@ -1,12 +0,0 @@ -; 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: Stephen C. Gilardi - -(ns clojure.test-clojure.load.cyclic4 - (:require clojure.test-clojure.load.cyclic5)) diff --git a/test/clojure/test_clojure/load/cyclic5.clj b/test/clojure/test_clojure/load/cyclic5.clj deleted file mode 100644 index e825b74..0000000 --- a/test/clojure/test_clojure/load/cyclic5.clj +++ /dev/null @@ -1,12 +0,0 @@ -; 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: Stephen C. Gilardi - -(ns clojure.test-clojure.load.cyclic5 - (:require clojure.test-clojure.load.cyclic6)) diff --git a/test/clojure/test_clojure/load/cyclic6.clj b/test/clojure/test_clojure/load/cyclic6.clj deleted file mode 100644 index d607f05..0000000 --- a/test/clojure/test_clojure/load/cyclic6.clj +++ /dev/null @@ -1,12 +0,0 @@ -; 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: Stephen C. Gilardi - -(ns clojure.test-clojure.load.cyclic6 - (:require clojure.test-clojure.load.cyclic4)) diff --git a/test/clojure/test_clojure/load/invalid.clj b/test/clojure/test_clojure/load/invalid.clj deleted file mode 100644 index fff9901..0000000 --- a/test/clojure/test_clojure/load/invalid.clj +++ /dev/null @@ -1,11 +0,0 @@ -; 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. - -(ns clojure.test-clojure.load.invalid) - -(this isn't valid code) -- 1.7.3.5 From 7eabf2595a97f109f09ff32596b9b4ed007fdeff Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Tue, 21 Aug 2012 23:17:35 -0400 Subject: [PATCH 2/3] add test.generative as a test dependency --- antsetup.sh | 1 + build.xml | 2 +- pom.xml | 13 +++++++++++++ 3 files changed, 15 insertions(+), 1 deletions(-) diff --git a/antsetup.sh b/antsetup.sh index 365e460..0cce8a9 100755 --- a/antsetup.sh +++ b/antsetup.sh @@ -3,5 +3,6 @@ mvn -q dependency:build-classpath -Dmdep.outputFile=maven-classpath cat <maven-classpath.properties maven.compile.classpath=`cat maven-classpath` +maven.test.classpath=`cat maven-classpath` EOF echo "Wrote maven-classpath.properties for standalone ant use" diff --git a/build.xml b/build.xml index a1638b7..485174b 100644 --- a/build.xml +++ b/build.xml @@ -102,7 +102,7 @@ unless="maven.test.skip"> - + diff --git a/pom.xml b/pom.xml index ca3d9e6..1b9d2e1 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,18 @@ 1.7.0 provided + + org.clojure + test.generative + 0.1.5 + test + + + org.clojure + clojure + + + @@ -94,6 +106,7 @@ + -- 1.7.3.5 From 665f424032e803a734edfab93b1f17b7ad8ca742 Mon Sep 17 00:00:00 2001 From: Stuart Halloway Date: Tue, 21 Aug 2012 23:18:34 -0400 Subject: [PATCH 3/3] use test.generative's runner, add a few generative tests --- src/script/run_tests.clj | 63 +------------------------- test/clojure/test_clojure/numbers.clj | 78 ++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 62 deletions(-) diff --git a/src/script/run_tests.clj b/src/script/run_tests.clj index 8742c7d..8a6f83e 100755 --- a/src/script/run_tests.clj +++ b/src/script/run_tests.clj @@ -1,62 +1,3 @@ -(ns clojure.test-clojure (:require clojure.test)) +(require '[clojure.test.generative.runner :as runner]) +(runner/-main "test") -(def test-namespaces '[ -clojure.test-clojure.agents -clojure.test-clojure.annotations -clojure.test-clojure.atoms -clojure.test-clojure.clojure-set -clojure.test-clojure.clojure-walk -clojure.test-clojure.clojure-xml -clojure.test-clojure.clojure-zip -clojure.test-clojure.compilation -clojure.test-clojure.control -clojure.test-clojure.data -clojure.test-clojure.data-structures -clojure.test-clojure.def -clojure.test-clojure.errors -clojure.test-clojure.evaluation -clojure.test-clojure.for -clojure.test-clojure.genclass.examples -clojure.test-clojure.genclass -clojure.test-clojure.java.io -clojure.test-clojure.java.javadoc -clojure.test-clojure.java.shell -clojure.test-clojure.java-interop -clojure.test-clojure.keywords -clojure.test-clojure.load -clojure.test-clojure.logic -clojure.test-clojure.macros -clojure.test-clojure.main -clojure.test-clojure.metadata -clojure.test-clojure.multimethods -clojure.test-clojure.ns-libs -clojure.test-clojure.numbers -clojure.test-clojure.other-functions -clojure.test-clojure.parallel -clojure.test-clojure.pprint -clojure.test-clojure.predicates -clojure.test-clojure.printer -clojure.test-clojure.protocols -clojure.test-clojure.protocols.hash-collisions -clojure.test-clojure.reader -clojure.test-clojure.reducers -clojure.test-clojure.reflect -clojure.test-clojure.refs -clojure.test-clojure.repl -clojure.test-clojure.rt -clojure.test-clojure.sequences -clojure.test-clojure.serialization -clojure.test-clojure.special -clojure.test-clojure.string -clojure.test-clojure.test -clojure.test-clojure.test-fixtures -clojure.test-clojure.transients -clojure.test-clojure.try-catch -clojure.test-clojure.vars -clojure.test-clojure.vectors -]) - -(apply require test-namespaces) - -(let [results (apply clojure.test/run-tests test-namespaces)] - (System/exit (+ (:error results) (:fail results)))) diff --git a/test/clojure/test_clojure/numbers.clj b/test/clojure/test_clojure/numbers.clj index 12c5886..d00b3f4 100644 --- a/test/clojure/test_clojure/numbers.clj +++ b/test/clojure/test_clojure/numbers.clj @@ -13,7 +13,9 @@ (ns clojure.test-clojure.numbers (:use clojure.test - clojure.template)) + [clojure.test.generative :exclude (is)] + clojure.template) + (:require [clojure.test.generative.generators :as gen])) ; TODO: @@ -563,3 +565,77 @@ Math/pow overflows to Infinity." min max)))) +(defn integer + "Distribution of integers biased towards the small, but + including all longs." + [] + (gen/one-of #(gen/uniform -1 32) gen/byte gen/short gen/int gen/long)) + +(defn longable? + [n] + (try + (long n) + true + (catch Exception _))) + +(defspec integer-commutative-laws + (partial map identity) + [^{:tag `integer} a ^{:tag `integer} b] + (if (longable? (+' a b)) + (assert (= (+ a b) (+ b a) + (+' a b) (+' b a) + (unchecked-add a b) (unchecked-add b a))) + (assert (= (+' a b) (+' b a)))) + (if (longable? (*' a b)) + (assert (= (* a b) (* b a) + (*' a b) (*' b a) + (unchecked-multiply a b) (unchecked-multiply b a))) + (assert (= (*' a b) (*' b a))))) + +(defspec integer-associative-laws + (partial map identity) + [^{:tag `integer} a ^{:tag `integer} b ^{:tag `integer} c] + (if (every? longable? [(+' a b) (+' b c) (+' a b c)]) + (assert (= (+ (+ a b) c) (+ a (+ b c)) + (+' (+' a b) c) (+' a (+' b c)) + (unchecked-add (unchecked-add a b) c) (unchecked-add a (unchecked-add b c)))) + (assert (= (+' (+' a b) c) (+' a (+' b c)) + (+ (+ (bigint a) b) c) (+ a (+ (bigint b) c))))) + (if (every? longable? [(*' a b) (*' b c) (*' a b c)]) + (assert (= (* (* a b) c) (* a (* b c)) + (*' (*' a b) c) (*' a (*' b c)) + (unchecked-multiply (unchecked-multiply a b) c) (unchecked-multiply a (unchecked-multiply b c)))) + (assert (= (*' (*' a b) c) (*' a (*' b c)) + (* (* (bigint a) b) c) (* a (* (bigint b) c)))))) + +(defspec integer-distributive-laws + (partial map identity) + [^{:tag `integer} a ^{:tag `integer} b ^{:tag `integer} c] + (if (every? longable? [(*' a (+' b c)) (+' (*' a b) (*' a c)) + (*' a b) (*' a c) (+' b c)]) + (assert (= (* a (+ b c)) (+ (* a b) (* a c)) + (*' a (+' b c)) (+' (*' a b) (*' a c)) + (unchecked-multiply a (+' b c)) (+' (unchecked-multiply a b) (unchecked-multiply a c)))) + (assert (= (*' a (+' b c)) (+' (*' a b) (*' a c)) + (* a (+ (bigint b) c)) (+ (* (bigint a) b) (* (bigint a) c)))))) + +(defspec addition-undoes-subtraction + (partial map identity) + [^{:tag `integer} a ^{:tag `integer} b] + (if (longable? (-' a b)) + (assert (= a + (-> a (- b) (+ b)) + (-> a (unchecked-subtract b) (unchecked-add b))))) + (assert (= a + (-> a (-' b) (+' b))))) + +(defspec quotient-and-remainder + (fn [a b] (sort [a b])) + [^{:tag `integer} a ^{:tag `integer} b] + (when-not (zero? (second %)) + (let [[a d] % + q (quot a d) + r (rem a d)] + (assert (= a + (+ (* q d) r) + (unchecked-add (unchecked-multiply q d) r)))))) -- 1.7.3.5