github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/go116_testpkg.go (about) 1 // +build go1.16 2 3 package main 4 5 import ( 6 "go/build" 7 "go/token" 8 9 gbuild "github.com/goplusjs/gopherjs/build" 10 ) 11 12 func makeTestPkg(pkg *gbuild.PackageData, xtest bool) *gbuild.PackageData { 13 if xtest { 14 return &gbuild.PackageData{ 15 Package: &build.Package{ 16 Name: pkg.Name + "_test", 17 ImportPath: pkg.ImportPath + "_test", 18 Dir: pkg.Dir, 19 GoFiles: pkg.XTestGoFiles, 20 Imports: pkg.XTestImports, 21 EmbedPatternPos: pkg.XTestEmbedPatternPos, 22 }, 23 IsTest: true, 24 } 25 } else { 26 pmap := make(map[string][]token.Position) 27 for k, v := range pkg.EmbedPatternPos { 28 pmap[k] = v 29 } 30 for k, v := range pkg.TestEmbedPatternPos { 31 if ov, ok := pmap[k]; ok { 32 pmap[k] = append(v, ov...) 33 } else { 34 pmap[k] = v 35 } 36 } 37 return &gbuild.PackageData{ 38 Package: &build.Package{ 39 Name: pkg.Name, 40 ImportPath: pkg.ImportPath, 41 Dir: pkg.Dir, 42 GoFiles: append(pkg.GoFiles, pkg.TestGoFiles...), 43 Imports: append(pkg.Imports, pkg.TestImports...), 44 EmbedPatternPos: pmap, 45 }, 46 IsTest: true, 47 JSFiles: pkg.JSFiles, 48 } 49 } 50 }