]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/vet: make vet_test module-agnostic
authorBryan C. Mills <bcmills@google.com>
Tue, 19 Feb 2019 19:53:26 +0000 (14:53 -0500)
committerBryan C. Mills <bcmills@google.com>
Wed, 20 Feb 2019 15:46:42 +0000 (15:46 +0000)
vet_test currently uses a custom GOPATH for each test, but it turns
out not to be necessary.

Updates #30228

Change-Id: Id7a7bf6d759bd94adccf44e197be1728c2f23575
Reviewed-on: https://go-review.googlesource.com/c/163038
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
26 files changed:
src/cmd/vet/testdata/asm/asm.go [moved from src/cmd/vet/testdata/src/asm/asm.go with 100% similarity]
src/cmd/vet/testdata/asm/asm1.s [moved from src/cmd/vet/testdata/src/asm/asm1.s with 100% similarity]
src/cmd/vet/testdata/assign/assign.go [moved from src/cmd/vet/testdata/src/assign/assign.go with 100% similarity]
src/cmd/vet/testdata/atomic/atomic.go [moved from src/cmd/vet/testdata/src/atomic/atomic.go with 100% similarity]
src/cmd/vet/testdata/bool/bool.go [moved from src/cmd/vet/testdata/src/bool/bool.go with 100% similarity]
src/cmd/vet/testdata/buildtag/buildtag.go [moved from src/cmd/vet/testdata/src/buildtag/buildtag.go with 100% similarity]
src/cmd/vet/testdata/cgo/cgo.go [moved from src/cmd/vet/testdata/src/cgo/cgo.go with 100% similarity]
src/cmd/vet/testdata/composite/composite.go [moved from src/cmd/vet/testdata/src/composite/composite.go with 100% similarity]
src/cmd/vet/testdata/copylock/copylock.go [moved from src/cmd/vet/testdata/src/copylock/copylock.go with 100% similarity]
src/cmd/vet/testdata/deadcode/deadcode.go [moved from src/cmd/vet/testdata/src/deadcode/deadcode.go with 100% similarity]
src/cmd/vet/testdata/httpresponse/httpresponse.go [moved from src/cmd/vet/testdata/src/httpresponse/httpresponse.go with 100% similarity]
src/cmd/vet/testdata/lostcancel/lostcancel.go [moved from src/cmd/vet/testdata/src/lostcancel/lostcancel.go with 100% similarity]
src/cmd/vet/testdata/method/method.go [moved from src/cmd/vet/testdata/src/method/method.go with 100% similarity]
src/cmd/vet/testdata/nilfunc/nilfunc.go [moved from src/cmd/vet/testdata/src/nilfunc/nilfunc.go with 100% similarity]
src/cmd/vet/testdata/print/print.go [moved from src/cmd/vet/testdata/src/print/print.go with 94% similarity]
src/cmd/vet/testdata/rangeloop/rangeloop.go [moved from src/cmd/vet/testdata/src/rangeloop/rangeloop.go with 100% similarity]
src/cmd/vet/testdata/shift/shift.go [moved from src/cmd/vet/testdata/src/shift/shift.go with 100% similarity]
src/cmd/vet/testdata/structtag/structtag.go [moved from src/cmd/vet/testdata/src/structtag/structtag.go with 100% similarity]
src/cmd/vet/testdata/tagtest/file1.go [moved from src/cmd/vet/testdata/src/tagtest/file1.go with 100% similarity]
src/cmd/vet/testdata/tagtest/file2.go [moved from src/cmd/vet/testdata/src/tagtest/file2.go with 100% similarity]
src/cmd/vet/testdata/testingpkg/tests.go [moved from src/cmd/vet/testdata/src/testingpkg/tests.go with 100% similarity]
src/cmd/vet/testdata/testingpkg/tests_test.go [moved from src/cmd/vet/testdata/src/testingpkg/tests_test.go with 100% similarity]
src/cmd/vet/testdata/unmarshal/unmarshal.go [moved from src/cmd/vet/testdata/src/unmarshal/unmarshal.go with 100% similarity]
src/cmd/vet/testdata/unsafeptr/unsafeptr.go [moved from src/cmd/vet/testdata/src/unsafeptr/unsafeptr.go with 100% similarity]
src/cmd/vet/testdata/unused/unused.go [moved from src/cmd/vet/testdata/src/unused/unused.go with 100% similarity]
src/cmd/vet/vet_test.go

