feature: allow specifying which shell to use for cram test#8134
feature: allow specifying which shell to use for cram test#8134haochenx wants to merge 33 commits intoocaml:mainfrom
Conversation
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
|
@rgrinberg do you mind to take a look at the design and implementation of this PR @johnridesabike do you think this approach satisfy your use case? |
| (cram) | ||
|
|
||
| (cram | ||
| (enabled_if %{bin-available:zsh}) |
There was a problem hiding this comment.
If you do this, you will have to add zsh to the CI so we can run the tests. Probably best if you restrict to unix too.
There was a problem hiding this comment.
I think the macOS CI environment should have zsh available.
What's the additional benefits to add restriction to unix in addition to checking whether zsh exists?
There was a problem hiding this comment.
Well actually I'm thinking that we shouldn't be using bin-available. If we miss putting zsh in the CI then this test will never be run, and it might surprise some other devs when they have zsh if this test is broken. So we have three choices:
- Either we make
zshmandatory (hence the unix restriction) so that the test is always seen to run. We can therefore catch any changes in CI. - We make a dummy
zshor any other shell, just to check how it works. (echo would probably work) - We don't test zsh.
There was a problem hiding this comment.
I see. I did have similar feeling when I added the test, but I ended up with adding them since I wanted to have some non-artificial tests.
But given that your concern is solid, I am in favor of doing (1) or (3) as you suggested. I don't think (2) is a good option since it seems that dune's cram test executor expects the shell at least have (a) output redirecting and (b) script sourcing features and making a convincing dummy zsh above the level of what is already done in shell-opt.t requires some significant efforts.
Regarding (1), I'm in general in favor of it, but since it involves changing the CI configuration, I don't think I should make the call.
If the maintainers of dune is not in favor of (1), then I think we should take (3) as missing this test case isn't crucial for the completeness of testing the feature added in this PR.
There was a problem hiding this comment.
(thank you for taking a look btw!)
There was a problem hiding this comment.
How should we reach to a consensus here?
|
This current implementation would certainly be helpful, but using an environment variable or CLI argument would be preferable for my use case. My goal is to check that my tests are shell-agnostic, so I'd like to run them in something like dash locally (or in multiple different shells), but allow other users/CIs run them in whatever they have installed. I wouldn't want to commit a Dune rule that requires using a specific shell. |
|
It's probably not what you want, but since you can refer to environment variable, you could probably achieve what you wanted to achieve. For example, you can use Yet it is indeed not as elegant. I will probably look into using an environment variable, but I think we need to set the expected behavior straight first I don't think I will be adding it in this PR. |
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen Kotoi-Xie <hx@kxc.inc>
Wouldn't this require all users to have that environment variable set in order to run cram tests? If we can only configure it in a Dune file, then I'll just add a |
The I agree that being able to specify the shell elegantly via environment variable is a great feature. I will think about how the spec. |
|
I'm thinking about to add two environment variables that matters for dune:
As it comes for determining the actual path for
Comments are welcomed. |
|
I would go for something more general. We have |
Sounds better! I agree that this change will go beyond the scope of this PR. I'm happy to submit another PR to implement that. If my understanding is correct, the place also need to be modify should be the following? dune/src/dune_engine/action_exec.ml Lines 289 to 301 in 4256431 |
| sh.ml | ||
| $ cat foo.cram.corrected | ||
| $ echo "foo from foo.cram" | ||
| ***** UNREACHABLE ***** |
There was a problem hiding this comment.
Why is this and the rest unreachable?
There was a problem hiding this comment.
My guess is that when creating foo.cram, the $ is interpreted by the parent shell. You can use << 'EOF' line 69 to prevent this.
There was a problem hiding this comment.
These tests try to see whether the PATH environment variable is regarded by making our own bash and sh compiled from bash.ml and sh.ml. But since those are nowhere near complete shell implementation, they do not handle stdout redirection directives (like echo hello > file.txt), which cram_exec relies on to capture the output. Therefore the cram test executor will think the cram test crashed and include ***** UNREACHABLE ***** here.
We know our own mocked version of bash and sh are invoked here by looking at https://github.com/ocaml/dune/pull/8134/files/e2913128ca6046e24b2dbfa7255be40588ce58d1#diff-0484438795287a34ad56a4a530a816caea0a5480e23fffb006408f39591b35e6R74 and https://github.com/ocaml/dune/pull/8134/files/e2913128ca6046e24b2dbfa7255be40588ce58d1#diff-0484438795287a34ad56a4a530a816caea0a5480e23fffb006408f39591b35e6R95
There was a problem hiding this comment.
This is less than ideal but I didn't come up with other ways to perform this test.
|
The problem with the special symbols is twofold:
Do you mean the dependency language or for allowing percent forms? I assume you meant the latter because that's the only thing that makes sense in this context. I think we should allow for expanding dune's percent forms and we should also allow command line arguments as well. For example, one should be able to: Dune has a single way of resolving binaries so the question regarding Once this is resolved and you remove the optional argument, this PR is good to go. |
|
@rgrinberg @emillon thanks for having a look and point out a direction. I will take sometime later this week to re-look at this issue and bring it forward. |
|
Unfortunately (and my apologies for that) I didn't get time to work on this PR last week.. I will see whether I can find some time this weekend. |
Signed-off-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
dd8079a to
9dbb040
Compare
Signed-off-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
Signed-off-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
| type t = int * int | ||
|
|
||
| let latest = 3, 11 | ||
| let latest = 3, 12 |
There was a problem hiding this comment.
not sure whether this should be in this PR
Signed-off-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
| | Custom_shell { prog; args } -> | ||
| let shell_deps, sandbox = Dep_conf_eval.unnamed ~expander [ File prog ] in | ||
| let dir = Path.build dir in | ||
| let expand_arg sw = | ||
| let open Action_builder.O in | ||
| let+ v = | ||
| String_expander.Action_builder.expand | ||
| sw | ||
| ~dir | ||
| ~mode:Many | ||
| ~f:(Expander.expand_pform expander) | ||
| in | ||
| Value.L.to_strings v ~dir | ||
| in | ||
| let shell = | ||
| let open Action_builder.O in | ||
| let+ shell_args = Action_builder.all (List.map args ~f:expand_arg) | ||
| and+ shell_prog = | ||
| Expander.( | ||
| With_deps_if_necessary.expand_single_path expander prog | ||
| |> Deps.action_builder) | ||
| in | ||
| shell_prog, List.concat shell_args | ||
| in | ||
| return ~shell_deps ~sandbox (Some shell) | ||
| in |
There was a problem hiding this comment.
not sure whether this is the best way to expand the prog path and arg here
|
I have addressed #8134 (comment) except for @rgrinberg do you think |
Signed-off-by: Haochen M. Kotoi-Xie <hx@kxc.inc>
I can give it a try myself |
|
@rgrinberg regarding |
|
Thanks @haochenx.
|
|
@rgrinberg thanks for the pointers. last time I tried to grep for Using
My take is that it will be confusing for the users, as it's not strictly the "input file", as the script executed is quite heavily processed snippets of the original (I estimate that I will attempt to implement |
Signed-off-by: Christine Rose <christinerose@users.noreply.github.com>
Allow explicitly using `bash` as the shell instead of `sh`. Extracted and/or loosely inspired form #8134 --------- Signed-off-by: Rudi Grinberg <me@rgrinberg.com>
|
We ended up providing |
Design
Add
(shell ..)option to the(cram)stanza and user action. The syntax is described below:(shell :system)will use the system shell (aka/usr/bin/env sh)(shell :bash)will use bash (aka/usr/bin/env bash)(shell <dep>)will resolve<dep>(that may contain variables) as a path to an executable and use it as the shell(shell %{bin:zsh})will use zsh as the shell(shell %{bin:dash})will use dash as the shellDiscussions
dune rulesdune rulesdoes not output entries regarding cram tests so we can probably safely assumethat currently no external tools depends on the encoded action spec
Sub-tasks
dune/src/dune_rules/cram/cram_exec.mli
Lines 3 to 7 in 80a5248
dune/src/dune_rules/cram/cram_exec.mli
Lines 14 to 19 in 80a5248
(cram (shell <shell_spec>))where<shell_spec>could be:system, which is interpreted asSystem_shell(akaenv sh):bash, which is interpreted asBash_shell(akaenv bash)<dep>, which is interpreted the same way as those in(deps <dep>)test/blackbox-tests/test-cases/cram/{shell-opt,shell-opt-zsh}.tadded)test/blackbox-tests/test-cases/cram/cram-action-shell-opt.tadded)test/blackbox-tests/test-cases/cram/shell-opt-dune-lang-version.tadded)Optional?
env sh) as requested in Specify a specific shell to execute cram test commands #7829