Open subsetpark opened 3 years ago
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:
change the function test
in commands.janet
like so:
(defn test
[& args]
(setdyn :test-args args)
(local-rule "test"))
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?
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.
eg:
runs only that test.