realworldocaml / mdx

Execute code blocks inside your documentation
ISC License
269 stars 45 forks source link

Allow running non-deterministic MDX stanzas using `dune-gen` #366

Closed Leonidas-from-XIV closed 2 years ago

Leonidas-from-XIV commented 2 years ago

There is a number of ways this could be implemented, but for simplicity this just uses the same environment variable as the main executable, but to avoid dependencies it doesn't use the Cmdliner flag.

Closes #365.

Leonidas-from-XIV commented 2 years ago

That's a good point for the future.

Unfortunately that would require us to use a dune version that has either 0.1 support or 0.2 support (the latter is dune 3.0 which is not released yet) unless we want to do a fun thing and declare:

dune | dune {>= "3.0" & with-test}
emillon commented 2 years ago

Looks good to me!

This still needs a change on the dune side to declare the env var dependency right? At some point it would be nice to include dune stanza tests here as well so we're confident we don't break the compat with dune on those features!

That's done in https://github.com/ocaml/dune/pull/5391. This only affects stanza 0.2 which is unreleased at the moment.

NathanReb commented 2 years ago

That's a good point indeed.

On the other hand I think that it wouldn't be too bad for MDX to require the version of dune that integrates well with it. We don't really offer good support for running MDX on your own anyway.

We'd need to look into the implications more carefully but on principle, I think it could work.

emillon commented 2 years ago

We can also test this by doing what the stanza does by hand, ie something like that in a cram test:

$ mdx dune-gen > t.ml
$ cat > dune <<EOF
> (executable ...)
$ dune exec ...

It's an e2e test of dune-gen, not of the dune stanza, but this ensures that this contract works.