Skip to content

Commit

Permalink
test: organize tests into separate files
Browse files Browse the repository at this point in the history
  • Loading branch information
mhanberg committed Aug 9, 2023
1 parent 218d4d0 commit 18a57f7
Show file tree
Hide file tree
Showing 5 changed files with 220 additions and 141 deletions.
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ defmodule NextLS.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:gen_lsp, "~> 0.5"},
{:gen_lsp, "~> 0.6"},
{:esqlite, "~> 0.8.6"},
{:styler, "~> 0.8", only: :dev},
{:ex_doc, ">= 0.0.0", only: :dev},
Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"esqlite": {:hex, :esqlite, "0.8.6", "7852d506eb12bd519c1084f03c467f364f8ddff69227154e5e6df9cc6346fbbf", [:rebar3], [], "hexpm", "607e45f4da42601d8f530979417f57a4cd629ab49085891849302057e68ea188"},
"ex_doc": {:hex, :ex_doc, "0.29.4", "6257ecbb20c7396b1fe5accd55b7b0d23f44b6aa18017b415cb4c2b91d997729", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2c6699a737ae46cb61e4ed012af931b57b699643b24dabe2400a8168414bc4f5"},
"finch": {:hex, :finch, "0.16.0", "40733f02c89f94a112518071c0a91fe86069560f5dbdb39f9150042f44dcfb1a", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.3", [hex: :mint, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.4 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:nimble_pool, "~> 0.2.6 or ~> 1.0", [hex: :nimble_pool, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f660174c4d519e5fec629016054d60edd822cdfe2b7270836739ac2f97735ec5"},
"gen_lsp": {:hex, :gen_lsp, "0.5.0", "463d25c2b81f64b95667e1e6fa9bf2a4ed00896f5e9abe2965bc50edeebae747", [:mix], [{:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:schematic, "~> 0.2.1", [hex: :schematic, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.3.0", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "6d40e2315bd2206cb0e40e93c5d58b28ab15787214fea1066f6561df783ef7c9"},
"gen_lsp": {:hex, :gen_lsp, "0.6.0", "6292627ec3e18a6cb026d00a1c63db3548ac4afc37d04018ea28fb621a69d0a7", [:mix], [{:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.5 or ~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:schematic, "~> 0.2.1", [hex: :schematic, repo: "hexpm", optional: false]}, {:typed_struct, "~> 0.3.0", [hex: :typed_struct, repo: "hexpm", optional: false]}], "hexpm", "676c3e1a442f3ea5fba94e67ea798a595385280dc99d509f695a78f45df515d4"},
"hpax": {:hex, :hpax, "0.1.2", "09a75600d9d8bbd064cdd741f21fc06fc1f4cf3d0fcc335e5aa19be1a7235c84", [:mix], [], "hexpm", "2c87843d5a23f5f16748ebe77969880e29809580efdaccd615cd3bed628a8c13"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
Expand Down
117 changes: 117 additions & 0 deletions test/next_ls/diagnostics_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
defmodule NextLS.DiagnosticsTest do
use ExUnit.Case, async: true

import GenLSP.Test
import NextLS.Support.Utils

@moduletag :tmp_dir
@moduletag root_paths: ["my_proj"]
setup %{tmp_dir: tmp_dir} do
File.mkdir_p!(Path.join(tmp_dir, "my_proj/lib"))
File.write!(Path.join(tmp_dir, "my_proj/mix.exs"), mix_exs())
[cwd: tmp_dir]
end

setup %{tmp_dir: tmp_dir} do
File.write!(Path.join(tmp_dir, "my_proj/lib/bar.ex"), """
defmodule Bar do
defstruct [:foo]
def foo(arg1) do
end
end
""")

File.write!(Path.join(tmp_dir, "my_proj/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, "my_proj/lib/foo.ex"), """
defmodule Foo do
end
""")

File.write!(Path.join(tmp_dir, "my_proj/lib/project.ex"), """
defmodule Project do
def hello do
:world
end
end
""")

File.rm_rf!(Path.join(tmp_dir, ".elixir-tools"))

:ok
end

setup :with_lsp

test "publishes diagnostics once the client has initialized", %{client: client, cwd: cwd} = context do
assert :ok == notify(client, %{method: "initialized", jsonrpc: "2.0", params: %{}})
assert_request(client, "client/registerCapability", fn _params -> nil end)

assert_notification "window/logMessage", %{
"message" => "[NextLS] NextLS v" <> _,
"type" => 4
}

title = "Initializing NextLS runtime for folder #{context.module}-my_proj..."

assert_notification "$/progress", %{
"value" => %{"kind" => "begin", "title" => ^title}
}

message = "NextLS runtime for folder #{context.module}-my_proj has initialized!"

assert_notification "$/progress", %{
"value" => %{
"kind" => "end",
"message" => ^message
}
}

assert_notification "$/progress", %{"value" => %{"kind" => "begin", "title" => "Compiling..."}}

assert_notification "$/progress", %{
"value" => %{
"kind" => "end",
"message" => "Compiled!"
}
}

for file <- ["bar.ex"] do
uri =
to_string(%URI{
host: "",
scheme: "file",
path: Path.join([cwd, "my_proj/lib", file])
})

char = if Version.match?(System.version(), ">= 1.15.0"), do: 10, else: 0

assert_notification "textDocument/publishDiagnostics", %{
"uri" => ^uri,
"diagnostics" => [
%{
"source" => "Elixir",
"severity" => 2,
"message" =>
"variable \"arg1\" is unused (if the variable is not meant to be used, prefix it with an underscore)",
"range" => %{
"start" => %{"line" => 3, "character" => ^char},
"end" => %{"line" => 3, "character" => 999}
}
}
]
}
end
end
end
Loading

0 comments on commit 18a57f7

Please sign in to comment.