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

Cannot run tests defined with custom macro #3279

Closed
lmartelli opened this issue Dec 5, 2022 · 6 comments · Fixed by #3481
Closed

Cannot run tests defined with custom macro #3279

lmartelli opened this issue Dec 5, 2022 · 6 comments · Fixed by #3481
Assignees

Comments

@lmartelli
Copy link

Expected behavior

Run tests, provided cider-test-defining-forms is customized for a custom test macro

Actual behavior

No assertions (or no tests) were run.Did you forget to use ‘is’ in your tests?

Steps to reproduce the problem

(ns test
  (:require
   [clojure.test :refer [deftest is are]]))


(defmacro def-my-test [f expected]
  `(deftest ~(symbol (str f "-test"))
     (is (= ~expected (~f)))))

(defn meaning-of-life [] 42)

(def-my-test meaning-of-life 43)

Include def-my-test in cider-test-defining-forms.

Run test for (def-my-test meaning-of-life 42) with `C-c C-

Macros sems to be OK, since I can run the test by hand :

test> (meaning-of-life-test)

FAIL in (meaning-of-life-test) (test.clj:12)
expected: (clojure.core/= 43 (meaning-of-life))
  actual: (not (clojure.core/= 43 42))
nil

Environment & Version information

CIDER version information

Include here the version string displayed when
CIDER's REPL is launched. Here's an example:

;; CIDER 1.1.1 (Plovdiv), nREPL 0.8.3
;; Clojure 1.10.0, Java 17.0.5

Lein / Clojure CLI version

Leiningen 2.9.1

Emacs version

27.1

Operating system

Ubuntu 22.04.1 LTS
Linux tp 5.15.0-56-generic #62-Ubuntu SMP

JDK distribution

openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment (build 17.0.5+8-Ubuntu-2ubuntu122.04)
OpenJDK 64-Bit Server VM (build 17.0.5+8-Ubuntu-2ubuntu122.04, mixed mode, sharing)

@bbatsov
Copy link
Member

bbatsov commented Dec 5, 2022

;; CIDER 1.1.1 (Plovdiv), nREPL 0.8.3

I assume you're not actually running CIDER 1.1.1, right? :-)

@lmartelli
Copy link
Author

;; CIDER 1.1.1 (Plovdiv), nREPL 0.8.3

I assume you're not actually running CIDER 1.1.1, right? :-)

I am afraid I am, actually :-\ I had not realized I am using such an old version. Will try the latest ...

@lmartelli
Copy link
Author

I have the same behavior with 1.5.0

@vemv
Copy link
Member

vemv commented Dec 6, 2022

Bit of an aside for @bbatsov - what's the point of cider-test-defining-forms?

Or alternatively worded - if no test-defining form is found, why not fall back to the current top-level form?

It seems a perfectly CIDER-y thing to do i.e. trust the runtime.

@bbatsov
Copy link
Member

bbatsov commented Dec 11, 2022

As noted in the docs:

If your individual tests are not defined by deftest or defspec, CIDER will
not recognize them when searching for a test at point in cider-test-run-test.
You can customize the variable cider-test-defining-forms to add additional
forms for CIDER to recognize as individual test definitions.

I guess we can alternatively assume that the current top-level form is a test and try to run it. I can't exactly remember the reasoning around the current implementation, I assume it was mostly an artefact of the old days were we only support deftest and we didn't need to care about anything else.

@vemv vemv self-assigned this Jul 27, 2023
@vemv vemv pinned this issue Aug 24, 2023
vemv added a commit that referenced this issue Sep 25, 2023
Fixes #2958
Fixes #3279

Co-authored-by: tvirolai <tvirolai@users.noreply.github.com>
vemv added a commit that referenced this issue Sep 25, 2023
Fixes #2958
Fixes #3279

Co-authored-by: tvirolai <tvirolai@users.noreply.github.com>
vemv added a commit that referenced this issue Sep 26, 2023
Fixes #2958
Fixes #3279

Co-authored-by: tvirolai <tvirolai@users.noreply.github.com>
@vemv
Copy link
Member

vemv commented Sep 26, 2023

CIDER master / 20230926.1139 features a revamped cider-test-run-test (run test at point).

Now, it will run the first valid test found at point for:

  • the current *cider-test-report* failure
  • deftests, and deftest-like forms (cider-test-defining-forms is no longer necessary and now deprecated) in the current namespace
  • :test metadata that may be present in vanilla defns
  • deftests for the current src/ defn, as found (and configurable) by cider-test-infer-test-ns
    • We search for a var named foo-test in that inferred ns, falling back to foo

Docs: https://docs.cider.mx/cider/testing/running_tests.html

@vemv vemv unpinned this issue Sep 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants