Uploaded image for project: 'Clojure'
  1. CLJ-1936

instrumented fdef with fspec unnecessarily invokes fspec generator

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Declined
    • Affects versions: Release 1.9
    • Fix versions: None
    • Labels:
    • Approval:
      Triaged

      Description

      With test.check is on the classpath, an instrumented fdef with fspec will invoke the generator for the fspec when invoked:

      (require '[clojure.spec :as s] '[clojure.spec.test :as st])
      
      (defn foo [fnn] (fnn 42))
      (s/fdef foo :args (s/cat :f (s/fspec :args (s/cat :i integer?)
                                           :ret integer?)))
      
      (foo #(do (println %) (when (even? %) 42)))
      42
      42
      
      (st/instrument `foo)
      
      (foo #(do (println %) (when (even? %) 42)))
      -1
      0
      -1
      0
      0
      -1
      0
      -1
      ExceptionInfo Call to #'user/foo did not conform to spec:
      In: [0] val: nil fails at: [:args :f :ret] predicate: integer?
      :clojure.spec/args  (#object[user$eval12$fn__13 0x515c6049 "user$eval12$fn__13@515c6049"])
      :clojure.spec/failure  :instrument
      :clojure.spec.test/caller  {:file "NO_SOURCE_FILE", :line 8, :var-scope user/eval12}
        clojure.core/ex-info (core.clj:4725)
      

      Without test.check, this fails:

      user=> (foo #(do (println %) (when (even? %) 42)))
      FileNotFoundException Could not locate clojure/test/check/generators__init.class or clojure/test/check/generators.clj on classpath.  clojure.lang.RT.load (RT.java:458)
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              arohner Allen Rohner
            • Votes:
              2 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: