diff --git a/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-basic.t b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-basic.t new file mode 100644 index 00000000000..81de4661ec6 --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-basic.t @@ -0,0 +1,32 @@ +Test that the "dune tools exec ocamllsp" command causes ocamllsp to be +locked, built and run when the command is run from a dune project with +a lockdir containing an "ocaml" lockfile. + + $ . ../helpers.sh + $ . ./helpers.sh + + $ mkrepo + $ make_mock_ocamllsp_package + $ mkpkg ocaml 5.2.0 + + $ setup_ocamllsp_workspace + + $ cat > dune-project < (lang dune 3.16) + > + > (package + > (name foo) + > (allow_empty)) + > EOF + + $ make_lockdir + $ cat > dune.lock/ocaml.pkg < (version 5.2.0) + > EOF + + $ dune tools exec ocamllsp + Solution for dev-tools.locks/ocaml-lsp-server: + - ocaml.5.2.0 + - ocaml-lsp-server.0.0.1 + Running 'ocamllsp' + hello from fake ocamllsp diff --git a/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-lock-dir.t b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-lock-dir.t new file mode 100644 index 00000000000..3f6c5dc7cdf --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-lock-dir.t @@ -0,0 +1,15 @@ +Exercise the behaviour of "dune tools exec ocamllsp" when run in a +dune project with no lockdir. + + $ cat > dune-project < (lang dune 3.16) + > + > (package + > (name foo) + > (allow_empty)) + > EOF + + $ dune tools exec ocamllsp + Error: Unable to load the lockdir for the default build context. + Hint: Try running 'dune pkg lock' + [1] diff --git a/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-ocaml-lockfile.t b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-ocaml-lockfile.t new file mode 100644 index 00000000000..227b228e372 --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-no-ocaml-lockfile.t @@ -0,0 +1,20 @@ +Exercise the behaviour of "dune tools exec ocamllsp" when the lockdir +doesn't contain a lockfile for the "ocaml" package. + + $ . ../helpers.sh + + $ cat > dune-project < (lang dune 3.16) + > + > (package + > (name foo) + > (allow_empty)) + > EOF + + $ make_lockdir + + $ dune tools exec ocamllsp + Error: The lockdir doesn't contain a lockfile for the package "ocaml". + Hint: Add a dependency on "ocaml" to one of the packages in dune-project and + then run 'dune pkg lock' + [1] diff --git a/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-outside-dune-project.t b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-outside-dune-project.t new file mode 100644 index 00000000000..b4c444d45ef --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-outside-dune-project.t @@ -0,0 +1,17 @@ +Exercise the behaviour of "dune tools exec ocamllsp" when run outside +of a dune project. + + +This is necessary for dune to act as it normally would outside of a +dune workspace. + $ unset INSIDE_DUNE + +Run the wrapper command from a temporary directory. With INSIDE_DUNE +unset dune would otherwise pick up the dune project itself as the +current workspace. + $ cd $(mktemp -d) + + $ dune tools exec ocamllsp + Error: Unable to run ocamllsp as a dev-tool because you don't appear to be + inside a dune project. + [1] diff --git a/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-relock-on-ocaml-version-change.t b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-relock-on-ocaml-version-change.t new file mode 100644 index 00000000000..eaa8e2ad6a8 --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamllsp/dev-tool-ocamllsp-relock-on-ocaml-version-change.t @@ -0,0 +1,63 @@ +Test that if the version of the "ocaml" package in the project's +lockdir changes then the ocamllsp dev tool is re-locked to be built +with the version of the ocaml compiler now in the project's +lockdir. This is necessary because ocamllsp must be compiled with the +same version of the ocaml compiler as the code that it's analyzing. + + $ . ../helpers.sh + $ . ./helpers.sh + + $ mkrepo + $ make_mock_ocamllsp_package + $ mkpkg ocaml 5.2.0 + $ mkpkg ocaml 5.1.0 + + $ setup_ocamllsp_workspace + + $ cat > dune-project < (lang dune 3.16) + > + > (package + > (name foo) + > (allow_empty)) + > EOF + + $ make_lockdir + $ cat > dune.lock/ocaml.pkg < (version 5.2.0) + > EOF + +Initially ocamllsp will be depend on ocaml.5.2.0 to match the project. + $ dune tools exec ocamllsp + Solution for dev-tools.locks/ocaml-lsp-server: + - ocaml.5.2.0 + - ocaml-lsp-server.0.0.1 + Running 'ocamllsp' + hello from fake ocamllsp + $ cat dev-tools.locks/ocaml-lsp-server/ocaml.pkg + (version 5.2.0) + +We can re-run "dune tools exec ocamllsp" without relocking or rebuilding. + $ dune tools exec ocamllsp + Running 'ocamllsp' + hello from fake ocamllsp + +Change the version of ocaml that the project depends on. + $ cat > dune.lock/ocaml.pkg < (version 5.1.0) + > EOF + +Running "dune tools exec ocamllsp" causes ocamllsp to be relocked and rebuilt +before running. Ocamllsp now depends on ocaml.5.1.0. + $ dune tools exec ocamllsp + The version of the compiler package ("ocaml") in this project's lockdir has + changed to 5.1.0 (formerly the compiler version was 5.2.0). The dev-tool + "ocaml-lsp-server" will be re-locked and rebuilt with this version of the + compiler. + Solution for dev-tools.locks/ocaml-lsp-server: + - ocaml.5.1.0 + - ocaml-lsp-server.0.0.1 + Running 'ocamllsp' + hello from fake ocamllsp + $ cat dev-tools.locks/ocaml-lsp-server/ocaml.pkg + (version 5.1.0) diff --git a/test/blackbox-tests/test-cases/pkg/ocamllsp/dune b/test/blackbox-tests/test-cases/pkg/ocamllsp/dune new file mode 100644 index 00000000000..552dd6cf4a9 --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamllsp/dune @@ -0,0 +1,3 @@ +(cram + (deps helpers.sh) + (applies_to :whole_subtree)) diff --git a/test/blackbox-tests/test-cases/pkg/ocamllsp/helpers.sh b/test/blackbox-tests/test-cases/pkg/ocamllsp/helpers.sh new file mode 100644 index 00000000000..89a12023640 --- /dev/null +++ b/test/blackbox-tests/test-cases/pkg/ocamllsp/helpers.sh @@ -0,0 +1,27 @@ +# Create a dune-workspace file with mock repos set up for the main +# project and the ocamllsp lockdir. +setup_ocamllsp_workspace() { + cat > dune-workspace < %{bin}%/ocamllsp" ] + [ "sh" "-c" "echo 'echo hello from fake ocamllsp' >> %{bin}%/ocamllsp" ] + [ "sh" "-c" "chmod a+x %{bin}%/ocamllsp" ] +] +EOF +}