Fix Go test task when using Git submodules (#17108)
I have found an error running tests in Golang projects that use submodules. This PR fixes the issue by accessing the directory before running the test.  The `commons` in the image is a git submodule in a subfolder inside a parent folder where the workspace is set. Release Notes: - Fixed Go tests not being able to run in case the package (and the `go.mod`) was in a nested folder. Pre-defined Go tasks have been changed to now run in the package's directory. That means `go test ./package -run MyTest` will run in `./package` and execute `go test -run MyTest`. Also, `go test ./...` will run in the package directory, not at the root of the Zed project, which is a small breaking change. In case one wants to run `go test ./...` from the root, one can spawn a manual task that does this.  --------- Co-authored-by: Thorsten Ball <mrnugget@gmail.com>
This commit is contained in:
parent
89632ff5c2
commit
00eed768ce
1 changed files with 14 additions and 9 deletions
|
@ -505,6 +505,12 @@ impl ContextProvider for GoContextProvider {
|
||||||
_: Option<Arc<dyn language::File>>,
|
_: Option<Arc<dyn language::File>>,
|
||||||
_: &AppContext,
|
_: &AppContext,
|
||||||
) -> Option<TaskTemplates> {
|
) -> Option<TaskTemplates> {
|
||||||
|
let package_cwd = if GO_PACKAGE_TASK_VARIABLE.template_value() == "." {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some("$ZED_DIRNAME".to_string())
|
||||||
|
};
|
||||||
|
|
||||||
Some(TaskTemplates(vec![
|
Some(TaskTemplates(vec![
|
||||||
TaskTemplate {
|
TaskTemplate {
|
||||||
label: format!(
|
label: format!(
|
||||||
|
@ -512,26 +518,23 @@ impl ContextProvider for GoContextProvider {
|
||||||
GO_PACKAGE_TASK_VARIABLE.template_value(),
|
GO_PACKAGE_TASK_VARIABLE.template_value(),
|
||||||
VariableName::Symbol.template_value(),
|
VariableName::Symbol.template_value(),
|
||||||
),
|
),
|
||||||
command: "go".into(),
|
command: format!("go test -run {}", VariableName::Symbol.template_value(),),
|
||||||
args: vec![
|
|
||||||
"test".into(),
|
|
||||||
GO_PACKAGE_TASK_VARIABLE.template_value(),
|
|
||||||
"-run".into(),
|
|
||||||
format!("^{}\\$", VariableName::Symbol.template_value(),),
|
|
||||||
],
|
|
||||||
tags: vec!["go-test".to_owned()],
|
tags: vec!["go-test".to_owned()],
|
||||||
|
cwd: package_cwd.clone(),
|
||||||
..TaskTemplate::default()
|
..TaskTemplate::default()
|
||||||
},
|
},
|
||||||
TaskTemplate {
|
TaskTemplate {
|
||||||
label: format!("go test {}", GO_PACKAGE_TASK_VARIABLE.template_value()),
|
label: format!("go test {}", GO_PACKAGE_TASK_VARIABLE.template_value()),
|
||||||
command: "go".into(),
|
command: "go".into(),
|
||||||
args: vec!["test".into(), GO_PACKAGE_TASK_VARIABLE.template_value()],
|
args: vec!["test".into(), GO_PACKAGE_TASK_VARIABLE.template_value()],
|
||||||
|
cwd: package_cwd.clone(),
|
||||||
..TaskTemplate::default()
|
..TaskTemplate::default()
|
||||||
},
|
},
|
||||||
TaskTemplate {
|
TaskTemplate {
|
||||||
label: "go test ./...".into(),
|
label: "go test ./...".into(),
|
||||||
command: "go".into(),
|
command: "go".into(),
|
||||||
args: vec!["test".into(), "./...".into()],
|
args: vec!["test".into(), "./...".into()],
|
||||||
|
cwd: package_cwd.clone(),
|
||||||
..TaskTemplate::default()
|
..TaskTemplate::default()
|
||||||
},
|
},
|
||||||
TaskTemplate {
|
TaskTemplate {
|
||||||
|
@ -544,7 +547,6 @@ impl ContextProvider for GoContextProvider {
|
||||||
command: "go".into(),
|
command: "go".into(),
|
||||||
args: vec![
|
args: vec![
|
||||||
"test".into(),
|
"test".into(),
|
||||||
GO_PACKAGE_TASK_VARIABLE.template_value(),
|
|
||||||
"-v".into(),
|
"-v".into(),
|
||||||
"-run".into(),
|
"-run".into(),
|
||||||
format!(
|
format!(
|
||||||
|
@ -553,6 +555,7 @@ impl ContextProvider for GoContextProvider {
|
||||||
GO_SUBTEST_NAME_TASK_VARIABLE.template_value(),
|
GO_SUBTEST_NAME_TASK_VARIABLE.template_value(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
cwd: package_cwd.clone(),
|
||||||
tags: vec!["go-subtest".to_owned()],
|
tags: vec!["go-subtest".to_owned()],
|
||||||
..TaskTemplate::default()
|
..TaskTemplate::default()
|
||||||
},
|
},
|
||||||
|
@ -571,13 +574,15 @@ impl ContextProvider for GoContextProvider {
|
||||||
"-bench".into(),
|
"-bench".into(),
|
||||||
format!("^{}\\$", VariableName::Symbol.template_value()),
|
format!("^{}\\$", VariableName::Symbol.template_value()),
|
||||||
],
|
],
|
||||||
|
cwd: package_cwd.clone(),
|
||||||
tags: vec!["go-benchmark".to_owned()],
|
tags: vec!["go-benchmark".to_owned()],
|
||||||
..TaskTemplate::default()
|
..TaskTemplate::default()
|
||||||
},
|
},
|
||||||
TaskTemplate {
|
TaskTemplate {
|
||||||
label: format!("go run {}", GO_PACKAGE_TASK_VARIABLE.template_value(),),
|
label: format!("go run {}", GO_PACKAGE_TASK_VARIABLE.template_value(),),
|
||||||
command: "go".into(),
|
command: "go".into(),
|
||||||
args: vec!["run".into(), GO_PACKAGE_TASK_VARIABLE.template_value()],
|
args: vec!["run".into(), ".".into()],
|
||||||
|
cwd: package_cwd.clone(),
|
||||||
tags: vec!["go-main".to_owned()],
|
tags: vec!["go-main".to_owned()],
|
||||||
..TaskTemplate::default()
|
..TaskTemplate::default()
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue