1
0
mirror of https://github.com/golang/go synced 2024-11-18 08:14:41 -07:00

Revert "refactor/eg: remove vendor prefix from imported packages"

This reverts commit c060f04f93.

Reason for revert: breaks the build. Nobody ran tests.

Change-Id: I981101eb503e8cebd6f7b5640299d106ca733b33
Reviewed-on: https://go-review.googlesource.com/33674
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Brad Fitzpatrick 2016-11-30 00:12:53 +00:00
parent cbfb669053
commit b66e054640
8 changed files with 1 additions and 172 deletions

View File

@ -1,79 +0,0 @@
// Copyright 2016 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 (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
var (
sub = flag.Bool("subtest", false, "Indicates that the program should act as the eg command rather than as a test")
)
func TestVendor(t *testing.T) {
if *sub {
if err := doMain(); err != nil {
fmt.Fprintf(os.Stderr, "eg: %s\n", err)
os.Exit(1)
}
os.Exit(0)
}
tests := []struct {
args []string
goldFile string
}{
{
args: []string{"-t", "A.template", "--", "A1.go"},
goldFile: "A1.golden",
},
}
curdir, err := os.Getwd()
if err != nil {
t.Fatalf("os.Getwd: %v", err)
}
for _, tt := range tests {
cmd := exec.Command(os.Args[0], append([]string{"-test.run=TestVendor", "-subtest"}, tt.args...)...)
cmd.Dir = filepath.Join(curdir, "testdata/src/prog")
cmd.Env = append(cmd.Env, "GOPATH="+filepath.Join(curdir, "testdata"))
for _, env := range os.Environ() {
if strings.HasPrefix(env, "GOPATH=") {
continue
}
cmd.Env = append(cmd.Env, env)
}
goldFile := filepath.Join(cmd.Dir, tt.goldFile)
gold, err := ioutil.ReadFile(goldFile)
if err != nil {
t.Errorf("read golden file %q: %v", goldFile, err)
continue
}
var stdout bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
t.Errorf("eg %q exec: %v", tt.args, err)
continue
}
if have, want := stdout.Bytes(), gold; !bytes.Equal(have, want) {
t.Errorf("eg %q output does not match contents of %q:\n%s\n!=\n%s\n", tt.args, tt.goldFile, have, want)
}
}
}

View File

@ -1,5 +0,0 @@
package dep0
func C() {}
func D() {}

View File

@ -1,11 +0,0 @@
package eg
import (
"dep0"
"dep1"
)
// Test of adding a dependency that is found via a "vendor" directory
func before() { dep0.D() }
func after() { dep1.E() }

View File

@ -1,10 +0,0 @@
package main
import (
"dep0"
)
func example() {
dep0.C()
dep0.D()
}

View File

@ -1,11 +0,0 @@
package main
import (
"dep0"
"dep1"
)
func example() {
dep0.C()
dep1.E()
}

View File

@ -1,3 +0,0 @@
package dep1
func E() {}

View File

@ -98,7 +98,7 @@ func (tr *Transformer) Transform(info *types.Info, pkg *types.Package, file *ast
if tr.nsubsts > 0 {
pkgs := make(map[string]*types.Package)
for obj := range tr.importedObjs {
pkgs[vendorlessImportPath(obj.Pkg().Path())] = obj.Pkg()
pkgs[obj.Pkg().Path()] = obj.Pkg()
}
for _, imp := range file.Imports {
@ -344,19 +344,3 @@ func updateTypeInfo(info *types.Info, new, old ast.Expr) {
info.Types[new] = tv
}
}
// vendorlessImportPath returns the devendorized version of the provided import path.
// e.g. "foo/bar/vendor/a/b" => "a/b"
//
// This function is taken from fix.go in the golang.org/x/tools/imports
// package.
func vendorlessImportPath(ipath string) string {
// Devendorize for use in import statement.
if i := strings.LastIndex(ipath, "/vendor/"); i >= 0 {
return ipath[i+len("/vendor/"):]
}
if strings.HasPrefix(ipath, "vendor/") {
return ipath[len("vendor/"):]
}
return ipath
}

View File

@ -1,36 +0,0 @@
// Copyright 2016 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 eg
import "testing"
func TestVendorlessImportPath(t *testing.T) {
tests := []struct {
path string
ipath string
}{
{"a/b/c", "a/b/c"},
{"a/b/vendor/c", "c"},
{"a/vendor/b/c", "b/c"},
{"vendor/a/b/c", "a/b/c"},
{"a/b/vendor/vendor/c", "c"},
{"a/vendor/b/vendor/c", "c"},
{"vendor/a/b/vendor/c", "c"},
{"vendor/a/vendor/b/c", "b/c"},
{"a/vendor/vendor/b/c", "b/c"},
{"vendor/vendor/a/b/c", "a/b/c"},
{"a/b/notvendor/c", "a/b/notvendor/c"},
{"a/b/vendors/c", "a/b/vendors/c"},
{"a/b/notvendors/c", "a/b/notvendors/c"},
{"notvendor/a/b/c", "notvendor/a/b/c"},
}
for _, tt := range tests {
if have, want := vendorlessImportPath(tt.path), tt.ipath; have != want {
t.Errorf("vendorlessImportPath(%q); %q != %q", tt.path, have, want)
}
}
}