зеркало из https://github.com/golang/dep.git
Merge branch 'master' into par_cmd_tests
This commit is contained in:
Коммит
dd3873dd41
|
@ -34,4 +34,4 @@ deploy: false
|
|||
|
||||
test_script:
|
||||
- go build github.com/golang/dep/cmd/dep
|
||||
- for /f "" %%G in ('go list github.com/golang/dep/... ^| find /i /v "/vendor/"') do @go test %%G
|
||||
- for /f "" %%G in ('go list github.com/golang/dep/... ^| find /i /v "/vendor/"') do ( go test %%G & IF ERRORLEVEL == 1 EXIT 1)
|
||||
|
|
|
@ -71,6 +71,12 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error {
|
|||
root = ctx.WorkingDir
|
||||
} else {
|
||||
root = args[0]
|
||||
if !filepath.IsAbs(args[0]) {
|
||||
root = filepath.Join(ctx.WorkingDir, args[0])
|
||||
}
|
||||
if err := os.MkdirAll(root, os.FileMode(0777)); err != nil {
|
||||
return errors.Errorf("unable to create directory %s , err %v", root, err)
|
||||
}
|
||||
}
|
||||
|
||||
mf := filepath.Join(root, dep.ManifestName)
|
||||
|
|
|
@ -45,6 +45,30 @@ func TestIntegration(t *testing.T) {
|
|||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
filepath.Walk(filepath.Join("testdata", "init_path_tests"),
|
||||
func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
t.Fatal("error walking filepath")
|
||||
}
|
||||
|
||||
wd, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if filepath.Base(path) == "testcase.json" {
|
||||
parse := strings.Split(path, string(filepath.Separator))
|
||||
testName := strings.Join(parse[2:len(parse)-1], "/")
|
||||
t.Run(testName, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
t.Run("external", testRelativePath(testName, wd, true, execCmd))
|
||||
t.Run("internal", testRelativePath(testName, wd, false, runMain))
|
||||
})
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// execCmd is a test.RunFunc which runs the program in another process.
|
||||
|
@ -87,7 +111,7 @@ func testIntegration(name, wd string, externalProc bool, run test.RunFunc) func(
|
|||
t.Parallel()
|
||||
|
||||
// Set up environment
|
||||
testCase := test.NewTestCase(t, name, wd)
|
||||
testCase := test.NewTestCase(t, name, "harness_tests", wd)
|
||||
defer testCase.Cleanup()
|
||||
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
|
||||
defer testProj.Cleanup()
|
||||
|
@ -130,3 +154,50 @@ func testIntegration(name, wd string, externalProc bool, run test.RunFunc) func(
|
|||
testCase.CompareVendorPaths(testProj.GetVendorPaths())
|
||||
}
|
||||
}
|
||||
|
||||
func testRelativePath(name, wd string, externalProc bool, run test.RunFunc) func(t *testing.T) {
|
||||
return func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Set up environment
|
||||
testCase := test.NewTestCase(t, name, "init_path_tests", wd)
|
||||
defer testCase.Cleanup()
|
||||
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
|
||||
defer testProj.Cleanup()
|
||||
|
||||
// Create and checkout the vendor revisions
|
||||
for ip, rev := range testCase.VendorInitial {
|
||||
testProj.GetVendorGit(ip)
|
||||
testProj.RunGit(testProj.VendorPath(ip), "checkout", rev)
|
||||
}
|
||||
|
||||
// Create and checkout the import revisions
|
||||
for ip, rev := range testCase.GopathInitial {
|
||||
testProj.RunGo("get", ip)
|
||||
testProj.RunGit(testProj.Path("src", ip), "checkout", rev)
|
||||
}
|
||||
|
||||
// Run commands
|
||||
testProj.RecordImportPaths()
|
||||
|
||||
var err error
|
||||
for i, args := range testCase.Commands {
|
||||
err = testProj.DoRun(args)
|
||||
if err != nil && i < len(testCase.Commands)-1 {
|
||||
t.Fatalf("cmd %s raised an unexpected error: %s", args[0], err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Check error raised in final command
|
||||
testCase.CompareError(err, testProj.GetStderr())
|
||||
|
||||
// Check output
|
||||
testCase.CompareOutput(testProj.GetStdout())
|
||||
|
||||
// Check final manifest and lock
|
||||
testCase.CompareFile(dep.ManifestName, testProj.ProjPath(dep.ManifestName))
|
||||
testCase.CompareFile(dep.LockName, testProj.ProjPath(dep.LockName))
|
||||
|
||||
testProj.CompareImportPaths()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ func removeErrors(name, wd string, externalProc bool, run test.RunFunc) func(*te
|
|||
return func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCase := test.NewTestCase(t, name, wd)
|
||||
testCase := test.NewTestCase(t, name, "harness_tests", wd)
|
||||
testProj := test.NewTestProject(t, testCase.InitialPath(), wd, externalProc, run)
|
||||
defer testProj.Cleanup()
|
||||
|
||||
|
|
12
cmd/dep/testdata/init_path_tests/relative_path/final/project_dir/Gopkg.lock
сгенерированный
поставляемый
Normal file
12
cmd/dep/testdata/init_path_tests/relative_path/final/project_dir/Gopkg.lock
сгенерированный
поставляемый
Normal file
|
@ -0,0 +1,12 @@
|
|||
memo = "af9a783a5430dabcaaf44683c09e2b729e1c0d61f13bfdf6677c4fd0b41387ca"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/sdboyer/deptest"
|
||||
packages = ["."]
|
||||
revision = "3f4c3bea144e112a69bbe5d8d01c1b09a544253f"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/sdboyer/deptestdos"
|
||||
packages = ["."]
|
||||
revision = "a0196baa11ea047dd65037287451d36b861b00ea"
|
7
cmd/dep/testdata/init_path_tests/relative_path/final/project_dir/Gopkg.toml
поставляемый
Normal file
7
cmd/dep/testdata/init_path_tests/relative_path/final/project_dir/Gopkg.toml
поставляемый
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/sdboyer/deptest"
|
||||
|
||||
[[dependencies]]
|
||||
name = "github.com/sdboyer/deptestdos"
|
13
cmd/dep/testdata/init_path_tests/relative_path/initial/project_dir/foo/bar.go
поставляемый
Normal file
13
cmd/dep/testdata/init_path_tests/relative_path/initial/project_dir/foo/bar.go
поставляемый
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package foo
|
||||
|
||||
import "github.com/sdboyer/deptest"
|
||||
|
||||
func Foo() deptest.Foo {
|
||||
var y deptest.Foo
|
||||
|
||||
return y
|
||||
}
|
18
cmd/dep/testdata/init_path_tests/relative_path/initial/project_dir/main.go
поставляемый
Normal file
18
cmd/dep/testdata/init_path_tests/relative_path/initial/project_dir/main.go
поставляемый
Normal file
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2017 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sdboyer/deptestdos"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var x deptestdos.Bar
|
||||
y := foo.FooFunc()
|
||||
|
||||
fmt.Println(x, y)
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"commands": [
|
||||
["init", "project_dir"]
|
||||
],
|
||||
"init-path": "project_dir"
|
||||
|
||||
}
|
|
@ -27,6 +27,8 @@ var (
|
|||
svnSchemes = []string{"https", "http", "svn", "svn+ssh"}
|
||||
)
|
||||
|
||||
const gopkgUnstableSuffix = "-unstable"
|
||||
|
||||
func validateVCSScheme(scheme, typ string) bool {
|
||||
// everything allows plain ssh
|
||||
if scheme == "ssh" {
|
||||
|
@ -276,10 +278,18 @@ func (m gopkginDeducer) deduceSource(p string, u *url.URL) (maybeSource, error)
|
|||
} else {
|
||||
u.Path = path.Join(v[2], v[3])
|
||||
}
|
||||
major, err := strconv.ParseUint(v[4][1:], 10, 64)
|
||||
|
||||
unstable := false
|
||||
majorStr := v[4]
|
||||
|
||||
if strings.HasSuffix(majorStr, gopkgUnstableSuffix) {
|
||||
unstable = true
|
||||
majorStr = strings.TrimSuffix(majorStr, gopkgUnstableSuffix)
|
||||
}
|
||||
major, err := strconv.ParseUint(majorStr[1:], 10, 64)
|
||||
if err != nil {
|
||||
// this should only be reachable if there's an error in the regex
|
||||
return nil, fmt.Errorf("could not parse %q as a gopkg.in major version", v[4][1:])
|
||||
return nil, fmt.Errorf("could not parse %q as a gopkg.in major version", majorStr[1:])
|
||||
}
|
||||
|
||||
mb := make(maybeSources, len(gitSchemes))
|
||||
|
@ -290,9 +300,10 @@ func (m gopkginDeducer) deduceSource(p string, u *url.URL) (maybeSource, error)
|
|||
}
|
||||
u2.Scheme = scheme
|
||||
mb[k] = maybeGopkginSource{
|
||||
opath: v[1],
|
||||
url: &u2,
|
||||
major: major,
|
||||
opath: v[1],
|
||||
url: &u2,
|
||||
major: major,
|
||||
unstable: unstable,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -131,6 +131,8 @@ type maybeGopkginSource struct {
|
|||
url *url.URL
|
||||
// the major version to apply for filtering
|
||||
major uint64
|
||||
// whether or not the source package is "unstable"
|
||||
unstable bool
|
||||
}
|
||||
|
||||
func (m maybeGopkginSource) try(ctx context.Context, cachedir string, c singleSourceCache, superv *supervisor) (source, sourceState, error) {
|
||||
|
@ -151,7 +153,8 @@ func (m maybeGopkginSource) try(ctx context.Context, cachedir string, c singleSo
|
|||
repo: &gitRepo{r},
|
||||
},
|
||||
},
|
||||
major: m.major,
|
||||
major: m.major,
|
||||
unstable: m.unstable,
|
||||
}
|
||||
|
||||
var vl []PairedVersion
|
||||
|
|
|
@ -278,7 +278,8 @@ func (s *gitSource) listVersions(ctx context.Context) (vlist []PairedVersion, er
|
|||
// according to the input URL.
|
||||
type gopkginSource struct {
|
||||
gitSource
|
||||
major uint64
|
||||
major uint64
|
||||
unstable bool
|
||||
}
|
||||
|
||||
func (s *gopkginSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
|
||||
|
@ -297,16 +298,14 @@ func (s *gopkginSource) listVersions(ctx context.Context) ([]PairedVersion, erro
|
|||
pv := v.(versionPair)
|
||||
switch tv := pv.v.(type) {
|
||||
case semVersion:
|
||||
if tv.sv.Major() == s.major {
|
||||
if tv.sv.Major() == s.major && !s.unstable {
|
||||
vlist[k] = v
|
||||
k++
|
||||
}
|
||||
case branchVersion:
|
||||
// The semver lib isn't exactly the same as gopkg.in's logic, but
|
||||
// it's close enough that it's probably fine to use. We can be more
|
||||
// exact if real problems crop up. The most obvious vector for
|
||||
// problems is that we totally ignore the "unstable" designation
|
||||
// right now.
|
||||
// exact if real problems crop up.
|
||||
sv, err := semver.NewVersion(tv.name)
|
||||
if err != nil || sv.Major() != s.major {
|
||||
// not a semver-shaped branch name at all, or not the same major
|
||||
|
@ -314,6 +313,12 @@ func (s *gopkginSource) listVersions(ctx context.Context) ([]PairedVersion, erro
|
|||
continue
|
||||
}
|
||||
|
||||
// Gopkg.in has a special "-unstable" suffix which we need to handle
|
||||
// separately.
|
||||
if s.unstable != strings.HasSuffix(tv.name, gopkgUnstableSuffix) {
|
||||
continue
|
||||
}
|
||||
|
||||
// Turn off the default branch marker unconditionally; we can't know
|
||||
// which one to mark as default until we've seen them all
|
||||
tv.isDefault = false
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"net/url"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
@ -152,10 +153,12 @@ func testGopkginSourceInteractions(t *testing.T) {
|
|||
t.Errorf("URL was bad, lolwut? errtext: %s", err)
|
||||
return
|
||||
}
|
||||
unstable := strings.HasSuffix(opath, gopkgUnstableSuffix)
|
||||
mb := maybeGopkginSource{
|
||||
opath: opath,
|
||||
url: u,
|
||||
major: major,
|
||||
opath: opath,
|
||||
url: u,
|
||||
major: major,
|
||||
unstable: unstable,
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
@ -240,7 +243,7 @@ func testGopkginSourceInteractions(t *testing.T) {
|
|||
|
||||
// simultaneously run for v1, v2, and v3 filters of the target repo
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(3)
|
||||
wg.Add(4)
|
||||
go func() {
|
||||
tfunc("gopkg.in/sdboyer/gpkt.v1", "github.com/sdboyer/gpkt", 1, []Version{
|
||||
NewVersion("v1.1.0").Is(Revision("b2cb48dda625f6640b34d9ffb664533359ac8b91")),
|
||||
|
@ -265,6 +268,13 @@ func testGopkginSourceInteractions(t *testing.T) {
|
|||
wg.Done()
|
||||
}()
|
||||
|
||||
go func() {
|
||||
tfunc("github.com/sdboyer/gpkt2.v1-unstable", "github.com/sdboyer/gpkt2", 1, []Version{
|
||||
newDefaultBranch("v1-unstable").Is(Revision("24de0be8f4a0b8a44321562117749b257bfcef69")),
|
||||
})
|
||||
wg.Done()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
|
|
|
@ -33,10 +33,11 @@ type IntegrationTestCase struct {
|
|||
GopathInitial map[string]string `json:"gopath-initial"`
|
||||
VendorInitial map[string]string `json:"vendor-initial"`
|
||||
VendorFinal []string `json:"vendor-final"`
|
||||
InitPath string `json:"init-path"`
|
||||
}
|
||||
|
||||
func NewTestCase(t *testing.T, name, wd string) *IntegrationTestCase {
|
||||
rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", "harness_tests", name))
|
||||
func NewTestCase(t *testing.T, name, test_dir, wd string) *IntegrationTestCase {
|
||||
rootPath := filepath.FromSlash(filepath.Join(wd, "testdata", test_dir, name))
|
||||
n := &IntegrationTestCase{
|
||||
t: t,
|
||||
name: name,
|
||||
|
|
|
@ -75,7 +75,10 @@ func BackupVendor(vpath, suffix string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
if vendorExists {
|
||||
vendorbak := vpath + "-" + suffix
|
||||
// vpath is a full filepath. We need to split it to prefix the backup dir
|
||||
// with an "_"
|
||||
vpathDir, name := filepath.Split(vpath)
|
||||
vendorbak := filepath.Join(vpathDir, "_"+name+"-"+suffix)
|
||||
// Check if a directory with same name exists
|
||||
if _, err = os.Stat(vendorbak); os.IsNotExist(err) {
|
||||
// Rename existing vendor to vendor-{suffix}
|
||||
|
|
|
@ -120,7 +120,7 @@ func TestBackupVendor(t *testing.T) {
|
|||
}
|
||||
|
||||
// Create a backup
|
||||
wantName := "vendor-sfx"
|
||||
wantName := "_vendor-sfx"
|
||||
vendorbak, err := BackupVendor("vendor", "sfx")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
|
|
Загрузка…
Ссылка в новой задаче