Permalink
Browse files

begin overhaul

  • Loading branch information...
1 parent 88e40f3 commit 992d3011502d7f6ff199dcfe1acf35bac77d3a11 @stuarthalloway stuarthalloway committed Aug 15, 2012
View
@@ -5,7 +5,6 @@ Test data generation and execution harness. Very early days.
This API will change. You have been warned.
-
Releases and Dependency Information
========================================
@@ -28,7 +27,6 @@ Latest stable release: 0.1.4
</dependency>
-
Example Usages
========================================
@@ -40,18 +38,13 @@ and a validator:
[^long a ^long b] ;; input spec
(assert (integer? %))) ;; 0 or more validator forms
-Given a var, namespace, or directory, you can run the tests for it:
-
- (test-vars #'integers-closed-over-addition)
- (test-namespaces 'clojure.test.generative-test)
- (test-dirs \"src/test/clojure\")
-
-Succesful test output includes :iterations, :msec, and the :var for
-each test run:
+To generate test data, see the fns in the generators namespace.
- {:iterations 44645, :msec 1429,
- :var #'clojure.test.generative-test/numbers-closed-over-addition}
+To integrate with clojure.test:
+ ;; somewhere in your test suite
+ (:require '[clojure.test.generative.clojure-test :as clojure-test])
+ (clojure-test/run-generative-tests)
Developer Information
========================================
@@ -69,6 +62,13 @@ Developer Information
Change Log
====================
+* Release 0.1.5 (in development)
+ * Can now run tests under clojure.test
+ * Tests produce data events that can be consumed by arbitrary reporting tools
+ * Example reporting integration with logback.
+ * Added `is` macro with more detailed reporting than `clojure.test/is`
+ * Removed collection based input generators. Input generators must be fns.
+ * Removed duplicate input check. Tests can be called multiple times with same input.
* Release 0.1.4 on 2012.01.03
* Initial version
File renamed without changes.
View
@@ -0,0 +1,7 @@
+#!/bin/bash
+# Note: First you must run mvn dependency:build-classpath -Dmdep.outputFile=bin/maven-classpath
+CLASSPATH=src/main/clojure:src/test/clojure:src/examples/clojure:`cat bin/maven-classpath`
+
+java -server -Xmx2GB -cp $CLASSPATH clojure.main "$@"
+
+
View
@@ -51,20 +51,21 @@
</repositories>
<properties>
- <clojure.version>1.3.0</clojure.version>
+ <clojure.version>1.4.0</clojure.version>
</properties>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
- <artifactId>clojure</artifactId>
- <version>1.3.0-beta1</version>
- </dependency>
- <dependency>
- <groupId>org.clojure</groupId>
<artifactId>tools.namespace</artifactId>
<version>0.1.1</version>
</dependency>
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <version>1.0.6</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
<build>
@@ -94,7 +95,8 @@
<artifactId>clojure-maven-plugin</artifactId>
<version>1.3.7</version>
<configuration>
- <testScript>script/test_runner.clj</testScript>
+ <vmargs>-Dclojure.test.generative.runner=clojure.test</vmargs>
+ <!-- <testScript>bin/test_runner.clj</testScript> -->
<copiedNamespaces>
<namespace>!.*</namespace>
</copiedNamespaces>
View
@@ -1,7 +0,0 @@
-#!/bin/sh
-# Note: First you must run mvn dependency:build-classpath -Dmdep.outputFile=script/maven-classpath
-CLASSPATH=src/main/clojure:src/test/clojure:src/examples/clojure:`cat script/maven-classpath`
-
-java -server -Xmx2G -cp $CLASSPATH clojure.main -i script/examples.clj
-
-
View
@@ -1,14 +0,0 @@
-(use '[clojure.test.generative])
-(try
- (println "Testing on" *cores* "cores for" *msec* "msec.")
- (let [futures (test-dirs "src/examples/clojure")]
- (doseq [f futures]
- @f))
- (catch Throwable t
- (.printStackTrace t)
- (System/exit -1))
- (finally
- (shutdown-agents)))
-(System/exit 0)
-
-
View
@@ -1,13 +0,0 @@
-#!/bin/bash
-# Note: First you must run mvn dependency:build-classpath -Dmdep.outputFile=script/maven-classpath
-CLASSPATH=src/main/clojure:src/test/clojure:src/examples/clojure:`cat script/maven-classpath`
-
-USER_SCRIPT=$1
-shift
-if [ "$USER_SCRIPT" != "" ]; then
- USER_SCRIPT="-i $USER_SCRIPT -r "
-fi
-
-java -server -Xmx2GB -cp $CLASSPATH clojure.main $USER_SCRIPT
-
-
@@ -1,14 +0,0 @@
-(use '[clojure.test.generative])
-(try
- (println "Testing on" *cores* "cores for" *msec* "msec.")
- (let [futures (test-dirs "src/main/clojure" "src/test/clojure")]
- (doseq [f futures]
- @f))
- (catch Throwable t
- (.printStackTrace t)
- (System/exit -1))
- (finally
- (shutdown-agents)))
-(System/exit 0)
-
-
@@ -0,0 +1,83 @@
+; Copyright (c) Rich Hickey, Stuart Halloway, and contributors.
+; 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.array-test
+ (:use clojure.test.generative)
+ (:require [clojure.test.generative.generators :as gen]
+ [clojure.test.generative.clojure-test :as clojure-test]))
+
+(clojure-test/run-generative-tests)
+
+(defn nan-or-=
+ [a b]
+ (or (= a b)
+ (and (Double/isNaN a)
+ (Double/isNaN b))))
+
+(defmacro array-access-specs
+ [pdescs]
+ `(do
+ ~@(map
+ (fn [[prim comp]]
+ `(defspec ~(symbol (str prim "-array-access"))
+ vec
+ [~(with-meta 'arr {:tag (list (symbol (str prim "-array")) prim)})]
+ (assert (= (alength ~'arr) (count ~'%)))
+ (dotimes [~'i (count ~'arr)]
+ (assert (~comp (aget ~'arr ~'i) (get ~'% ~'i))))))
+ pdescs)))
+
+(defmacro copy-array-fns
+ [& types]
+ `(do
+ ~@(map
+ (fn [t]
+ `(defn ~(symbol (str "copy-" t "-array"))
+ [~'a]
+ (let [~'copy ~(list (symbol (str t "-array")) 'a)]
+ (dotimes [~'i (alength ~'a)]
+ (aset ~'copy ~'i ~(with-meta `(aget ~'a ~'i)
+ {:tag (symbol (str t "s"))})))
+ ~'copy)))
+ types)))
+
+(copy-array-fns boolean byte char short int long float double object)
+
+(defmacro aset-specs
+ [pdescs]
+ `(do
+ ~@(map
+ (fn [[prim comp]]
+ `(defspec ~(symbol (str prim "-aset-spec"))
+ copy-object-array
+ [~(with-meta 'arr {:tag (list (symbol (str prim "-array")) prim)})]
+ (assert (= (alength ~'arr) (alength ~'%)))
+ (dotimes [~'i (count ~'arr)]
+ (assert (~comp (aget ~'arr ~'i) (aget ~'% ~'i))))))
+ pdescs)))
+
+(array-access-specs {int =
+ long =
+ float nan-or-=
+ double nan-or-=
+ short =
+ byte =
+ char =
+ boolean =})
+
+(aset-specs {int =
+ long =
+ float nan-or-=
+ double nan-or-=
+ short =
+ byte =
+ char =
+ boolean =})
+
+
@@ -0,0 +1,29 @@
+; Copyright (c) Rich Hickey, Stuart Halloway, and contributors.
+; 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.java-test
+ (:use clojure.test.generative))
+
+(set! *warn-on-reflection* true)
+
+(defspec entry-set-keys-always-have-values
+ #(java.util.concurrent.ConcurrentHashMap. ^java.util.Map %)
+ [^{:tag (hash-map #(uniform 0 1e7) long #(uniform 1 20000))} m]
+ (let [ks (keys m)]
+ (dotimes [_ 5]
+ (future
+ (doseq [k (shuffle ks)]
+ (.remove ^java.util.Map % k)
+ (Thread/sleep 1)))))
+ (loop [it (-> ^java.util.Map % (.entrySet) (.iterator))]
+ (Thread/sleep 1)
+ (when (.hasNext it)
+ (let [[k v] (.next it)]
+ (when (nil? v) (throw (RuntimeException. "Nil value for " k)))
+ (recur it)))))
@@ -78,9 +78,10 @@
(defspec quotient-and-remainder
(fn [a b] (sort [a b]))
[^{:tag `integer} a ^{:tag `integer} b]
- (let [[a d] %
- q (quot a d)
- r (rem a d)]
- (assert (= a
- (+ (* q d) r)
- (unchecked-add (unchecked-multiply q d) r)))))
+ (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))))))
Oops, something went wrong.

0 comments on commit 992d301

Please sign in to comment.