Skip to content

Commit

Permalink
checkGopDeps fix: support qiniu/x
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Feb 18, 2024
1 parent 01d5110 commit f9fff1b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
9 changes: 6 additions & 3 deletions modload/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ func (p Module) Save() (err error) {
}

func (p Module) checkGopDeps() (flags int) {
switch p.Path() {
case gopMod:
return FlagDepModGop | FlagDepModX
case xMod:
return FlagDepModX
}
for _, r := range p.File.Require {
switch r.Mod.Path {
case gopMod:
Expand Down Expand Up @@ -345,9 +351,6 @@ const (
// SaveWithGopMod adds `require github.com/goplus/gop` and saves all
// changes of this module.
func (p Module) SaveWithGopMod(gop *env.Gop, flags int) (err error) {
if p.Path() == gopMod { // don't change Go+ itself
return
}
old := p.checkGopDeps()
if (flags &^ old) == 0 { // nothing to do
return
Expand Down
12 changes: 12 additions & 0 deletions modload/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ import (
"golang.org/x/mod/module"
)

func TestCheckGopDeps(t *testing.T) {
mod := Default
file := *mod.File
mod.File = &file
mod.File.Module = &gomodfile.Module{Mod: module.Version{
Path: "github.com/qiniu/x",
}}
if mod.checkGopDeps() != FlagDepModX {
t.Fatal("checkGopDeps")
}
}

func TestEmpty(t *testing.T) {
mod := &Module{File: new(gomodfile.File), Opt: new(modfile.File)}
if mod.HasModfile() {
Expand Down

0 comments on commit f9fff1b

Please sign in to comment.