metosin / spec-tools

Clojure(Script) tools for clojure.spec
Eclipse Public License 2.0
593 stars 94 forks source link

Inconsistent results from s/valid? and s/explain when trying to spec list of values #275

Open OknoLombarda opened 1 year ago

OknoLombarda commented 1 year ago

When using spec-tools ("0.10.5") to spec a list of values, result spec produces inconsistent results when validated against in s/valid? and s/explain.

Clojure CLI version 1.11.1.1273

Minimal example:

(ns case
  (:require [spec-tools.data-spec :as ds]
            [clojure.spec.alpha :as s]))

(def invalid-data {:cards (list 66)})

(def valid-data {:cards [66]})

(def cards
  {:cards [int?]})

(defn do-stuff [data]
  (if (s/valid? (ds/spec ::sp cards) data)
    (println "Conforms to spec according to 'valid?'")
    (println "Does not conform to spec according to 'valid?'"))
  (if (s/explain-data (ds/spec ::sp cards) data)
    (println "Does not conform to spec according to 'explain-data'")
    (println "Conforms to spec according to 'explain-data'")))

(comment
  (do-stuff invalid-data)
  (do-stuff valid-data))

For some reason s/valid? and s/explain produce different result when a list is used, but same when a vector is used. When I tried to reproduce this issue with spec created directly with clojure.spec.alpha, everything was fine, so it seems the problem is with spec-tools