diff --git a/lib/ruby_lsp/requests/code_lens.rb b/lib/ruby_lsp/requests/code_lens.rb index 9826c8f834..b353f88b60 100644 --- a/lib/ruby_lsp/requests/code_lens.rb +++ b/lib/ruby_lsp/requests/code_lens.rb @@ -212,11 +212,13 @@ def add_test_code_lens(node, name:, command:, kind:) data: { type: "test_in_terminal", **grouping_data }, ) + shell_escaped_arguments = arguments.clone + shell_escaped_arguments[2] = Shellwords.escape(shell_escaped_arguments[2]) @_response << create_code_lens( node, title: "Debug", command_name: "rubyLsp.debugTest", - arguments: arguments, + arguments: shell_escaped_arguments, data: { type: "debug", **grouping_data }, ) end diff --git a/test/expectations/code_lens/minitest_tests.exp.json b/test/expectations/code_lens/minitest_tests.exp.json index 964c744d39..89fa263855 100644 --- a/test/expectations/code_lens/minitest_tests.exp.json +++ b/test/expectations/code_lens/minitest_tests.exp.json @@ -83,7 +83,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "Test", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /Test/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /Test/", { "start_line": 0, "start_column": 0, @@ -180,7 +180,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "test_public", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /Test\\#test_public/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /Test\\\\\\#test_public/", { "start_line": 5, "start_column": 2, @@ -276,7 +276,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "test_public_command", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /Test\\#test_public_command/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /Test\\\\\\#test_public_command/", { "start_line": 9, "start_column": 9, @@ -372,7 +372,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "test_another_public", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /Test\\#test_another_public/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /Test\\\\\\#test_another_public/", { "start_line": 11, "start_column": 9, @@ -468,7 +468,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "test_public_vcall", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /Test\\#test_public_vcall/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /Test\\\\\\#test_public_vcall/", { "start_line": 17, "start_column": 2, @@ -564,7 +564,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "test_with_q?", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /Test\\#test_with_q\\?/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /Test\\\\\\#test_with_q\\\\\\?/", { "start_line": 19, "start_column": 2, @@ -662,7 +662,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "AnotherTest", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /AnotherTest/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /AnotherTest/", { "start_line": 24, "start_column": 0, @@ -759,7 +759,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "test_public", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /AnotherTest\\#test_public/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /AnotherTest\\\\\\#test_public/", { "start_line": 25, "start_column": 2, @@ -855,7 +855,7 @@ "arguments": [ "/fixtures/minitest_tests.rb", "test_public_2", - "bundle exec ruby -Itest /fixtures/minitest_tests.rb --name /AnotherTest\\#test_public_2/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/minitest_tests.rb\\ --name\\ /AnotherTest\\\\\\#test_public_2/", { "start_line": 31, "start_column": 2, @@ -871,7 +871,5 @@ } } ], - "params": [ - - ] + "params": [] } diff --git a/test/expectations/code_lens/nested_minitest_tests.exp.json b/test/expectations/code_lens/nested_minitest_tests.exp.json index bca0fe26fe..770c99c92d 100644 --- a/test/expectations/code_lens/nested_minitest_tests.exp.json +++ b/test/expectations/code_lens/nested_minitest_tests.exp.json @@ -83,7 +83,7 @@ "arguments": [ "/fixtures/nested_minitest_tests.rb", "ParentTest", - "bundle exec ruby -Itest /fixtures/nested_minitest_tests.rb --name /ParentTest/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/nested_minitest_tests.rb\\ --name\\ /ParentTest/", { "start_line": 0, "start_column": 0, @@ -180,7 +180,7 @@ "arguments": [ "/fixtures/nested_minitest_tests.rb", "test_public", - "bundle exec ruby -Itest /fixtures/nested_minitest_tests.rb --name /ParentTest\\#test_public/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/nested_minitest_tests.rb\\ --name\\ /ParentTest\\\\\\#test_public/", { "start_line": 1, "start_column": 2, @@ -278,7 +278,7 @@ "arguments": [ "/fixtures/nested_minitest_tests.rb", "FirstChildTest", - "bundle exec ruby -Itest /fixtures/nested_minitest_tests.rb --name /FirstChildTest/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/nested_minitest_tests.rb\\ --name\\ /FirstChildTest/", { "start_line": 5, "start_column": 2, @@ -375,7 +375,7 @@ "arguments": [ "/fixtures/nested_minitest_tests.rb", "test_public", - "bundle exec ruby -Itest /fixtures/nested_minitest_tests.rb --name /FirstChildTest\\#test_public/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/nested_minitest_tests.rb\\ --name\\ /FirstChildTest\\\\\\#test_public/", { "start_line": 6, "start_column": 4, @@ -473,7 +473,7 @@ "arguments": [ "/fixtures/nested_minitest_tests.rb", "SecondChildTest", - "bundle exec ruby -Itest /fixtures/nested_minitest_tests.rb --name /SecondChildTest/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/nested_minitest_tests.rb\\ --name\\ /SecondChildTest/", { "start_line": 13, "start_column": 2, @@ -570,7 +570,7 @@ "arguments": [ "/fixtures/nested_minitest_tests.rb", "test_public", - "bundle exec ruby -Itest /fixtures/nested_minitest_tests.rb --name /SecondChildTest\\#test_public/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/nested_minitest_tests.rb\\ --name\\ /SecondChildTest\\\\\\#test_public/", { "start_line": 14, "start_column": 4, @@ -666,7 +666,7 @@ "arguments": [ "/fixtures/nested_minitest_tests.rb", "test_public_again", - "bundle exec ruby -Itest /fixtures/nested_minitest_tests.rb --name /ParentTest\\#test_public_again/", + "bundle\\ exec\\ ruby\\ -Itest\\ /fixtures/nested_minitest_tests.rb\\ --name\\ /ParentTest\\\\\\#test_public_again/", { "start_line": 19, "start_column": 2, @@ -682,7 +682,5 @@ } } ], - "params": [ - - ] + "params": [] } diff --git a/test/requests/code_lens_expectations_test.rb b/test/requests/code_lens_expectations_test.rb index d6f55d2b0c..82fd38053c 100644 --- a/test/requests/code_lens_expectations_test.rb +++ b/test/requests/code_lens_expectations_test.rb @@ -43,6 +43,11 @@ def test_bar; end "bundle exec ruby -Itest /fake.rb --testcase /FooTest/ --name test_bar", T.must(response[4]).command.arguments[2], ) + assert_equal("Debug", T.must(response[5]).command.title) + assert_equal( + "bundle\\ exec\\ ruby\\ -Itest\\ /fake.rb\\ --testcase\\ /FooTest/\\ --name\\ test_bar", + T.must(response[5]).command.arguments[2], + ) end def test_escapes_command_for_debug @@ -67,9 +72,10 @@ def test_bar; end assert_equal("Debug", T.must(response[5]).command.title) assert_equal( - "cd engines/my_engine " \ - "&& bundle exec ruby -Itest /engines/my_engine/fake.rb --testcase /FooTest/ --name test_bar " \ - "&& cd ../..", + "cd\\ engines/my_engine\\ " \ + "\\&\\&\\ bundle\\ exec\\ ruby\\ -Itest\\ /engines/my_engine/fake.rb\\ --testcase\\ /FooTest/\\ " \ + "--name\\ test_bar\\ " \ + "\\&\\&\\ cd\\ ../..", T.must(response[5]).command.arguments[2], ) end