Skip to content

Commit

Permalink
chore: write fixtures at runtime (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg authored Jul 3, 2023
1 parent f7df2a0 commit d0ae204
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 108 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ jobs:
- name: Start EPMD
run: epmd -daemon

- name: Compile test project
run: (cd test/support/project && mix deps.get && mix compile)

- name: Compile
env:
MIX_ENV: test
Expand Down
4 changes: 4 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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
[
Expand Down
13 changes: 12 additions & 1 deletion test/next_ls/runtime_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
defmodule NextLs.RuntimeTest do
use ExUnit.Case, async: true
import NextLS.Support.Utils

@moduletag :tmp_dir

Expand All @@ -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 ->
Expand Down
42 changes: 38 additions & 4 deletions test/next_ls_test.exs
Original file line number Diff line number Diff line change
@@ -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"))

Expand Down Expand Up @@ -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 ==
Expand Down
4 changes: 0 additions & 4 deletions test/support/project/.formatter.exs

This file was deleted.

26 changes: 0 additions & 26 deletions test/support/project/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions test/support/project/README.md

This file was deleted.

6 changes: 0 additions & 6 deletions test/support/project/lib/bar.ex

This file was deleted.

9 changes: 0 additions & 9 deletions test/support/project/lib/code_action.ex

This file was deleted.

2 changes: 0 additions & 2 deletions test/support/project/lib/foo.ex

This file was deleted.

5 changes: 0 additions & 5 deletions test/support/project/lib/project.ex

This file was deleted.

25 changes: 0 additions & 25 deletions test/support/project/mix.exs

This file was deleted.

2 changes: 0 additions & 2 deletions test/support/project/mix.lock

This file was deleted.

31 changes: 31 additions & 0 deletions test/support/utils.ex
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d0ae204

Please sign in to comment.