Leiningen test hooks clash with test.check 0.9.0 #2173

Closed
gaverhae opened this Issue Jul 13, 2016 · 6 comments

Comments

7 participants
@gaverhae
Contributor

gaverhae commented Jul 13, 2016

Minimal (or at least small) reproducing example, project.clj:

(defproject t "0"
  :dependencies [[org.clojure/clojure "1.9.0-alpha10"]
                 [org.clojure/test.check "0.9.0"]])

test/t/core_test.clj

(ns t.core-test
  (:require [clojure.spec :as spec]
            [clojure.spec.test :as spec.test]
            [clojure.test :refer :all]))

(defn dummy [i] (inc i))

(deftest fails
  (is (true?
        (->
          (spec.test/check-fn
            dummy
            (spec/fspec
              :args (spec/tuple int?)
              :ret integer?
              :fn #(= (-> % :ret) (-> % :args first inc))))
          :clojure.spec.test.check/ret :result))))

I would expect that test to pass. Running the check-fn in the REPL works fine. When running lein test, however, I get:

ERROR in (fails) (Compiler.java:7410)
expected: (true? (-> (spec.test/check-fn dummy (spec/fspec :args (spec/tuple int?) :ret integer? :fn (fn* [p1__485#] (= (-> p1__485# :ret) (-> p1__485# :args first inc))))) :clojure.spec.test.check/ret :result))
  actual: clojure.lang.Compiler$CompilerException: java.lang.ClassCastException: clojure.lang.AFunction$1 cannot be cast to clojure.lang.MultiFn, compiling:(clojure/test/check/clojure_test.cljc:95:1)

That test.check line 95 is trying to call get-method on clojure.test/report, which is defined as a multimethod in clojure.test.

Running the above tests with tools.trace enabled, I got:

TRACE t493: (clojure.core/alter-var-root #'clojure.test/report #object[leiningen.core.injected$prepare_for_hooks$fn__34 0x55795845 "leiningen.core.injected$prepare_for_hooks$fn__34@55795845"])
TRACE t493: => #object[clojure.lang.AFunction$1 0x5b970f7 "clojure.lang.AFunction$1@5b970f7"]

which leads me to believe that the source of the problem is somewhere around here, though I am definitely not familiar enough with that code to understand the implications. Should this be filed against robert-hooke to keep the "multi" nature of a redefined fn?

@puredanger

This comment has been minimized.

Show comment
Hide comment
@puredanger

puredanger Aug 3, 2016

One workaround for this problem is to turn off lein monkey-patching of clojure.test in your project.clj:

:monkeypatch-clojure-test false

Also, I believe test.check has a change that avoids this in master for the next version.

One workaround for this problem is to turn off lein monkey-patching of clojure.test in your project.clj:

:monkeypatch-clojure-test false

Also, I believe test.check has a change that avoids this in master for the next version.

@puredanger

This comment has been minimized.

Show comment
Hide comment
@otfrom

This comment has been minimized.

Show comment
Hide comment
@otfrom

otfrom Sep 19, 2016

I bumped into this problem on 19 Sept. Adding :monkeypatch-clojure-test false worked, but it failed as above without it. I'm using

[org.clojure/clojure "1.9.0-alpha12"]
[org.clojure/test.check "0.9.0"]

otfrom commented Sep 19, 2016

I bumped into this problem on 19 Sept. Adding :monkeypatch-clojure-test false worked, but it failed as above without it. I'm using

[org.clojure/clojure "1.9.0-alpha12"]
[org.clojure/test.check "0.9.0"]

@hypirion hypirion added docs bug and removed docs labels Sep 19, 2016

@halcyon halcyon referenced this issue in rentpath/rp-util-clj Oct 13, 2016

Merged

Add only-one and non-blank-string? #2

@technomancy

This comment has been minimized.

Show comment
Hide comment
@technomancy

technomancy Mar 23, 2017

Owner

I don't think there's much we can do about this; clojure.test is notoriously inflexible, and my efforts to improve it upstream have historically had a very poor success rate; otherwise we never would have resorted to this unfortunate monkeypatching.

If I had to do it over again I would have made lein test use a fork of clojure.test so that we could improve it as needed, but there's no way to give up on the monkeypatching now without breaking existing features.

Owner

technomancy commented Mar 23, 2017

I don't think there's much we can do about this; clojure.test is notoriously inflexible, and my efforts to improve it upstream have historically had a very poor success rate; otherwise we never would have resorted to this unfortunate monkeypatching.

If I had to do it over again I would have made lein test use a fork of clojure.test so that we could improve it as needed, but there's no way to give up on the monkeypatching now without breaking existing features.

@didibus

This comment has been minimized.

Show comment
Hide comment
@didibus

didibus Apr 3, 2017

Another workaround is to add (run-tests) at the end of you test namespace. It has the unfortunate effect of having lein run the tests twice, but it appears to fix this issue at the same time.

didibus commented Apr 3, 2017

Another workaround is to add (run-tests) at the end of you test namespace. It has the unfortunate effect of having lein run the tests twice, but it appears to fix this issue at the same time.

@conan

This comment has been minimized.

Show comment
Hide comment
@conan

conan Oct 9, 2017

I've encountered this without depending on test.check directly, but instead pulling it in via clojure.spec.test.alpha. :monkeypatch-clojure-test false in the project.clj makes it work.

conan commented Oct 9, 2017

I've encountered this without depending on test.check directly, but instead pulling it in via clojure.spec.test.alpha. :monkeypatch-clojure-test false in the project.clj makes it work.

dlebrero added a commit to akvo/akvo-flow-services that referenced this issue Jul 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment