Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Non-string test names crash exunit indexer #676

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.ExUnit do
end

# Test block test "test name" do ... or test "test name", arg do
def extract({:test, _, [{_, _, [test_name]} | _] = args} = test, %Reducer{} = reducer) do
def extract({:test, _, [{_, _, [test_name]} | _] = args} = test, %Reducer{} = reducer)
when is_binary(test_name) do
{:ok, module} = Analyzer.current_module(reducer.analysis, Reducer.position(reducer))
arity = arity_for(args)
module_name = Formats.module(module)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,10 +246,10 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.ExUnitTest do
test "when pending" do
{:ok, [test], doc} =
~q[
defmodule SomeTest do
test "my test"
end
]
defmodule SomeTest do
test "my test"
end
]
|> index_definitions()

assert test.type == :ex_unit_test
Expand All @@ -262,11 +262,11 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.ExUnitTest do
test "when they only have a block" do
{:ok, [test], doc} =
~q[
defmodule SomeTest do
test "my test" do
defmodule SomeTest do
test "my test" do
end
end
end
]
]
|> index_definitions()

assert test.type == :ex_unit_test
Expand All @@ -279,11 +279,11 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.ExUnitTest do
test "when they have a block and a context" do
{:ok, [test], doc} =
~q[
defmodule SomeTest do
test "my test", context do
defmodule SomeTest do
test "my test", context do
end
end
end
]
]
|> index_definitions()

assert test.type == :ex_unit_test
Expand All @@ -301,12 +301,12 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.ExUnitTest do
test "describe contains tests" do
{:ok, [module, describe, test], _} =
~q[
defmodule SomeTexst do
describe "outer" do
test "my test", context do
end
end
end
defmodule SomeTexst do
describe "outer" do
test "my test", context do
end
end
end
]
|> index_with_structure()

Expand All @@ -320,4 +320,18 @@ defmodule Lexical.RemoteControl.Search.Indexer.Extractors.ExUnitTest do
assert test.block_id == describe.id
end
end

describe "things that it will miss" do
test "quoted test cases" do
{:ok, [], _} =
~q[
quote do
test unquote(test_name) do
end
end
]
|> in_a_module()
|> index_definitions()
end
end
end
Loading