зеркало из https://github.com/golang/dep.git
Merge pull request #571 from niranjan92/master
dep init - support relative path
This commit is contained in:
Коммит
155a6deee8
|
@ -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)
|
||||
|
|
|
@ -43,6 +43,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.
|
||||
|
@ -85,7 +109,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()
|
||||
|
@ -128,3 +152,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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ func TestRemoveErrors(t *testing.T) {
|
|||
|
||||
func removeErrors(name, wd string, externalProc bool, run test.RunFunc) func(*testing.T) {
|
||||
return func(t *testing.T) {
|
||||
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"
|
||||
|
||||
}
|
|
@ -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,
|
||||
|
|
Загрузка…
Ссылка в новой задаче