From 5e286897d31c6eece6d9aaa795ac0391fb293fca Mon Sep 17 00:00:00 2001 From: Jake Date: Fri, 4 Apr 2025 21:04:38 +1100 Subject: [PATCH] Escape carets (^) in Go test regex (#27746) This is a follow up to https://github.com/zed-industries/zed/pull/14821, which escaped `$` but not `^`. This is fine for `bash`, but causes issues with `zsh`. This change escapes the `^`. I tested this against `bash`, `zsh` and `fish` I suspect such escaping would probably need to be done at some shell-specific layer of the code, but for now it seems like the tasks provided by the `ContextProvider` are supposed to be shell agnostic. To reproduce the original issue: 1. Create a Go test file in a module that just contains a single test `TestABC`. 2. Run `zsh -i -c "go test -run ^TestABC\$"` which is what Zed tries to run when the task for a specific Go test is executed. 3. An error that there are no tests to run will be produced even though there is a test. 4. Run `zsh -i -c "go test -run \^TestABC\$"` (note the backslash before ^). 5. The test will run successfully. Example: ``` go package bar import "testing" func TestABC(t *testing.T) {} ``` Release Notes: - fix: Escape the ^ in the Go test -run regex to improve shell compatibility (notably with zsh). --- crates/languages/src/go.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/languages/src/go.rs b/crates/languages/src/go.rs index 7cf7d2ff41..72051feab2 100644 --- a/crates/languages/src/go.rs +++ b/crates/languages/src/go.rs @@ -528,7 +528,7 @@ impl ContextProvider for GoContextProvider { args: vec![ "test".into(), "-run".into(), - format!("^{}\\$", VariableName::Symbol.template_value(),), + format!("\\^{}\\$", VariableName::Symbol.template_value(),), ], tags: vec!["go-test".to_owned()], cwd: package_cwd.clone(), @@ -561,7 +561,7 @@ impl ContextProvider for GoContextProvider { "-v".into(), "-run".into(), format!( - "^{}\\$/^{}\\$", + "\\^{}\\$/\\^{}\\$", VariableName::Symbol.template_value(), GO_SUBTEST_NAME_TASK_VARIABLE.template_value(), ), @@ -580,9 +580,9 @@ impl ContextProvider for GoContextProvider { args: vec![ "test".into(), "-benchmem".into(), - "-run=^$".into(), + "-run='^$'".into(), "-bench".into(), - format!("^{}\\$", VariableName::Symbol.template_value()), + format!("\\^{}\\$", VariableName::Symbol.template_value()), ], cwd: package_cwd.clone(), tags: vec!["go-benchmark".to_owned()], @@ -599,7 +599,7 @@ impl ContextProvider for GoContextProvider { "test".into(), "-fuzz=Fuzz".into(), "-run".into(), - format!("^{}\\$", VariableName::Symbol.template_value(),), + format!("\\^{}\\$", VariableName::Symbol.template_value(),), ], tags: vec!["go-fuzz".to_owned()], cwd: package_cwd.clone(),