Skip to content
This repository has been archived by the owner on Jan 9, 2022. It is now read-only.
/ spartan.spec Public archive

A spartan version of clojure.spec compatible with babashka

License

Notifications You must be signed in to change notification settings

borkdude/spartan.spec

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spartan.spec

project chat

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.

Rationale

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.

Differences with clojure.spec.alpha

  • No generators (yet)
  • No fdef (yet)

Usage:

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.

Example

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?)

-------------------------

Tests

Install babashka and deps.clj. Then run script/test.

License

Copyright © 2020 Michiel Borkent

Distributed under the EPL License. See LICENSE.

About

A spartan version of clojure.spec compatible with babashka

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published