Skip to content

Commit

Permalink
Merge pull request #62 from xushiwei/req
Browse files Browse the repository at this point in the history
TestLoadFrom
  • Loading branch information
xushiwei authored Feb 11, 2024
2 parents fdc5f8a + 8097d48 commit 1626453
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions gopmod/gopmod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ package gopmod

import (
"log"
"path/filepath"
"runtime"
"testing"

"github.com/goplus/mod"
"github.com/goplus/mod/modcache"
"github.com/goplus/mod/modload/modtest"
"github.com/qiniu/x/errors"
"golang.org/x/mod/module"
)

Expand Down Expand Up @@ -70,6 +74,23 @@ func TestPkgType(t *testing.T) {
}
}

func loadModBy(mod module.Version) (p *Module, err error) {
dir, err := modcache.Path(mod)
if err != nil {
return
}
return loadFromDir(dir)
}

func loadFromDir(dir string) (p *Module, err error) {
dir, gomod, err := mod.FindGoMod(dir)
if err != nil {
err = errors.NewWith(err, `mod.FindGoMod(dir)`, -2, "mod.FindGoMod", dir)
return
}
return LoadFrom(gomod, filepath.Join(dir, "gop.mod"))
}

func TestClassfile(t *testing.T) {
modVer := module.Version{Path: "github.com/goplus/yap", Version: "v0.5.0"}
mod, err := LoadMod(modVer)
Expand All @@ -90,6 +111,11 @@ func TestClassfile(t *testing.T) {
if _, err = LoadMod(modVer); !IsNotFound(err) {
log.Fatal("LoadMod github.com/unknown-repo/x:", err)
}

modVer = module.Version{Path: "github.com/goplus/yap", Version: "v0.5.0"}
if _, err = loadModBy(modVer); err != nil {
t.Fatal("loadModBy:", err)
}
}

func TestClassfile2(t *testing.T) {
Expand Down

0 comments on commit 1626453

Please sign in to comment.