Generative Testing for Self-Hosted ClojureScript

June 7, 2017

A release of test.check is now available which supports self-hosted ClojureScript! All you need to obtain is version 0.10.0-alpha1.

Here is the test.check ClojureScript example working in Planck (the same works in Lumo):

$ planck -qc test.check-0.10.0-alpha1.jar
cljs.user=> (ns cljs.user
       #_=>   (:require [clojure.test.check :as tc]
       #_=>             [clojure.test.check.generators :as gen]
       #_=>             [ :as prop :include-macros true]))
cljs.user=> (def sort-idempotent-prop
       #_=>   (prop/for-all [v (gen/vector gen/int)]
       #_=>     (= (sort v) (sort (sort v)))))
cljs.user=> (tc/quick-check 100 sort-idempotent-prop)
{:result true, :num-tests 100, :seed 1496853287202}

The changes needed for this (TCHECK-105) have been around for a while now, so have been fairly well tested. They are actually already available in the version of Replete that is in the App Store.

The update to test.check also works with Spec in self-hosted ClojureScript:

$ planck -qc test.check-0.10.0-alpha1.jar
cljs.user=> (require '[clojure.spec.alpha :as s]
       #_=>  '[clojure.test.check.generators])
cljs.user=> (s/def ::my-number integer?)
cljs.user=> (s/exercise ::my-number)
([0 0] [-1 -1] [-1 -1] [-1 -1] [1 1] [-8 -8] [0 0] [6 6] [-108 -108] [-57 -57])

Have fun!

Tags: ClojureScript