From 7cbcc851f53d4827d558e40b24a285f6ec310f4e Mon Sep 17 00:00:00 2001 From: Craig Ferguson Date: Tue, 14 Apr 2020 14:28:49 +0200 Subject: [PATCH] Use MDX to test the README example --- .ocamlformat-ignore | 1 - README.md | 34 ++++++++++++++++++---------------- dune | 3 +++ dune-project | 4 +++- examples/readme.ml | 13 +++++-------- irmin-chunk.opam | 2 +- irmin-fs.opam | 2 +- irmin-git.opam | 2 +- irmin-graphql.opam | 2 +- irmin-http.opam | 2 +- irmin-mem.opam | 2 +- irmin-mirage-git.opam | 2 +- irmin-mirage-graphql.opam | 2 +- irmin-mirage.opam | 2 +- irmin-pack.opam | 2 +- irmin-test.opam | 2 +- irmin-unix.opam | 2 +- irmin.opam | 7 ++++++- ppx_irmin.opam | 2 +- 19 files changed, 48 insertions(+), 40 deletions(-) delete mode 100644 .ocamlformat-ignore create mode 100644 dune diff --git a/.ocamlformat-ignore b/.ocamlformat-ignore deleted file mode 100644 index 5927dee845d..00000000000 --- a/.ocamlformat-ignore +++ /dev/null @@ -1 +0,0 @@ -examples/readme.ml diff --git a/README.md b/README.md index 3e0ca9142db..4e1733937ed 100644 --- a/README.md +++ b/README.md @@ -51,19 +51,22 @@ For more information about an individual package consult the [online documentati To install the development version of Irmin, clone this repository and `opam install` the packages inside: - git clone https://github.com/mirage/irmin - cd irmin/ - opam install . + +```sh +git clone https://github.com/mirage/irmin +cd irmin/ +opam install . +``` ### Examples Below is a simple example of setting a key and getting the value out of a Git based, filesystem-backed store. - + ```ocaml open Lwt.Infix (* Irmin store with string contents *) -module Store = Irmin_unix.Git.FS.KV(Irmin.Contents.String) +module Store = Irmin_unix.Git.FS.KV (Irmin.Contents.String) (* Database configuration *) let config = Irmin_git.config ~bare:true "/tmp/irmin/test" @@ -76,17 +79,14 @@ let info fmt = Irmin_unix.info ~author fmt let main = (* Open the repo *) - Store.Repo.v config >>= - + Store.Repo.v config >>= fun repo -> (* Load the master branch *) - Store.master >>= fun t -> - + Store.master repo >>= fun t -> (* Set key "foo/bar" to "testing 123" *) - Store.set_exn t ~info:(info "Updating foo/bar") ["foo"; "bar"] "testing 123" >>= fun () -> - - (* Get key "foo/bar" and print it to stdout *) - Store.get t ["foo"; "bar"] >|= fun x -> - Printf.printf "foo/bar => '%s'\n" x + Store.set_exn t ~info:(info "Updating foo/bar") [ "foo"; "bar" ] "testing 123" + >>= fun () -> + (* Get key "foo/bar" print it to stdout *) + Store.get t [ "foo"; "bar" ] >|= fun x -> Printf.printf "foo/bar => '%s'\n" x (* Run the program *) let () = Lwt_main.run main @@ -94,7 +94,8 @@ let () = Lwt_main.run main The example is contained in `examples/readme.ml`. It can be compiled and executed with dune: -```bash + +```sh $ dune build examples/readme.exe $ dune exec examples/readme.exe foo/bar => 'testing 123' @@ -104,11 +105,12 @@ The `examples/` directory also contains more advanced examples, which can be exe ### Command-line The same thing can also be accomplished using `irmin`, the command-line application installed with `irmin-unix`, by running: -```bash +```sh $ echo "root: ." > irmin.yml $ irmin init $ irmin set foo/bar "testing 123" $ irmin get foo/bar +testing 123 ``` `irmin.yml` allows for `irmin` flags to be set on a per-directory basis. You can also set flags globally using `$HOME/.irmin/config.yml`. Run `irmin help irmin.yml` for further details. diff --git a/dune b/dune new file mode 100644 index 00000000000..b470f0d5232 --- /dev/null +++ b/dune @@ -0,0 +1,3 @@ +(mdx + (files README.md) + (packages irmin irmin-unix)) diff --git a/dune-project b/dune-project index ca8837ae247..3322fc1dad3 100644 --- a/dune-project +++ b/dune-project @@ -1,2 +1,4 @@ -(lang dune 2.0) +(lang dune 2.4) (name irmin) + +(using mdx 0.1) \ No newline at end of file diff --git a/examples/readme.ml b/examples/readme.ml index b1629f1a19a..5f119950095 100644 --- a/examples/readme.ml +++ b/examples/readme.ml @@ -1,6 +1,3 @@ -(* N.B. This excerpt is extracted from project README. Any changes made here - * should be mirrored there. *) - open Lwt.Infix (* Irmin store with string contents *) @@ -17,13 +14,13 @@ let info fmt = Irmin_unix.info ~author fmt let main = (* Open the repo *) - Store.Repo.v config >>= (* Load the master branch *) - Store.master >>= fun t -> + Store.Repo.v config >>= fun repo -> + (* Load the master branch *) + Store.master repo >>= fun t -> (* Set key "foo/bar" to "testing 123" *) - Store.set_exn t ~info:(info "Updating foo/bar") [ "foo"; "bar" ] - "testing 123" + Store.set_exn t ~info:(info "Updating foo/bar") [ "foo"; "bar" ] "testing 123" >>= fun () -> - (* Get key "foo/bar" and print it to stdout *) + (* Get key "foo/bar" print it to stdout *) Store.get t [ "foo"; "bar" ] >|= fun x -> Printf.printf "foo/bar => '%s'\n" x (* Run the program *) diff --git a/irmin-chunk.opam b/irmin-chunk.opam index 55155d8abf4..25ddf26f18f 100644 --- a/irmin-chunk.opam +++ b/irmin-chunk.opam @@ -14,7 +14,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "lwt" "irmin-mem" {with-test & >= "2.0.0"} diff --git a/irmin-fs.opam b/irmin-fs.opam index 7c2100779a4..9a1080aeaa5 100644 --- a/irmin-fs.opam +++ b/irmin-fs.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.03.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "irmin-test" {with-test & >= "2.0.0"} ] diff --git a/irmin-git.opam b/irmin-git.opam index e59d7b97bd5..faeb474cf0a 100644 --- a/irmin-git.opam +++ b/irmin-git.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "git" {>= "2.1.1"} "digestif" {>= "0.7.3"} diff --git a/irmin-graphql.opam b/irmin-graphql.opam index b92541b9f63..3f014676835 100644 --- a/irmin-graphql.opam +++ b/irmin-graphql.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.03.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "graphql" {>= "0.13.0"} "graphql-lwt" {>= "0.13.0"} diff --git a/irmin-http.opam b/irmin-http.opam index 3c401f77523..76defb50da8 100644 --- a/irmin-http.opam +++ b/irmin-http.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "crunch" {>= "2.2.0"} "webmachine" {>= "0.6.0"} "irmin" {>= "2.0.0"} diff --git a/irmin-mem.opam b/irmin-mem.opam index 81a92032ab4..ae3e32729df 100644 --- a/irmin-mem.opam +++ b/irmin-mem.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.03.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "irmin-test" {with-test} ] diff --git a/irmin-mirage-git.opam b/irmin-mirage-git.opam index 49533254485..27c7477919d 100644 --- a/irmin-mirage-git.opam +++ b/irmin-mirage-git.opam @@ -13,7 +13,7 @@ build: [ ] depends: [ - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin-mirage" "irmin-git" {>= "2.0.0"} "git-mirage" {>= "2.1.2"} diff --git a/irmin-mirage-graphql.opam b/irmin-mirage-graphql.opam index 8ba997f74ab..ed4722500ec 100644 --- a/irmin-mirage-graphql.opam +++ b/irmin-mirage-graphql.opam @@ -13,7 +13,7 @@ build: [ ] depends: [ - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin-mirage" "git-mirage" {>= "2.1.1"} "irmin-graphql" diff --git a/irmin-mirage.opam b/irmin-mirage.opam index 588d920bf33..7cfce53c344 100644 --- a/irmin-mirage.opam +++ b/irmin-mirage.opam @@ -13,7 +13,7 @@ build: [ ] depends: [ - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "irmin-mem" {>= "2.0.0"} "ptime" diff --git a/irmin-pack.opam b/irmin-pack.opam index 87bd83571ba..93cd436c468 100644 --- a/irmin-pack.opam +++ b/irmin-pack.opam @@ -14,7 +14,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "index" {>= "1.2.0"} "lwt" diff --git a/irmin-test.opam b/irmin-test.opam index 692d5e2ceb3..ffc187d557f 100644 --- a/irmin-test.opam +++ b/irmin-test.opam @@ -14,7 +14,7 @@ build: [ depends: [ "ocaml" {>= "4.02.3"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.0.0"} "alcotest" {>= "1.0.1"} "mtime" {>= "1.0.0"} diff --git a/irmin-unix.opam b/irmin-unix.opam index c7ab53d8183..068516ae230 100644 --- a/irmin-unix.opam +++ b/irmin-unix.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.01.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "irmin" {>= "2.1.0"} "irmin-mem" {>= "2.0.0"} "irmin-git" {>= "2.0.0"} diff --git a/irmin.opam b/irmin.opam index 2ebf9f2cd44..2034ce22378 100644 --- a/irmin.opam +++ b/irmin.opam @@ -15,7 +15,7 @@ build: [ depends: [ "ocaml" {>= "4.07.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "fmt" {>= "0.8.0"} "uri" {>= "1.3.12"} "jsonm" {>= "1.0.0"} @@ -28,6 +28,7 @@ depends: [ "hex" {with-test} "alcotest" {with-test} "ppx_irmin" {with-test} + "mdx" {with-test & >= "1.7.0"} ] synopsis: """ Irmin, a distributed database that follows the same design principles as Git @@ -39,3 +40,7 @@ variety of backends. Irmin is written in pure OCaml and does not depend on external C stubs; it aims to run everywhere, from Linux, to browsers and Xen unikernels. """ + +pin-depends: [ + ["mdx.dev" "git+https://github.com/realworldocaml/mdx"] +] diff --git a/ppx_irmin.opam b/ppx_irmin.opam index 8466457fb54..c582538dfef 100644 --- a/ppx_irmin.opam +++ b/ppx_irmin.opam @@ -14,7 +14,7 @@ build: [ depends: [ "ocaml" {>= "4.06.0"} - "dune" {>= "2.0.0"} + "dune" {>= "2.4.0"} "ocaml-syntax-shims" "ppxlib" {= "0.12.0"} ]