1

I want to check if the right instance is used.
But while the repl gives me true, the actual test returns nil. Idk why


(ns my-app.queue)

(def queue (atom clojure.lang.PersistentQueue/EMPTY))

(ns my-app.queue-test
  (:require [my-app.queue :as sut]
            [clojure.test :refer :all]))

(deftest queue-type-test
  (is (instance? clojure.lang.PersistentQueue @sut/queue)))

;repl output
;(instance? clojure.lang.PersistentQueue @sut/queue) ;=> true

The command lein test gives me:
FAIL in (queue-type-test) (queue_test.clj:6) expected: (instance? clojure.lang.PersistentQueue (clojure.core/deref sut/queue)) actual: nil

I know the test itself is not really useful, but I can't figure out why this behaves like this.

5
  • Small detail, but the first namespace declaration and import in your code don't align. Commented Feb 27, 2018 at 16:01
  • Could it be that another test resets the atom to nil? Commented Feb 27, 2018 at 16:02
  • I have the same result running lein test :only my-app.queue-test Commented Feb 27, 2018 at 16:11
  • It works great for me. Try running lein clean, verify your namespaces are all OK, and re-run lein test. Commented Feb 27, 2018 at 17:16
  • Maybe you could reproduce this in a git project. Commented Feb 27, 2018 at 17:44

1 Answer 1

1

tl;dr: both is and @ are macros. Most obvious fix would be something like:

(deftest queue-type-test
  (let [queue @sut/queue]
    (is (instance? clojure.lang.PersistentQueue queue)))

clojure.test docs don't make it immediately obvious, but is is a pretty tricky macro that looks inside its body. Here's a snippet from the docstring:

user> (is (= 5 (+ 2 2)))

FAIL in  (:1)
expected: (= 5 (+ 2 2))
  actual: (not (= 5 4))
false

Notice actual: (not (= 5 4)). It's clear that it did not evaluate = so that it can show us the result of (+ 2 2). Here are all the special cases for assert-expr multimethod.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.