Skip to content

Commit

Permalink
cmd/go/internal: use strings.CutSuffix
Browse files Browse the repository at this point in the history
Updates #42537

Change-Id: I2d4c5e911c8a2ddfe9a976896b05d3cd8be61f6b
GitHub-Last-Rev: a87597d
GitHub-Pull-Request: #55830
Reviewed-on: https://go-review.googlesource.com/c/go/+/433275
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Reviewed-by: Benny Siegert <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
  • Loading branch information
cuishuang authored and gopherbot committed Sep 27, 2022
1 parent b0f8e20 commit 48a58c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/cmd/go/internal/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,16 +340,14 @@ func clean(p *load.Package) {
continue
}

if strings.HasSuffix(name, "_test.go") {
base := name[:len(name)-len("_test.go")]
if base, found := strings.CutSuffix(name, "_test.go"); found {
allRemove = append(allRemove, base+".test", base+".test.exe")
}

if strings.HasSuffix(name, ".go") {
if base, found := strings.CutSuffix(name, ".go"); found {
// TODO(adg,rsc): check that this .go file is actually
// in "package main", and therefore capable of building
// to an executable file.
base := name[:len(name)-len(".go")]
allRemove = append(allRemove, base, base+".exe")
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/go/internal/load/pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -3115,10 +3115,10 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args
}
patterns := make([]string, len(args))
for i, arg := range args {
if !strings.HasSuffix(arg, "@"+version) {
p, found := strings.CutSuffix(arg, "@"+version)
if !found {
return nil, fmt.Errorf("%s: all arguments must refer to packages in the same module at the same version (@%s)", arg, version)
}
p := arg[:len(arg)-len(version)-1]
switch {
case build.IsLocalImport(p):
return nil, fmt.Errorf("%s: argument must be a package path, not a relative path", arg)
Expand Down

0 comments on commit 48a58c5

Please sign in to comment.