-
-
Notifications
You must be signed in to change notification settings - Fork 761
tools/upgradedep: add support for Label based repositories.bzl #3051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9e6fed2
tools/upgradedep: add support for Label based repositories.bzl
JamyDev 26e563f
upgradedep: switch to ioutil, move test data
JamyDev 1e6bd8b
upgradedep: log actual failure reason
JamyDev 3b86af4
upgradedep_test: use .Abs path
JamyDev fbc5058
upgradedep_test: use bazel.Runfile
JamyDev a323aff
upgradedep_test: change to simpler testing format
JamyDev 83cc25f
upgradedep: nit comments from PR
JamyDev 777c961
fixup! separate tests between success and fail
JamyDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,89 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| bzl "github.com/bazelbuild/buildtools/build" | ||
| ) | ||
|
|
||
| func TestPatchItemParser(t *testing.T) { | ||
|
JamyDev marked this conversation as resolved.
Outdated
|
||
| tests := []struct { | ||
| expression []byte | ||
| result string | ||
| error string | ||
| }{ | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| Label("//third_party:org_golang_x_tools-gazelle.patch")`), | ||
| result: "//third_party:org_golang_x_tools-gazelle.patch", | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| "@io_bazel_rules_go//third_party:org_golang_x_tools-gazelle.patch"`), | ||
| result: "//third_party:org_golang_x_tools-gazelle.patch", | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| "//third_party:org_golang_x_tools-gazelle.patch"`), | ||
| result: "//third_party:org_golang_x_tools-gazelle.patch", | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| Label("@io_bazel_rules_go//third_party:org_golang_x_tools-gazelle.patch")`), | ||
| result: "@io_bazel_rules_go//third_party:org_golang_x_tools-gazelle.patch", | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| NotLabel("//third_party:org_golang_x_tools-gazelle.patch")`), | ||
| result: "", | ||
| error: `invalid patch function: "NotLabel"`, | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| NotLabel(True)`), | ||
| error: `invalid patch function: "NotLabel"`, | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| True`), | ||
| error: "not all patches are string literals or Label()", | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| Label("//third_party:org_golang_x_tools-gazelle.patch", True)`), | ||
| error: "Label expr should have 1 argument, found 2", | ||
| }, | ||
| { | ||
| expression: []byte(`# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/tools -go_naming_convention import_alias | ||
| Label(True)`), | ||
| error: "Label expr does not contain a string literal", | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(fmt.Sprintf("%v", tt.expression), func(t *testing.T) { | ||
| patchExpr, err := bzl.Parse("repos.bzl", tt.expression) | ||
| if err != nil { | ||
| t.Fatalf(err.Error()) | ||
| } | ||
|
|
||
| patchLabelStr, _, err := parsePatchesItem(patchExpr.Stmt[0]) | ||
| if err != nil && err.Error() != tt.error { | ||
|
JamyDev marked this conversation as resolved.
Outdated
|
||
| if tt.error != "" { | ||
| t.Errorf("expected error %q, but got error %q instead", tt.error, err.Error()) | ||
| } else { | ||
| t.Errorf("unexpected error while parsing expression: %s", err.Error()) | ||
| } | ||
| } | ||
|
|
||
| if err == nil && patchLabelStr != tt.result { | ||
| if tt.error != "" { | ||
| t.Errorf("expected error %q, but got result %q instead", tt.error, patchLabelStr) | ||
| } else { | ||
| t.Errorf("expected result %q, but got result %q instead", tt.result, patchLabelStr) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.