File tree Expand file tree Collapse file tree
examples/clojure/clojure/test
main/clojure/clojure/test/generative Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,7 +39,19 @@ and a validator:
3939To generate test data, see the fns in the generators namespace. Note
4040that these functions shadow a bunch of clojure.core names.
4141
42- Running Interactively During Development
42+ You can also create the underlying test data structures directly,
43+ marking vars with : clojure .test.generative/specs so they are picked up
44+ by the runner. This can be useful e.g. to model relationships between
45+ input parameters, or to specify a finite list of special cases. The
46+ example below specifies five specific one-argument arg lists:
47+
48+ (def ^::tgen/specs
49+ inc'-doesnt-overflow-specs
50+ [{:test 'clojure.test.math-test/inc'-doesnt-overflow
51+ :input-gen #(map vector [Long/MIN_VALUE -1 0 1 Long/MAX_VALUE])}])
52+
53+
54+ Running Interactively During Development
4355========================================
4456
4557Specify the number of threads, the number of msec, and one or more
Original file line number Diff line number Diff line change 99
1010(ns clojure.test.math-test
1111 (:use clojure.test.generative)
12- (:require [clojure.data.generators :as gen]))
12+ (:require
13+ [clojure.data.generators :as gen]
14+ [clojure.test.generative :as tgen]))
1315
1416(defn integer
1517 " Distribution of integers biased towards the small, but
8587 (assert (= a
8688 (+ (* q d) r)
8789 (unchecked-add (unchecked-multiply q d) r))))))
90+
91+ (defn inc '-doesnt-overflow
92+ [a]
93+ (assert (< a (inc' a))))
94+
95+ ; ; You can mark a var containing "raw" specs with ::tgen/specs to
96+ ; ; include it in the test suite.
97+ (def ^::tgen/specs
98+ inc '-doesnt-overflow-specs
99+ [{:test 'clojure.test.math-test/inc'-doesnt-overflow
100+ :input-gen #(map vector [Long/MIN_VALUE -1 0 1 Long/MAX_VALUE])}])
Original file line number Diff line number Diff line change 1111 (:require
1212 [clojure.pprint :as pprint]
1313 [clojure.tools.namespace :as ns ]
14- [clojure.data.generators :as gen]))
14+ [clojure.data.generators :as gen]
15+ [clojure.test.generative :as tgen]))
1516
1617(set! *warn-on-reflection* true )
1718
5051 clojure.lang.Var
5152 (get-tests
5253 [v]
53- (when-let [arg-fns (:clojure.test.generative/arg-fns (meta v))]
54- [{:test (-> (if-let [ns (.ns v)]
55- (str ns " /" (.sym v))
56- (.sym v))
57- symbol)
58- :input-gen (fn []
59- (repeatedly
60- (fn []
61- (into [] (map #(% ) arg-fns)))))}]))
62-
63- clojure.lang.MapEquivalence
64- (get-tests
65- [m] m))
54+ (let [m (meta v)
55+ arg-fns (::tgen/arg-fns m)
56+ specs (::tgen/specs m)]
57+ (cond
58+ arg-fns
59+ [{:test (-> (if-let [ns (.ns v)]
60+ (str ns " /" (.sym v))
61+ (.sym v))
62+ symbol)
63+ :input-gen (fn []
64+ (repeatedly
65+ (fn []
66+ (into [] (map #(% ) arg-fns)))))}]
67+
68+ specs
69+ @v))))
6670
6771
6872(defn- find-vars-in-namespaces
You can’t perform that action at this time.
0 commit comments