similarity index 94%
rename from src/cmd/vet/testdata/src/print/print.go
rename to src/cmd/vet/testdata/print/print.go
index 6bacd0fd747c8659875ceabb86668ff4841f0f3d..7a4783aee4fd920c6c90b7e3a8dcce1a254522cb 100644 (file)
@@ -126,16 +126,16 @@ func PrintfTests() {
        fmt.Printf("%U", x)                         // ERROR "Printf format %U has arg x of wrong type float64"
        fmt.Printf("%x", nil)                       // ERROR "Printf format %x has arg nil of wrong type untyped nil"
        fmt.Printf("%X", 2.3)                       // ERROR "Printf format %X has arg 2.3 of wrong type float64"
-       fmt.Printf("%s", stringerv)                 // ERROR "Printf format %s has arg stringerv of wrong type print.ptrStringer"
-       fmt.Printf("%t", stringerv)                 // ERROR "Printf format %t has arg stringerv of wrong type print.ptrStringer"
-       fmt.Printf("%s", embeddedStringerv)         // ERROR "Printf format %s has arg embeddedStringerv of wrong type print.embeddedStringer"
-       fmt.Printf("%t", embeddedStringerv)         // ERROR "Printf format %t has arg embeddedStringerv of wrong type print.embeddedStringer"
-       fmt.Printf("%q", notstringerv)              // ERROR "Printf format %q has arg notstringerv of wrong type print.notstringer"
-       fmt.Printf("%t", notstringerv)              // ERROR "Printf format %t has arg notstringerv of wrong type print.notstringer"
-       fmt.Printf("%t", stringerarrayv)            // ERROR "Printf format %t has arg stringerarrayv of wrong type print.stringerarray"
-       fmt.Printf("%t", notstringerarrayv)         // ERROR "Printf format %t has arg notstringerarrayv of wrong type print.notstringerarray"
-       fmt.Printf("%q", notstringerarrayv)         // ERROR "Printf format %q has arg notstringerarrayv of wrong type print.notstringerarray"
-       fmt.Printf("%d", BoolFormatter(true))       // ERROR "Printf format %d has arg BoolFormatter\(true\) of wrong type print.BoolFormatter"
+       fmt.Printf("%s", stringerv)                 // ERROR "Printf format %s has arg stringerv of wrong type .*print.ptrStringer"
+       fmt.Printf("%t", stringerv)                 // ERROR "Printf format %t has arg stringerv of wrong type .*print.ptrStringer"
+       fmt.Printf("%s", embeddedStringerv)         // ERROR "Printf format %s has arg embeddedStringerv of wrong type .*print.embeddedStringer"
+       fmt.Printf("%t", embeddedStringerv)         // ERROR "Printf format %t has arg embeddedStringerv of wrong type .*print.embeddedStringer"
+       fmt.Printf("%q", notstringerv)              // ERROR "Printf format %q has arg notstringerv of wrong type .*print.notstringer"
+       fmt.Printf("%t", notstringerv)              // ERROR "Printf format %t has arg notstringerv of wrong type .*print.notstringer"
+       fmt.Printf("%t", stringerarrayv)            // ERROR "Printf format %t has arg stringerarrayv of wrong type .*print.stringerarray"
+       fmt.Printf("%t", notstringerarrayv)         // ERROR "Printf format %t has arg notstringerarrayv of wrong type .*print.notstringerarray"
+       fmt.Printf("%q", notstringerarrayv)         // ERROR "Printf format %q has arg notstringerarrayv of wrong type .*print.notstringerarray"
+       fmt.Printf("%d", BoolFormatter(true))       // ERROR "Printf format %d has arg BoolFormatter\(true\) of wrong type .*print.BoolFormatter"
        fmt.Printf("%z", FormatterVal(true))        // correct (the type is responsible for formatting)
        fmt.Printf("%d", FormatterVal(true))        // correct (the type is responsible for formatting)
        fmt.Printf("%s", nonemptyinterface)         // correct (the type is responsible for formatting)
@@ -186,10 +186,10 @@ func PrintfTests() {
        Printf("d%", 2)                       // ERROR "Printf format % is missing verb at end of string"
        Printf("%d", percentDV)
        Printf("%d", &percentDV)
-       Printf("%d", notPercentDV)  // ERROR "Printf format %d has arg notPercentDV of wrong type print.notPercentDStruct"
-       Printf("%d", &notPercentDV) // ERROR "Printf format %d has arg &notPercentDV of wrong type \*print.notPercentDStruct"
+       Printf("%d", notPercentDV)  // ERROR "Printf format %d has arg notPercentDV of wrong type .*print.notPercentDStruct"
+       Printf("%d", &notPercentDV) // ERROR "Printf format %d has arg &notPercentDV of wrong type \*.*print.notPercentDStruct"
        Printf("%p", &notPercentDV) // Works regardless: we print it as a pointer.
-       Printf("%q", &percentDV)    // ERROR "Printf format %q has arg &percentDV of wrong type \*print.percentDStruct"
+       Printf("%q", &percentDV)    // ERROR "Printf format %q has arg &percentDV of wrong type \*.*print.percentDStruct"
        Printf("%s", percentSV)
        Printf("%s", &percentSV)
        // Good argument reorderings.
@@ -234,7 +234,7 @@ func PrintfTests() {
        Printf("%T", someFunction) // ok: maybe someone wants to see the type
        // Bug: used to recur forever.
        Printf("%p %x", recursiveStructV, recursiveStructV.next)
-       Printf("%p %x", recursiveStruct1V, recursiveStruct1V.next) // ERROR "Printf format %x has arg recursiveStruct1V\.next of wrong type \*print\.RecursiveStruct2"
+       Printf("%p %x", recursiveStruct1V, recursiveStruct1V.next) // ERROR "Printf format %x has arg recursiveStruct1V\.next of wrong type \*.*print\.RecursiveStruct2"
        Printf("%p %x", recursiveSliceV, recursiveSliceV)
        Printf("%p %x", recursiveMapV, recursiveMapV)
        // Special handling for Log.
@@ -587,37 +587,37 @@ func UnexportedStringerOrError() {
        fmt.Printf("%s", unexportedInterface{3})     // ok; we can't see the problem
 
        us := unexportedStringer{}
-       fmt.Printf("%s", us)  // ERROR "Printf format %s has arg us of wrong type print.unexportedStringer"
-       fmt.Printf("%s", &us) // ERROR "Printf format %s has arg &us of wrong type [*]print.unexportedStringer"
+       fmt.Printf("%s", us)  // ERROR "Printf format %s has arg us of wrong type .*print.unexportedStringer"
+       fmt.Printf("%s", &us) // ERROR "Printf format %s has arg &us of wrong type [*].*print.unexportedStringer"
 
        usf := unexportedStringerOtherFields{
                s: "foo",
                S: "bar",
        }
-       fmt.Printf("%s", usf)  // ERROR "Printf format %s has arg usf of wrong type print.unexportedStringerOtherFields"
-       fmt.Printf("%s", &usf) // ERROR "Printf format %s has arg &usf of wrong type [*]print.unexportedStringerOtherFields"
+       fmt.Printf("%s", usf)  // ERROR "Printf format %s has arg usf of wrong type .*print.unexportedStringerOtherFields"
+       fmt.Printf("%s", &usf) // ERROR "Printf format %s has arg &usf of wrong type [*].*print.unexportedStringerOtherFields"
 
        ue := unexportedError{
                e: &errorer{},
        }
-       fmt.Printf("%s", ue)  // ERROR "Printf format %s has arg ue of wrong type print.unexportedError"
-       fmt.Printf("%s", &ue) // ERROR "Printf format %s has arg &ue of wrong type [*]print.unexportedError"
+       fmt.Printf("%s", ue)  // ERROR "Printf format %s has arg ue of wrong type .*print.unexportedError"
+       fmt.Printf("%s", &ue) // ERROR "Printf format %s has arg &ue of wrong type [*].*print.unexportedError"
 
        uef := unexportedErrorOtherFields{
                s: "foo",
                e: &errorer{},
                S: "bar",
        }
-       fmt.Printf("%s", uef)  // ERROR "Printf format %s has arg uef of wrong type print.unexportedErrorOtherFields"
-       fmt.Printf("%s", &uef) // ERROR "Printf format %s has arg &uef of wrong type [*]print.unexportedErrorOtherFields"
+       fmt.Printf("%s", uef)  // ERROR "Printf format %s has arg uef of wrong type .*print.unexportedErrorOtherFields"
+       fmt.Printf("%s", &uef) // ERROR "Printf format %s has arg &uef of wrong type [*].*print.unexportedErrorOtherFields"
 
        uce := unexportedCustomError{
                e: errorer{},
        }
-       fmt.Printf("%s", uce) // ERROR "Printf format %s has arg uce of wrong type print.unexportedCustomError"
+       fmt.Printf("%s", uce) // ERROR "Printf format %s has arg uce of wrong type .*print.unexportedCustomError"
 
        uei := unexportedErrorInterface{}
-       fmt.Printf("%s", uei)       // ERROR "Printf format %s has arg uei of wrong type print.unexportedErrorInterface"
+       fmt.Printf("%s", uei)       // ERROR "Printf format %s has arg uei of wrong type .*print.unexportedErrorInterface"
        fmt.Println("foo\n", "bar") // not an error
 
        fmt.Println("foo\n")  // ERROR "Println arg list ends with redundant newline"
@@ -627,7 +627,7 @@ func UnexportedStringerOrError() {
        intSlice := []int{3, 4}
        fmt.Printf("%s", intSlice) // ERROR "Printf format %s has arg intSlice of wrong type \[\]int"
        nonStringerArray := [1]unexportedStringer{{}}
-       fmt.Printf("%s", nonStringerArray)  // ERROR "Printf format %s has arg nonStringerArray of wrong type \[1\]print.unexportedStringer"
+       fmt.Printf("%s", nonStringerArray)  // ERROR "Printf format %s has arg nonStringerArray of wrong type \[1\].*print.unexportedStringer"
        fmt.Printf("%s", []stringer{3, 4})  // not an error
        fmt.Printf("%s", [2]stringer{3, 4}) // not an error
 }
@@ -677,5 +677,5 @@ func PointersToCompoundTypes() {
        type T1 struct {
                X *T2
        }
-       fmt.Printf("%s\n", T1{&T2{"x"}}) // ERROR "Printf format %s has arg T1{&T2{.x.}} of wrong type print\.T1"
+       fmt.Printf("%s\n", T1{&T2{"x"}}) // ERROR "Printf format %s has arg T1{&T2{.x.}} of wrong type .*print\.T1"
 }
index 6e8cc70440e54b15caa8257b56653171617eae55..e9b8c69d53bb65d0c4235befbff45bbce258e20e 100644 (file)
@@ -13,6 +13,7 @@ import (
        "log"
        "os"
        "os/exec"
+       "path"
        "path/filepath"
        "regexp"
        "strconv"
@@ -65,14 +66,9 @@ func Build(t *testing.T) {
        built = true
 }
 
-func vetCmd(t *testing.T, args ...string) *exec.Cmd {
-       cmd := exec.Command(testenv.GoToolPath(t), "vet", "-vettool="+binary)
-       cmd.Args = append(cmd.Args, args...)
-       testdata, err := filepath.Abs("testdata")
-       if err != nil {
-               t.Fatal(err)
-       }
-       cmd.Env = append(os.Environ(), "GOPATH="+testdata)
+func vetCmd(t *testing.T, arg, pkg string) *exec.Cmd {
+       cmd := exec.Command(testenv.GoToolPath(t), "vet", "-vettool="+binary, arg, path.Join("cmd/vet/testdata", pkg))
+       cmd.Env = os.Environ()
        return cmd
 }
 
@@ -119,7 +115,7 @@ func TestVet(t *testing.T) {
                                cmd.Env = append(cmd.Env, "GOOS=linux", "GOARCH=amd64")
                        }
 
-                       dir := filepath.Join("testdata/src", pkg)
+                       dir := filepath.Join("testdata", pkg)
                        gos, err := filepath.Glob(filepath.Join(dir, "*.go"))
                        if err != nil {
                                t.Fatal(err)