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

Specify test on command line #12

Open
subsetpark opened this issue Aug 11, 2021 · 2 comments
Open

Specify test on command line #12

subsetpark opened this issue Aug 11, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@subsetpark
Copy link
Collaborator

eg:

(deftest foo-test
 ...)
jpm test -t "foo-test"

runs only that test.

@subsetpark subsetpark added the enhancement New feature or request label Aug 11, 2021
@pyrmont
Copy link
Owner

pyrmont commented Nov 1, 2021

I spent some time looking at how to implement this. Essentially, you have to change the way that JPM works and I'm not sure if doing that would be welcomed. You'd ideally want something generalisable and not just for Testament and I'm not sure what that would look like.

In terms of a crude solution, you can do the following:

  1. change the function test in commands.janet like so:

    (defn test
      [& args]
      (setdyn :test-args args)
      (local-rule "test"))
  2. change the function run-tests in declare.janet like so:

    (defn run-tests
      "Run tests on a project in the current directory. The tests will
      be run in the environment dictated by (dyn :modpath)."
      [&opt root-directory build-directory]
      (def monkey-patch
        (string
          "(setdyn :test-args " (string/format "%p" (dyn :test-args)) ")\n"
          ...

This now allows you to write jpm test arg-1 arg-2 and have arg-1 arg-2 appear in the :test-args dynamic variable. At this point, we can change the way run-tests! works to look for that dynamic variable and adjust behaviour accordingly.

Even with this, you can't do something like jpm test --name test-name because JPM will see --name as an option that can apply to jpm. And then the problem with jpm test arg-1 arg-2 as a syntax is that you might reasonably think that the arguments after the test command are filenames (so that jpm test my_test.janet would run only test/my_test.janet rather than every file in the test directory). For what it's worth, I think the way that JPM's option parsing works is a mistake since --name looks to me like an option on the test subcommand not the jpm primary command but I'd be worried a change to this part of JPM would make a pull request even less likely to be accepted.

Given the above, I'm not sure what to do. Having this functionality would definitely be nice but without adding a sophisticated argument parsing library on top of JPM, I'm not sure if there's a way to get it. Any thoughts?

@pyrmont
Copy link
Owner

pyrmont commented Nov 29, 2021

OK, so I went and made an alternative project manager, Jeep, and I basically implemented what I suggested above.

Jeep is in many ways an alternative front-end to JPM but set up to work the way that I would like a Janet project manager to work. One of the things I did was make it so that you can write:

$ jeep test test-1 test-2 test-3

and Jeep will execute each Janet file in test/ with the dynamic binding :tests set to @["test-1" "test-2" "test-3"]. It's just a matter at this point of updating Testament's run-tests! function to look for that dynamic binding and adjust behaviour accordingly. I'll give that a go sometime this week.

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

No branches or pull requests

2 participants