Skip to content

Commit

Permalink
Add a test case
Browse files Browse the repository at this point in the history
Signed-off-by: Alpha DIALLO <[email protected]>
  • Loading branch information
moyodiallo committed Nov 7, 2024
1 parent 64bcacf commit 6126ca9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 3 deletions.
7 changes: 4 additions & 3 deletions bin/lock_dev_tool.ml
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,10 @@ let lock_ocamlformat () =
let lock_odoc () = lock_dev_tool Odoc None
let lock_ocamllsp () = lock_dev_tool Ocamllsp None

let lock_tools (tools : Dune_pkg.Dev_tool.t list) =
List.map tools ~f:(function
| Dune_pkg.Dev_tool.Odoc -> lock_odoc ()
let lock_tools tools =
List.map tools ~f:(fun (tool : Dune_pkg.Dev_tool.t) ->
match tool with
| Odoc -> lock_odoc ()
| Ocamllsp -> lock_ocamllsp ()
| Ocamlformat -> lock_ocamlformat ())
;;
12 changes: 12 additions & 0 deletions test/blackbox-tests/test-cases/pkg/helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,15 @@ print_source() {
solve() {
make_project $@ | solve_project
}

make_mock_tool_package() {
package=$1
binary=$2
mkpkg $package <<EOF
install: [
[ "sh" "-c" "echo '#!/bin/sh' > %{bin}%/$binary" ]
[ "sh" "-c" "echo 'echo hello from fake $binary' >> %{bin}%/$binary" ]
[ "sh" "-c" "chmod a+x %{bin}%/$binary" ]
]
EOF
}
57 changes: 57 additions & 0 deletions test/blackbox-tests/test-cases/pkg/tools-install.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
$ . ./helpers.sh

Test for "dune tools install" command which installs all the available dev-tools .
The command locks and builds those dev-tools.

$ mkrepo
$ make_mock_tool_package odoc odoc
$ make_mock_tool_package ocaml-lsp-server ocamllsp
$ make_mock_tool_package ocamlformat ocamlformat
$ mkpkg ocaml 5.2.0

Each dev-tool has it own lock-dir
$ cat > dune-workspace <<EOF
> (lang dune 3.16)
> (lock_dir
> (path "dev-tools.locks/odoc")
> (repositories mock))
> (lock_dir
> (path "dev-tools.locks/ocamlformat")
> (repositories mock))
> (lock_dir
> (path "dev-tools.locks/ocaml-lsp-server")
> (repositories mock))
> (lock_dir
> (repositories mock))
> (repository
> (name mock)
> (source "file://$(pwd)/mock-opam-repository"))
> EOF

$ cat > dune-project <<EOF
> (lang dune 3.16)
> (package
> (name foo)
> (depends ocaml))
> EOF

Building dev-tool requires the project been locked.
$ dune pkg lock
Solution for dune.lock:
- ocaml.5.2.0

$ DUNE_CONFIG__LOCK_DEV_TOOL=enabled dune tools install
Solution for dev-tools.locks/ocamlformat:
- ocamlformat.0.0.1
Solution for dev-tools.locks/odoc:
- ocaml.5.2.0
- odoc.0.0.1
Solution for dev-tools.locks/ocaml-lsp-server:
- ocaml.5.2.0
- ocaml-lsp-server.0.0.1

Check, if the dev-tools are built.
$ ls ./_build/_private/default/.dev-tool
ocaml-lsp-server
ocamlformat
odoc

0 comments on commit 6126ca9

Please sign in to comment.