test.check

defspec makes it impossible to specify :max-size (and seed)

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

While defspec is very valuable for integration with clojure.test, it is almost impossible to specify :max-size for the quick-check call. The only way I've found around it right now is by using the following macro:

(defmacro ^:private change-max-size
  [name max-size]
  `(alter-meta! (var ~name) assoc
                :test (fn [] (#'ct/assert-check
                             (assoc (~name ct/*default-test-count*
                                           :max-size ~max-size)
                               :test-var (str '~name))))))

This macro alters the meta of a named test such that the quick-check-call uses a specified expression for max-size, but obviously this is a very hacky solution. Preferably, I would be able to specify the :max-size value directly through defspec. I imagine that something like this could work:

(defspec my-test
  {:max-size 40, :num-tests 400}
  (my-test-here))

Essentially, if the optional argument (currently named default-times) is a map, inspect the map for values given, or use defaults if not.

Activity

Hide
Reid Draper added a comment -

I like the idea of making the first (optional) argument a map. This allows us to add in more options in the future, without breaking existing code.

Show
Reid Draper added a comment - I like the idea of making the first (optional) argument a map. This allows us to add in more options in the future, without breaking existing code.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated: