reiddraper / simple-check

QuickCheck for Clojure
http://reiddraper.github.io/simple-check/
286 stars 18 forks source link

Default test count option in defspec is broken #48

Closed hypirion closed 10 years ago

hypirion commented 10 years ago

The form (defspec name property) throws an ArityException printing "Wrong number of args(1) passed to: clojure-test$defspec" when you attempt to use it.

Minimal reproducible test steps:

$ lein new faulty-defspec
Generating a project called faulty-defspec based on the 'default' template.
To see other templates (app, lein plugin, etc), try `lein help new`.
$ cd faulty-defspec
# Modify project.clj so that it contains following line:
#  :profiles {:dev {:dependencies [[reiddraper/simple-check "0.5.3"]]}}

Then replace the contents of test/faulty_defspec/core_test.clj with the following:

(ns faulty-defspec.core-test
  (:require [simple-check.core       :as sc]
            [simple-check.generators :as gen]
            [simple-check.properties :as prop]
            [simple-check.clojure-test :as ct :refer [defspec]]
            [clojure.test :refer :all]))

(defspec prop-check
  (prop/for-all [a gen/int
                 b gen/pos-int]
    (>= (+ a b) a)))

Now, running DEBUG='y' lein test will return the following stacktrace:

Leiningen's classpath: .:/home/your-username/.lein/self-installs/leiningen-2.3.4-standalone.jar
Applying task test to ()
Applying task javac to nil
Running javac with [@/tmp/.leiningen-cmdline2625741719597718623.tmp]
Applying task compile to nil
All namespaces already AOT compiled.
Exception in thread "main" clojure.lang.ArityException: Wrong number of args (1) passed to: clojure-test$defspec
    at clojure.lang.Compiler.macroexpand1(Compiler.java:6473)
    at clojure.lang.Compiler.macroexpand(Compiler.java:6529)
    at clojure.lang.Compiler.eval(Compiler.java:6603)
    at clojure.lang.Compiler.load(Compiler.java:7064)
    at clojure.lang.RT.loadResourceScript(RT.java:370)
    at clojure.lang.RT.loadResourceScript(RT.java:361)
    at clojure.lang.RT.load(RT.java:440)
    at clojure.lang.RT.load(RT.java:411)
    at clojure.core$load$fn__5018.invoke(core.clj:5530)
    at clojure.core$load.doInvoke(core.clj:5529)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5336)
    at clojure.core$load_lib$fn__4967.invoke(core.clj:5375)
    at clojure.core$load_lib.doInvoke(core.clj:5374)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:619)
    at clojure.core$load_libs.doInvoke(core.clj:5413)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:619)
    at clojure.core$require.doInvoke(core.clj:5496)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:619)
    at user$eval85.invoke(form-init1109842131822090307.clj:1)
    at clojure.lang.Compiler.eval(Compiler.java:6619)
    at clojure.lang.Compiler.eval(Compiler.java:6609)
    at clojure.lang.Compiler.load(Compiler.java:7064)
    at clojure.lang.Compiler.loadFile(Compiler.java:7020)
    at clojure.main$load_script.invoke(main.clj:294)
    at clojure.main$init_opt.invoke(main.clj:299)
    at clojure.main$initialize.invoke(main.clj:327)
    at clojure.main$null_opt.invoke(main.clj:362)
    at clojure.main$main.doInvoke(main.clj:440)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at clojure.lang.Var.invoke(Var.java:419)
    at clojure.lang.AFn.applyToHelper(AFn.java:163)
    at clojure.lang.Var.applyTo(Var.java:532)
    at clojure.main.main(main.java:37)
Tests failed.

Issue lies within this line:

([name property]
  (defspec name *default-test-count* property))

One solution to the issue is to modify the line as follows:

([name property]
  `(defspec ~name ~*default-test-count* ~property))

I didn't bother to do a PR because of the possible Contrib migration and the hassle such a PR would provide.

cemerick commented 10 years ago

Damn, you're totally right.

@reiddraper: should I push a fix for this now, or is the repo in lock-down until the contrib thing is settled?

reiddraper commented 10 years ago

@cemerick a fix would be great. It's only on lockdown for new contributors, until the move. At least as far as I understand...

reiddraper commented 10 years ago

Anything beside this guy that would be suitable for another release before simple-check moves to test.check?

cemerick commented 10 years ago

There's #46? I'll try to get a PR for this to you tomorrow.