CodeLens Run Test In Terminal doesn't work (on Windows) due to incorrectly escaped Regex
Description
Ruby LSP Information
VS Code Version
1.104.1
Ruby LSP Extension Version
0.9.32
Ruby LSP Server Version
0.26.1
Ruby LSP Add-ons
- RuboCop (unknown)
Ruby Version
3.1.4
Ruby Version Manager
none
Installed Extensions
Click to expand
- Lisp (0.1.12)
- code-spell-checker (4.2.6)
- color-highlight (2.8.0)
- errorlens (3.26.0)
- exercism-cli (0.2.2)
- gitlens (17.4.1)
- jikiscript (1.0.0)
- postcss (1.0.9)
- prettier-vscode (11.0.0)
- rails (0.22.0)
- rainbow-csv (3.22.0)
- react-native-ide (1.3.0)
- remote-explorer (0.5.0)
- remote-ssh (0.120.0)
- remote-ssh-edit (0.87.0)
- ruby-lsp (0.9.32)
- vscode-eslint (3.0.16)
- vscode-expo-tools (1.6.1)
- vscode-github-actions (0.27.2)
- vscode-graphql (0.13.2)
- vscode-graphql-syntax (1.3.8)
- vscode-tailwindcss (0.14.26)
- vscode-versionlens (1.22.4)
- vscode-yaml (1.18.0)
- vscode-zipfs (3.0.0)
- vsliveshare (1.0.5959)
Ruby LSP Settings
Click to expand
Workspace
{
"indexing": {
"includedPatterns": [
"lib/**/*.rb",
"test/**/*.rb"
]
}
}
User
{
"enabledFeatures": {
"codeActions": true,
"diagnostics": true,
"documentHighlights": true,
"documentLink": true,
"documentSymbols": true,
"foldingRanges": true,
"formatting": false,
"hover": true,
"inlayHint": true,
"onTypeFormatting": false,
"selectionRanges": true,
"semanticHighlighting": true,
"completion": true,
"codeLens": true,
"definition": true,
"workspaceSymbol": true,
"signatureHelp": true,
"typeHierarchy": true
},
"featuresConfiguration": {},
"addonSettings": {},
"rubyVersionManager": {
"identifier": "none"
},
"customRubyCommand": "",
"formatter": "auto",
"linters": null,
"bundleGemfile": "",
"testTimeout": 30,
"branch": "",
"pullDiagnosticsOn": "both",
"useBundlerCompose": false,
"bypassTypechecker": false,
"rubyExecutablePath": "",
"indexing": {
"includedPatterns": [
"lib/**/*.rb",
"test/**/*.rb"
]
},
"erbSupport": true,
"featureFlags": {},
"sigOpacityLevel": "1"
}
Reproduction steps
- Start the Ruby LSP using VS Code
- Open a Ruby test file with a single test
- Click "Run Test in Terminal"
- Terminal reports no tests ran
class TestNothing < Minitest::Test
def test_nothing
refute_nil true
end
end
The full file can be tested:
C:\Users\Derk-Jan\...snip...>bundle exec ruby -rC:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.26.1/lib/ruby_lsp/test_reporters/minitest_reporter.rb -rC:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.26.1/lib/ruby_lsp/test_reporters/test_unit_reporter.rb -Itest c:/Users/Derk-Jan/...snip.../test/test_nothing.rb --name "/^TestNothing(#|::)/"
Run options: --name "/^TestNothing(#|::)/" --seed 56682
# Running:
.
Finished in 0.015750s, 63.4917 runs/s, 63.4917 assertions/s.
Simplifying this command we see:
bundle exec ruby -rPathToLspProvidedReporter.rb -rPathToAnotherLspProvidedReporter.rb -Itest PathToFile --name "/^TestClassName(#|::)/"
There are three paths:
- PathToLspProvidedReporter
- PathToAnotherLspProvidedReporter
- PathToFile
There is one regex matcher:
- /^TestNothing(#|::)/
For a single test, we get:
C:\Users\Derk-Jan\...snip...>bundle exec ruby -rC:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.26.1/lib/ruby_lsp/test_reporters/minitest_reporter.rb -rC:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/ruby-lsp-0.26.1/lib/ruby_lsp/test_reporters/test_unit_reporter.rb -Itest c:/Users/Derk-Jan/...snip.../test_nothing.rb --name "/^TestNothing#test_nothing\$/"
Run options: --name "/^TestNothing#test_nothing\\$/" --seed 33369
[...]
Finished in 0.010229s, 0.0000 runs/s, 0.0000 assertions/s.
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
Nothing ran for filter: /^TestNothing#test_nothing\$/
The issue can be seen in the --name argument:
/^TestNothing#test_nothing\\$/
Removing the extra slash makes the entire command work again.
https://github.com/Shopify/ruby-lsp/blob/369e2d1ba7c766e70273d26bf61240d2f13ee17a/test/requests/resolve_test_commands_test.rb#L70-L71
The test also seems to test for this incorrect behaviour (as in: it's being tested as if this is correct).
Thank you for the bug report! Does removing all backslashes before the $ still work on Windows? I mean like this /^TestNothing#test_nothing$/.
For Linux and MacOS, escaping the $ is important because Fish (and potentially other shells) assigns special meaning to it.
Yes, that works, that's how I tested it!
According to this command line reference, $ is not special on windows. I do not know what happens on WSL though, but the win check should likely not return true on WSL/WSL2.
Wouldn't escaped $ be \$ though?
This issue is being marked as stale because there was no activity in the last 2 months