Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deftest inside false conditional still tests/test is list instead of function #1405

Closed
bobisageek opened this issue Oct 23, 2022 · 4 comments

Comments

@bobisageek
Copy link
Contributor

version
1.0.164

platform
Windows (also repro'ed on linux bb in WSL)

problem
If a deftest exists inside a conditional (e.g. a when), and the condition is false, the :test meta appears to get created as a list instead of a function (as though it were quoted), and the test still tries to execute when the ns is tested

repro

(ns test-test
  (:require [clojure.test :refer [deftest is run-tests]]))

(when nil
  (deftest non-exist (is (= 1 2))))

(meta #'non-exist)
;;;; clojure/JVM
;; => {:ns #namespace[test-test], :name non-exist}

;;;; bb
;; => {:test (clojure.core/fn [] (is (= 1 2))),
;;     :name non-exist,
;;     :ns #object[sci.lang.Namespace 0xdf88f5c "test-test"],
;;     :file "c:\\testing_stuff\\test_test.clj"}


(run-tests)
;;;; clojure/JVM
;; => {:test 0, :pass 0, :fail 0, :error 0, :type :summary}

;;;; bb
;; => {:test 1, :pass 0, :fail 0, :error 1, :type :summary}
;;;; and exception...
;; ERROR in (non-exist) (c:\testing_stuff\test_test.clj:)
;; Uncaught exception, not in assertion.
;; expected: nil
;;   actual: java.lang.ClassCastException: clojure.lang.Cons cannot be cast to clojure.lang.IFn

expected behavior

In the case where the conditional is false, based on Clojure/JVM behavior, the :test meta shouldn't be set, which would imply that when tests are run, the test wouldn't get executed.

additional context
This is very tangentially related to #602 - I'm working on adding the lib tests from the original repo, with a macro to fill in some of the midje functionality - that test code uses some conditional fact calls, so I'm transforming them into deftest calls, which led to this finding.
I haven't done a ton of cause analysis on this yet; just noting the symptom here.

@borkdude
Copy link
Collaborator

@borkdude
Copy link
Collaborator

I guess the name metadata should not be involved there, after some manual JVM Clojure testing

@borkdude
Copy link
Collaborator

At a closer look, only :ns and :name seem to be present in a conditionally defined var in JVM Clojure.
Removing the name metadata worked, but removing :file caused some failing tests in bb. I guess we could just remove the name metadata as a fix for this issue.

@borkdude
Copy link
Collaborator

Should work now with master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants