From 43d61cb52dc0752a9834b212cd2d5d69dec3d4cf Mon Sep 17 00:00:00 2001 From: Olga Borzenkova Date: Tue, 3 Sep 2024 22:45:10 +0300 Subject: [PATCH] Gazelle: detect any directory with /test in path as test package (#297) We have not very java-like structure in our monorepo: Screen Shot 2024-08-29 at 16 53 15 So current func IsTestPackage doesn't detect our tests as tests and we have `found MULTIPLE results in rule index` error because of the same package in test classes. We propose the fix, so files in packages like `//common/test` will also fit as test packages. --- java/gazelle/private/java/java.go | 2 +- java/gazelle/private/java/java_test.go | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/java/gazelle/private/java/java.go b/java/gazelle/private/java/java.go index 88e6a2c8..70d774b2 100644 --- a/java/gazelle/private/java/java.go +++ b/java/gazelle/private/java/java.go @@ -21,7 +21,7 @@ func IsTestPackage(pkg string) bool { } } - return strings.Contains(pkg, "/test/") + return strings.Contains(pkg, "/test/") || strings.HasSuffix(pkg, "/test") } // This list was derived from a script along the lines of: diff --git a/java/gazelle/private/java/java_test.go b/java/gazelle/private/java/java_test.go index 4864f75b..a265e4c5 100644 --- a/java/gazelle/private/java/java_test.go +++ b/java/gazelle/private/java/java_test.go @@ -18,6 +18,8 @@ func TestIsTestPackage(t *testing.T) { "src/test/java/com/example/myproject": true, "src/main/com/example/perftest": false, "test-utils/src/main/com/example/project": false, + "foo/bar/test": true, + "project1/testutils/src/main": false, } for pkg, want := range tests {