clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.55k stars 645 forks source link

Assertion on type of a record only succeeds if it is the last assertion of a test #1936

Closed jsab closed 5 years ago

jsab commented 7 years ago

Expected behavior

The order of is assertions withing a deftest form should not impact their execution.

Actual behavior

After a defrecord form has been evaluated more than once. An assertion on the type of the record will succeed if it is the last assertion in a deftest but will fail if there is one or more assertions after.

Note that running lein test does not exhibit the problem.

Steps to reproduce the problem

Use minimal project:

https://github.com/jsab/test-record

Follow steps in the README.md file. At the time of the creation of the issue, they are:

  1. M-x cider-jack-in
  2. M-x cider-eval-buffer in core_test.clj
  3. M-x cider-test-run-ns-tests -> PASS
  4. M-x cider-eval-buffer in core.clj
  5. M-x cider-test-run-ns-tests -> FAIL
  6. Comment the last assertion of the first test.
  7. M-x cider-eval-buffer in core_test.clj
  8. M-x cider-test-run-ns-tests -> PASS
  9. Uncomment the last assertion of the first test.
  10. M-x cider-eval-buffer in core_test.clj
  11. M-x cider-test-run-ns-tests -> FAIL
  12. Goto 6.

Using cider-load-buffer instead of cider-eval-buffer yields the same results.

Environment & Version information

CIDER version information

;; CIDER 0.15.0snapshot (package: 20170104.1330), nREPL 0.2.12
;; Clojure 1.8.0, Java 1.8.0_112

Lein/Boot version

Leiningen 2.7.1 on Java 1.8.0_112 Java HotSpot(TM) 64-Bit Server VM

Emacs version

GNU Emacs 25.1.1 (x86_64-apple-darwin16.3.0, NS appkit-1504.76 Version 10.12.2 (Build 16C67)) of 2017-01-06

Operating system

macOS Sierra 10.12.2 (16C67)

bbatsov commented 7 years ago

Looks like a bug indeed. Guess we should look into this. I won't have any time for CIDER until the end of the month at least, so help would be appreciated.

expez commented 7 years ago

My guess is that this behavior would disappear if he used cider-refresh to reload all the code at the same time. Two types on the jvm are equal if they are both the same and were loaded with the same classloader.

Can you try that @jsab?

jsab commented 7 years ago

@expez cider-refresh does not make the test pass.

Steps used:

  1. First five steps as above.
  2. M-x cider-refresh -> Cider refresh: Reloading successful
  3. M-x cider-test-run-ns-tests -> Fail

There are now two tests in the project so that you can see the behavior for last expression or not last expression in the same test run.

dpsutton commented 7 years ago

@jsab how can you demonstrate the lein test does not have this behavior? It seems that CIDER's test run results in all passing on the first run, but then after re-evaling the source buffer, it starts having issues. It seems lein test would only simulate our first successful run, correct?

jsab commented 7 years ago

@dpsutton Agreed. I included this information because when talking in freenode#clojure about the issue and where I should file it, it was one of the first thing people wanted to know.

xiongtx commented 6 years ago

Cannot reproduce using

CIDER 0.17.0snapshot (package: 20180131.913), nREPL 0.2.13
Clojure 1.8.0, Java 1.8.0_151
xiongtx commented 6 years ago

Hmm, was able to reproduce when using cider-refresh instead of cider-eval-buffer.

This bug is actually pretty extraordinary--I've no idea why it's behaving the way it is!

(deftest a-test
  (is (= (.getClassLoader test_record.core.MyRecord) (.getClassLoader (type (map->MyRecord {})))))
  (is (= 1 1)))
;; => fail

(deftest c-test
  (let [cl1 (.getClassLoader test_record.core.MyRecord)
        cl2 (.getClassLoader (type (map->MyRecord {})))]
    (is (= cl1 cl2)))
  (is (= 1 1)))
;; => pass
stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

stale[bot] commented 5 years ago

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.