languages: Exclude TestMain from Go runnables (#46575)

Exclude special [TestMain](https://pkg.go.dev/testing#hdr-Main) function
from Go runnables.

Release Notes:

- Excluded `TestMain` function from Go runnables.
This commit is contained in:
Lev Zakharov authored and GitHub committed 2026-02-10 09:12:55 +00:00
1 parent 4177be4479
commit 64c3e8a848
2 files changed
+36 -1

No files matched your search

+34
View File
@@ -847,6 +847,40 @@ mod tests {
);
}
#[gpui::test]
fn test_go_test_main_ignored(cx: &mut TestAppContext) {
let language = language("go", tree_sitter_go::LANGUAGE.into());
let example_test = r#"
package main
func TestMain(m *testing.M) {
os.Exit(m.Run())
}
"#;
let buffer =
cx.new(|cx| crate::Buffer::local(example_test, cx).with_language(language.clone(), cx));
cx.executor().run_until_parked();
let runnables: Vec<_> = buffer.update(cx, |buffer, _| {
let snapshot = buffer.snapshot();
snapshot.runnable_ranges(0..example_test.len()).collect()
});
let tag_strings: Vec<String> = runnables
.iter()
.flat_map(|r| &r.runnable.tags)
.map(|tag| tag.0.to_string())
.collect();
assert!(
!tag_strings.contains(&"go-test".to_string()),
"Should NOT find go-test tag, found: {:?}",
tag_strings
);
}
#[gpui::test]
fn test_testify_suite_detection(cx: &mut TestAppContext) {
let language = language("go", tree_sitter_go::LANGUAGE.into());
+2 -1
View File
@@ -2,7 +2,8 @@
(
(
(function_declaration name: (_) @run
(#match? @run "^Test.*"))
(#match? @run "^Test.*")
(#not-match? @run "^TestMain$"))
) @_
(#set! tag go-test)
)