Skip to content
Open
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
8 changes: 5 additions & 3 deletions lib/ruby_lsp/listeners/test_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ def handle_test_unit_groups(file_path, groups_and_examples)
command = +"#{COMMAND} -Itest #{Shellwords.escape(file_path)} --testcase \"/^#{group_regex}\\$/\""

unless examples.empty?
command << if examples.length == 1
" --name \"/#{examples[0]}\\$/\""
name_pattern = if examples.length == 1
examples[0]
else
" --name \"/(#{examples.join("|")})\\$/\""
"(#{examples.join("|")})"
end

command << %Q( --name "/#{name_pattern}$/")
end

command
Expand Down
44 changes: 44 additions & 0 deletions test/requests/resolve_test_commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,50 @@ def test_resolve_test_command_specific_examples
end
end

def test_test_unit_examples_do_not_shell_escape_name_patterns
with_server do |server|
server.process_message({
id: 1,
method: "rubyLsp/resolveTestCommands",
params: {
items: [
{
id: "ServerTest",
uri: "file:///test/server_test.rb",
label: "ServerTest",
range: {
start: { line: 0, character: 0 },
end: { line: 30, character: 3 },
},
tags: ["framework:test_unit", "test_group"],
children: [
{
id: "ServerTest#test_server",
uri: "file:///test/server_test.rb",
label: "test_server",
range: {
start: { line: 1, character: 2 },
end: { line: 10, character: 3 },
},
tags: ["framework:test_unit"],
children: [],
},
],
},
],
},
})

result = server.pop_response.response
assert_equal(
[
"#{COMMAND} -Itest /test/server_test.rb --testcase \"/^ServerTest\\$/\" --name \"/test_server$/\"",
],
result[:commands],
)
end
end

def test_resolve_test_command_group_mixed_with_examples
with_server do |server|
server.process_message({
Expand Down
Loading