Skip to content

Wildcard keys can override specific keys #16

@gfredericks

Description

@gfredericks

Looks like {:a s/Int, s/Keyword s/Bool} can fail when the key :a gets coincidentally generated by the s/Keyword key schema.

This causes a spurious test failure for me every few weeks.

I see there's currently a comment to this effect:

  ;; TODO: this does not currently capture proper semantics of maps with
  ;; both specific keys and key schemas that can override them.

Reproduction:

#!/usr/bin/env bash

clojure \
    -Srepro \
    -Sdeps '{:deps {prismatic/schema-generators {:mvn/version "0.1.2"}}}' \
    /dev/stdin <<EOF
(ns user
  (:require
   [clojure.test.check.generators :as gen]
   [schema.core                   :as s]
   [schema-generators.generators  :as schema-generators]))

(def schema {:a s/Int, s/Keyword s/Bool})

(def g (schema-generators/generator schema))

;; throws after a couple minutes
(count (schema-generators/sample 10000 schema))

;; throws immediately, but uses test.check impl details
#_
(prn (#'gen/call-gen g (clojure.test.check.random/make-random 2784) 30))

EOF

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions