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

Fix issues with test runner #764

Closed
bpringe opened this issue Aug 22, 2020 · 4 comments
Closed

Fix issues with test runner #764

bpringe opened this issue Aug 22, 2020 · 4 comments
Labels
bug Something isn't working documentation Better documentation needed. test-runner

Comments

@bpringe
Copy link
Member

bpringe commented Aug 22, 2020

After fixing an issue with tests not being found, I realized the test runner could use more work than just that fix, such as:

  • Fixing the output in the repl window (showing a prompt after results, tidying things)
  • Switching the use of the deprecated "test" op to "test-var-query"
  • Fixing "run current test"
    • If there is a #break reader tag in the form at the cursor, parsing of the form fails. Then "undefined" is returned, which then leads to another issue - we pass undefined to the test op which then runs all tests found in the namespace. I think we can possibly make the parser not croak on the #break tag by providing a data reader function for it.
    • It queries for tests when the form at cursor isn't even a test (just a def, instead of deftest or with-test)
    • It doesn't work with with-test tests
  • Writing documentation for the test runner, describing any changes in this PR as well (there is no documentation for it now)
@bpringe bpringe added bug Something isn't working documentation Better documentation needed. test-runner labels Aug 22, 2020
@PEZ
Copy link
Collaborator

PEZ commented Aug 22, 2020

Yes, this would be great to improve in the ways you point at.

About looking for tests when it is just a def. Remember that we should be querying for tests when it is a defn.

@bpringe
Copy link
Member Author

bpringe commented Aug 22, 2020

Sorry, I meant defn. Currently the Run Current Test command doesn't work on defn if it has a corresponding deftest.

If there is a function defined as (defn foo ... and then a test defined as (deftest foo-test ..., if the cursor is at the function defn foo, then foo will be queried as the name of a test, but the corresponding test name is actually foo-test, so no test is found.

I'm not sure if the intention is to find the corresponding test for a defn or to only query for the test if the form is deftest or a defn enclosed in a with-test. If the intention is the former, then we probably should add -test to the name of the function before passing to the nrepl op for running the test.

@PEZ
Copy link
Collaborator

PEZ commented Aug 23, 2020

The intention is to run any tests defined in the metadata of the symbol. So with something like this:

(defn abs
  "The absolute value of a number."
   {:test (fn []
            (is (= (Math/abs 5) 5))
            (is (= (Math/abs -2) 2))
            (is (= (Math/abs 0) 0)))}
  [x]
  {:pre [(number? x)]}
  (if (pos? x)
    x
    (- x)))

Running the current test with the cursor inside this function should run those tests.

Indeed, if we could find the corresponding test defined in a deftest, and if we can support with-tests as well, that would be great. I think for the deftest case we would need two settings:

  1. How to find the namespace where the corresponding deftest could be
  2. How to find the deftest symbol

Probably both involve some regex. Maybe if CIDER does the right thing here, we could have a look at how it is done there.

@bpringe
Copy link
Member Author

bpringe commented Aug 23, 2020

I see. Thanks for the info.

Currently we use the convention -test to look for the corresponding test namespace (for running namespace tests) and use cider-nrepl to find the file path, which does work, so I think a similar thing can be used for finding a corresponding deftest.

const testNS = ns + '-test';

@bpringe bpringe mentioned this issue Aug 25, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Better documentation needed. test-runner
Projects
None yet
Development

No branches or pull requests

2 participants