diff --git a/mix.exs b/mix.exs index 971edc0c..2abf7be1 100644 --- a/mix.exs +++ b/mix.exs @@ -7,6 +7,7 @@ defmodule NextLS.MixProject do description: "The language server for Elixir that just works", version: "0.4.0", elixir: "~> 1.13", + elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, package: package(), deps: deps(), @@ -27,6 +28,9 @@ defmodule NextLS.MixProject do ] end + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + # Run "mix help deps" to learn about dependencies. defp deps do [ diff --git a/test/next_ls/runtime_test.exs b/test/next_ls/runtime_test.exs index ddb58d75..f78b5b45 100644 --- a/test/next_ls/runtime_test.exs +++ b/test/next_ls/runtime_test.exs @@ -1,5 +1,6 @@ defmodule NextLs.RuntimeTest do use ExUnit.Case, async: true + import NextLS.Support.Utils @moduletag :tmp_dir @@ -9,7 +10,17 @@ defmodule NextLs.RuntimeTest do alias NextLS.Runtime setup %{tmp_dir: tmp_dir} do - File.cp_r!("test/support/project", tmp_dir) + File.write!(Path.join(tmp_dir, "mix.exs"), mix_exs()) + File.mkdir_p!(Path.join(tmp_dir, "lib")) + + File.write!(Path.join(tmp_dir, "lib/bar.ex"), """ + defmodule Bar do + defstruct [:foo] + + def foo(arg1) do + end + end + """) {:ok, logger} = Task.start_link(fn -> diff --git a/test/next_ls_test.exs b/test/next_ls_test.exs index 2bcbaff5..878ee801 100644 --- a/test/next_ls_test.exs +++ b/test/next_ls_test.exs @@ -1,12 +1,48 @@ defmodule NextLSTest do use ExUnit.Case, async: true + import NextLS.Support.Utils @moduletag :tmp_dir import GenLSP.Test setup %{tmp_dir: tmp_dir} do - File.cp_r!("test/support/project", tmp_dir) + File.write!(Path.join(tmp_dir, "mix.exs"), mix_exs()) + File.mkdir_p!(Path.join(tmp_dir, "lib")) + + File.write!(Path.join(tmp_dir, "lib/bar.ex"), """ + defmodule Bar do + defstruct [:foo] + + def foo(arg1) do + end + end + """) + + File.write!(Path.join(tmp_dir, "lib/code_action.ex"), """ + defmodule Foo.CodeAction do + # some comment + + defmodule NestedMod do + def foo do + :ok + end + end + end + """) + + File.write!(Path.join(tmp_dir, "lib/foo.ex"), """ + defmodule Foo do + end + """) + + File.write!(Path.join(tmp_dir, "lib/project.ex"), """ + defmodule Project do + def hello do + :world + end + end + """) File.rm_rf!(Path.join(tmp_dir, ".elixir-tools")) @@ -69,9 +105,7 @@ defmodule NextLSTest do assert_result 2, nil end - test "returns method not found for unimplemented requests", %{ - client: client - } do + test "returns method not found for unimplemented requests", %{client: client} do id = System.unique_integer([:positive]) assert :ok == diff --git a/test/support/project/.formatter.exs b/test/support/project/.formatter.exs deleted file mode 100644 index d2cda26e..00000000 --- a/test/support/project/.formatter.exs +++ /dev/null @@ -1,4 +0,0 @@ -# Used by "mix format" -[ - inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] -] diff --git a/test/support/project/.gitignore b/test/support/project/.gitignore deleted file mode 100644 index 89d8f868..00000000 --- a/test/support/project/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -# The directory Mix will write compiled artifacts to. -/_build/ - -# If you run "mix test --cover", coverage assets end up here. -/cover/ - -# The directory Mix downloads your dependencies sources to. -/deps/ - -# Where third-party dependencies like ExDoc output generated docs. -/doc/ - -# Ignore .fetch files in case you like to edit your project deps locally. -/.fetch - -# If the VM crashes, it generates a dump, let's ignore it too. -erl_crash.dump - -# Also ignore archive artifacts (built via "mix archive.build"). -*.ez - -# Ignore package tarball (built via "mix hex.build"). -project-*.tar - -# Temporary files, for example, from tests. -/tmp/ diff --git a/test/support/project/README.md b/test/support/project/README.md deleted file mode 100644 index dcbbf7c5..00000000 --- a/test/support/project/README.md +++ /dev/null @@ -1,21 +0,0 @@ -# Project - -**TODO: Add description** - -## Installation - -If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `project` to your list of dependencies in `mix.exs`: - -```elixir -def deps do - [ - {:project, "~> 0.1.0"} - ] -end -``` - -Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc) -and published on [HexDocs](https://hexdocs.pm). Once published, the docs can -be found at . - diff --git a/test/support/project/lib/bar.ex b/test/support/project/lib/bar.ex deleted file mode 100644 index 43dea95a..00000000 --- a/test/support/project/lib/bar.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule Bar do - defstruct [:foo] - - def foo(arg1) do - end -end diff --git a/test/support/project/lib/code_action.ex b/test/support/project/lib/code_action.ex deleted file mode 100644 index 7ad0ff63..00000000 --- a/test/support/project/lib/code_action.ex +++ /dev/null @@ -1,9 +0,0 @@ -defmodule Foo.CodeAction do - # some comment - - defmodule NestedMod do - def foo do - :ok - end - end -end diff --git a/test/support/project/lib/foo.ex b/test/support/project/lib/foo.ex deleted file mode 100644 index b921e00e..00000000 --- a/test/support/project/lib/foo.ex +++ /dev/null @@ -1,2 +0,0 @@ -defmodule Foo do -end diff --git a/test/support/project/lib/project.ex b/test/support/project/lib/project.ex deleted file mode 100644 index 2d35018f..00000000 --- a/test/support/project/lib/project.ex +++ /dev/null @@ -1,5 +0,0 @@ -defmodule Project do - def hello do - :world - end -end diff --git a/test/support/project/mix.exs b/test/support/project/mix.exs deleted file mode 100644 index be61cf23..00000000 --- a/test/support/project/mix.exs +++ /dev/null @@ -1,25 +0,0 @@ -defmodule Project.MixProject do - use Mix.Project - - def project do - [ - app: :project, - version: "0.1.0", - elixir: "~> 1.10", - start_permanent: Mix.env() == :prod, - deps: deps() - ] - end - - # Run "mix help compile.app" to learn about applications. - def application do - [ - extra_applications: [:logger] - ] - end - - # Run "mix help deps" to learn about dependencies. - defp deps do - [] - end -end diff --git a/test/support/project/mix.lock b/test/support/project/mix.lock deleted file mode 100644 index 0ac823b3..00000000 --- a/test/support/project/mix.lock +++ /dev/null @@ -1,2 +0,0 @@ -%{ -} diff --git a/test/support/utils.ex b/test/support/utils.ex new file mode 100644 index 00000000..99426482 --- /dev/null +++ b/test/support/utils.ex @@ -0,0 +1,31 @@ +defmodule NextLS.Support.Utils do + def mix_exs do + """ + defmodule Project.MixProject do + use Mix.Project + + def project do + [ + app: :project, + version: "0.1.0", + elixir: "~> 1.10", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [] + end + end + """ + end +end