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

Supporting clojure.test/with-test #707

Closed
giorgio-v opened this issue Aug 6, 2014 · 15 comments
Closed

Supporting clojure.test/with-test #707

giorgio-v opened this issue Aug 6, 2014 · 15 comments
Assignees

Comments

@giorgio-v
Copy link

Would it be possible to extend Cider to support the clojure.test/with-test macro?

Basically, I’d like to run tests defined in this way, too:

(test/with-test
  (defn hello [name]
    (str "Hello, " name))
  (is (= (hello "Brian") "Hello, Brian"))
  (is (= (hello nil) "Hello, ")))

Right now, these are not loaded because they are attached as meta data to the functions.

@jeffvalk jeffvalk self-assigned this Aug 7, 2014
@jeffvalk
Copy link
Contributor

jeffvalk commented Aug 7, 2014

It should be possible, yes. I will look into this, but possibly not for a little while.

This is way of writing tests was obviously a supported feature early in Clojure's history, but I don't think many people write tests this way in practice.

@giorgio-v
Copy link
Author

I see.

Honestly, I’m trying to figure out if this style of testing is worth the pain, given the lack of tool support. I like the idea to define tests and functions in the same place, I think it gives you a much better context, but the supposed advantage could be offset if the friction with tools is too high.

@bbatsov
Copy link
Member

bbatsov commented Jan 26, 2016

Btw, @jeffvalk any plans to work on this?

@jeffvalk
Copy link
Contributor

I hadn't thought about it...but now that I am, I'm not sure why this doesn't work as is. I'll look at it.

@bbatsov
Copy link
Member

bbatsov commented Jan 27, 2016

Great!

@Malabarba
Copy link
Member

I'm not sure why this doesn't work as is. I'll look at it.

My guess would be that with-tests adds the tests to the function metadata, which is on the current namespace. However, CIDER only ever runs tests from one namespace. So if there's also a namespace called current.namespace-test, then CIDER is only going to run tests from the latter.

Just a guess, though. :-)

@jeffvalk
Copy link
Contributor

@Malabarba Yep, seems likely. If that's the case, running tests with suppress-inference should pick these up. And if that's true, this issue is already resolved.

@bbatsov
Copy link
Member

bbatsov commented Jan 27, 2016

Maybe. :-) Although we might have to account for tests being in the same namespace and in a test namespace (which shouldn't be hard to do).

@bbatsov
Copy link
Member

bbatsov commented Feb 3, 2016

Did someone check this?

@jeffvalk
Copy link
Contributor

jeffvalk commented Feb 3, 2016

@bbatsov Yes. @Malabarba is right. And the forthcoming (very soon!) commit to add #1226 will close this issue.

@derekchiang
Copy link

derekchiang commented Dec 15, 2017

@jeffvalk sorry if I missed something obvious, but how is this issue fixed? As in, how exactly do I run the tests defined with with-test?

@bbatsov
Copy link
Member

bbatsov commented Dec 16, 2017

with-tests adds some metadata that CIDER uses to know if something is a test that needs to be run or not. You can just use its functionality to run the tests in the current namespace.

@derekchiang
Copy link

@bbatsov but how exactly do you run the tests? Neither cider-test-run-ns-tests nor cider-test-run-test works.

@bbatsov
Copy link
Member

bbatsov commented Dec 24, 2017

C-c C-t C-n has to be invoked with a prefix argument (C-u) to suppress namespace inference. Otherwise it will try to find some test namespace. Not sure why cider-test-run-test is not working for you, though. If a var has the right metadata it should work. Please, file a ticket for this.

@bbatsov
Copy link
Member

bbatsov commented Dec 24, 2017

Ah, I forgot about something - http://cider.readthedocs.io/en/latest/running_tests/

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.

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

No branches or pull requests

5 participants