This project is archived in favor of babashka/spec.alpha.
A spartan implementation of clojure.spec.alpha compatible with babashka (>= 0.2.5) and Clojure.
Currently babashka doesn't have a
built-in implementation of clojure.spec.alpha
. This library can be used
meanwhile. If the application of spec in scripting turns out to be useful,
babashka will probably bundle a built-in implementation of spec2 at some point
which will be more performant than this interpreted version.
- No generators (yet)
- No
fdef
(yet)
Usage in a deps.edn
project:
borkdude/spartan.spec {:git/url "https://github.com/borkdude/spartan.spec"
:sha "12947185b4f8b8ff8ee3bc0f19c98dbde54d4c90"}
Requiring spartan.spec
will create a namespace clojure.spec.alpha
for compatibility.
This is an example that you can run with babashka:
(ns expound
(:require [babashka.deps :as deps]))
(deps/add-deps
'{:deps {borkdude/spartan.spec {:git/url "https://github.com/borkdude/spartan.spec"
:sha "12947185b4f8b8ff8ee3bc0f19c98dbde54d4c90"}
expound/expound {:mvn/version "0.8.9"}}})
;; Loading spartan.spec will create a namespace clojure.spec.alpha for compatibility:
(require 'spartan.spec)
(alias 's 'clojure.spec.alpha)
;; Expound expects some vars to be there, like `with-gen`. Spartan prints warnings that these are used, but doesn't implement them yet.
(require '[expound.alpha :as expound])
(s/def ::a (s/cat :i int? :j string?))
(expound/expound ::a [1 2])
Output:
-- Spec failed --------------------
[... 2]
^
should satisfy
string?
-- Relevant specs -------
:expound/a:
(clojure.spec.alpha/cat :i clojure.core/int? :j clojure.core/string?)
-------------------------
Install babashka and deps.clj.
Then run script/test
.
Copyright © 2020 Michiel Borkent
Distributed under the EPL License. See LICENSE.