-
Notifications
You must be signed in to change notification settings - Fork 372
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, `gazelle` wouldn't look into `include`ed segments of module files when collecting the apparent to module name mapping.
- Loading branch information
Showing
8 changed files
with
140 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package module | ||
|
||
import ( | ||
"path/filepath" | ||
"testing" | ||
|
||
"github.com/bazelbuild/rules_go/go/runfiles" | ||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestCollectApparent(t *testing.T) { | ||
moduleFile, err := runfiles.Rlocation("bazel_gazelle/internal/module/testdata/MODULE.bazel") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
apparentNames, err := collectApparentNames(filepath.Dir(moduleFile), "MODULE.bazel") | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
|
||
expected := map[string]string{ | ||
"rules_bar": "rules_bar", | ||
"rules_baz": "rules_baz", | ||
"rules_foo": "my_rules_foo", | ||
"rules_lang": "my_rules_lang", | ||
"rules_quz": "rules_quz", | ||
"test_module": "my_test_module", | ||
} | ||
if diff := cmp.Diff(expected, apparentNames); diff != "" { | ||
t.Errorf("unexpected apparent names (-want +got):\n%s", diff) | ||
} | ||
} | ||
|
||
func TestCollectApparent_fileDoesNotExist(t *testing.T) { | ||
_, err := collectApparentNames(t.TempDir(), "MODULE.bazel") | ||
if err != nil { | ||
t.Fatalf("unexpected error: %v", err) | ||
} | ||
_, err = collectApparentNames(t.TempDir(), "segment.MODULE.bazel") | ||
if err == nil { | ||
t.Fatalf("expected error, got nil") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module( | ||
name = "test_module", | ||
repo_name = "my_test_module", | ||
) | ||
|
||
bazel_dep(name = "rules_bar", version = "1.2.3") | ||
|
||
include("//bazel:lang.MODULE.bazel") | ||
|
||
bazel_dep(name = "rules_foo", version = "1.2.3", repo_name = "my_rules_foo") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bazel_dep(name = "rules_quz", version = "0.0.1") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
bazel_dep(name = "rules_lang", version = "1.2.3", repo_name = "my_rules_lang") | ||
|
||
include("//:deps.MODULE.bazel") | ||
include("//bazel:dir/deps.MODULE.bazel") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
bazel_dep(name = "rules_baz", version = "0.0.1") |