Skip to content

Instantly share code, notes, and snippets.

@Risto-Stevcev
Created March 13, 2020 09:08
Show Gist options
  • Save Risto-Stevcev/9fa99418a11a52a44db2d80bc0a9407f to your computer and use it in GitHub Desktop.
Save Risto-Stevcev/9fa99418a11a52a44db2d80bc0a9407f to your computer and use it in GitHub Desktop.
Migrating mdx from ocaml dune < 2.4.0 to dune >= 2.4.0

This is how the require the lambda_streams package and test the output. Try changing the toplevel output to unit Sync.input:

# #require "lambda_streams";;
# open Lambda_streams;;
# let foo = Sync.pure 123;;
val foo : int Sync.input = <fun>

Get mdx to check it by running dune runtest.

Mdx will check shell files too. To make get it to ignore things like installation instructions, just don't specify that it's sh in the code block.

For example, this will try to run opam install lambda_streams and will rightly fail:

opam install lambda_streams

You need to avoid the sh to make sure mdx ignores it:

opam install lambda_streams
; The new syntax for dune >= 2.4.0
; This `dune` file is in the project root, referencing the `lambda_streams` package from `src/dune`
; In this example, you can get mdx to check the README.md by running `dune runtest`
(mdx
(files README.md)
(packages lambda_streams))
; For dune < 2.4.0
; This dune file is in the src/ folder where the lambda_streams package files live
(library
(name lambda_streams)
(public_name lambda_streams))
(documentation
(mld_files ("index")))
; This is the rule to generate the mdx diff
; This is run using `dune runtest`
; FOO.md is in the src/ folder
; Remove this rule if you're using the new mdx syntax
(rule
(alias runtest)
(deps
(package lambda_streams)
(:x FOO.md))
(action
(progn
(run ocaml-mdx test %{x})
(diff? %{x} %{x}.corrected))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment