New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/vet: gives errors about import paths when used on test files in Windows #24587

Closed
veqryn opened this Issue Mar 29, 2018 · 13 comments

Comments

Projects
None yet
5 participants
@veqryn

veqryn commented Mar 29, 2018

What version of Go are you using (go version)?

go version go1.10 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\cduncan\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\cduncan\workspace\go
set GORACE=
set GOROOT=C:\Go
set GOTMPDIR=
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-IC:\Users\cduncan\workspace\programs\oracle\windows\instantclient_12_1\sdk\include
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-LC:\Users\cduncan\workspace\programs\oracle\windows\instantclient_12_1 -loci
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\cduncan\AppData\Local\Temp\go-build922471030=/tmp/go-build -gno-record-gcc-switches

What did you do?

I have a file and some tests.
All third party code has been vendored into the vendor directory using go dep version v0.4.1
The tests have these imports:

import (
	"bytes"
	"context"
	"encoding/json"
	"fmt"
	"net"
	"net/http"
	"runtime/debug"
	"sync"
	"testing"
	"time"

	"github.com/ReturnPath/ecm/lib/util"
	"github.com/ReturnPath/ecm/lib/vendor_mocks/aws/mock_firehoseiface"
	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/service/firehose"
	"github.com/elodina/go-avro"
	"github.com/golang/mock/gomock"
	"github.com/valyala/fasthttp"
)

What did you expect to see?

With Golang 1.9.2 (my previous version), go vet gave me an 'all clear'.
The files and the tests also compile and run perfectly fine.

What did you see instead?

C:\Users\cduncan>go vet C:\Users\cduncan\workspace\go\src\github.com\ReturnPath\ecm\services\pixel_server\pixel_server_test.go
# github.com\ReturnPath\ecm/vendor/github.com/aws/aws-sdk-go/aws
workspace\go\src\github.com\ReturnPath\ecm\vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: import path contains backslash; use slash: "github.com\\ReturnPath\\ecm/vendor/github.com/aws/aws-sdk-go/aws/awserr"
workspace\go\src\github.com\ReturnPath\ecm\vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: cannot import "github.com\\ReturnPath\\ecm/vendor/github.com/aws/aws-sdk-go/aws/credentials" due to version skew - reinstall package (bad package path "github.com\\ReturnPath\\ecm/vendor/github.com/aws/aws-sdk-go/aws/awserr" for package awserr)
# github.com\ReturnPath\ecm/vendor/github.com/valyala/fasthttp
workspace\go\src\github.com\ReturnPath\ecm\vendor\github.com\valyala\fasthttp\compress.go:10:2: import path contains backslash; use slash: "github.com\\ReturnPath\\ecm/vendor/github.com/klauspost/compress/flate"
workspace\go\src\github.com\ReturnPath\ecm\vendor\github.com\valyala\fasthttp\compress.go:10:2: cannot import "github.com\\ReturnPath\\ecm/vendor/github.com/klauspost/compress/gzip" due to version skew - reinstall package (bad package path "github.com\\ReturnPath\\ecm/vendor/github.com/klauspost/compress/flate" for package flate)

Also to note: go tool vet doesn't return anything. I'm still not sure what the difference between them is.

And go vet on the non-test file (go vet C:\Users\cduncan\workspace\go\src\github.com\ReturnPath\ecm\services\pixel_server\pixel_server.go) returns an all clear

@veqryn

This comment has been minimized.

veqryn commented Mar 29, 2018

go vet on test files also fails to find methods in other test files in the same directory and package:

# command-line-arguments
services\pixel_server\pixel_server_benchmark_test.go:30:62: undefined: setup
services\pixel_server\pixel_server_benchmark_test.go:45:3: undefined: Must

^ Those methods exist in a different test file in the same dir/package. All my tests in all these files run and succeed perfectly fine.

@ALTree ALTree changed the title from Go vet gives errors about import paths when used on test files in Windows to cmd/vet: gives errors about import paths when used on test files in Windows Mar 29, 2018

@mvdan mvdan added the OS-Windows label Mar 29, 2018

@mvdan

This comment has been minimized.

Member

mvdan commented Mar 29, 2018

Is there a good and easy way to reproduce and test fixes for these things while on a different operating system? Other than running a virtual machine, that is.

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Mar 29, 2018

Is there a way that we can recreate the problems ourselves?

Are the vet errors correct? Or do the files contain forward slashes although vet is complaining about backslashes?

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Mar 29, 2018

@veqryn

This comment has been minimized.

veqryn commented Mar 29, 2018

Sorry for not posting a short way to reproduce this, I did not have the time yesterday but wanted to put the bug in before I forgot.

Here is a short way to reproduce, even if it is a bit contrived:

Create the following files, then also download github.com/aws/aws-sdk-go to a vendor directory at or above the same level as these files.

vet_bug.go

package vet_bug

func Add(a, b int) int {
	return a + b
}

vet_bug_test.go

package vet_bug

import (
	"testing"
)

func TestAdd(t *testing.T) {
	inouts := []struct {
		a int
		b int
		r int
	}{
		{a: 0, b: 0, r: 0},
		{a: 1, b: 1, r: 2},
		{a: 3, b: 5, r: 8},
	}

	for _, inout := range inouts {
		AssertEqual(t, inout.r, Add(inout.a, inout.b))
	}
}

util_test.go

package vet_bug

import (
	"fmt"
	"testing"

	"github.com/aws/aws-sdk-go/aws"
)

func AssertEqual(tb testing.TB, expected, actual int) {
	tb.Helper()

	// Pointless, but gives us an error in `go vet`
	config := aws.Config{}
	fmt.Println(config)

	if expected != actual {
		tb.Error("Expected:", expected, "; Got:", actual)
	}
}

When running go vet on the util_test.go file, I get:

# command-line-arguments
src\vet_bug\vet_bug_test.go:19:3: undefined: AssertEqual
src\vet_bug\vet_bug_test.go:19:27: undefined: Add

When running go vet on the vet_bug_test.go file, I get:

# github.com\veqryn\personal/vendor/github.com/aws/aws-sdk-go/aws
vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: import path contains backslash; use slash: "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/awserr"
vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: cannot import "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/credentials" due to version skew - reinstall package (bad package path "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/awserr" for package awserr)

Here are the contents of the file it is referencing: https://github.com/aws/aws-sdk-go/blob/master/aws/config.go

package aws

import (
	"net/http"
	"time"

	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/endpoints"
)

// The rest of the file...

The tests pass.
The vet errors are obviously wrong, on both counts.

I would also love if someone could tell me what the difference is between go vet and go tool vet, and why both exist?

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Mar 29, 2018

The difference between go vet and go tool vet is documented at https://golang.org/cmd/vet (jump down to the bottom). In general you will be fine if you forget that go tool vet exists.

After you follow the instructions you describe, what does the start of vendor\github.com\aws\aws-sdk-go\aws\config.go look like on your system? On my system it does not contain any backslashes:

package aws

import (
	"net/http"
	"time"

	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/endpoints"
)

When you say "run go vet on the file x.go" what precisely are you typing?

@veqryn

This comment has been minimized.

veqryn commented Mar 29, 2018

I have the exact same as you for the top portion of that config file.
I am running go vet util_test.go

Here is git-bash terminal showing the issue:

MinGW 04:40:14 ~/workspace/go/src/github.com/veqryn/personal/src/vet_bug$ go vet ./vet_bug_test.go
# command-line-arguments
.\vet_bug_test.go:19:3: undefined: AssertEqual
.\vet_bug_test.go:19:27: undefined: Add
MinGW 04:40:25 ~/workspace/go/src/github.com/veqryn/personal/src/vet_bug$ go vet ./util_test.go
# github.com\veqryn\personal/vendor/github.com/aws/aws-sdk-go/aws
..\..\vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: import path contains backslash; use slash: "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/awserr"
..\..\vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: cannot import "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/credentials" due to version skew - reinstall package (bad package path "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/awserr" for package awserr)

Here is good old cmd.exe showing the same issue:

C:\Users\cduncan\workspace\go\src\github.com\veqryn\personal\src\vet_bug>go vet .\vet_bug_test.go
# command-line-arguments
.\vet_bug_test.go:19:3: undefined: AssertEqual
.\vet_bug_test.go:19:27: undefined: Add

C:\Users\cduncan\workspace\go\src\github.com\veqryn\personal\src\vet_bug>go vet .\util_test.go
# github.com\veqryn\personal/vendor/github.com/aws/aws-sdk-go/aws
..\..\vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: import path contains backslash; use slash: "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/awserr"
..\..\vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: cannot import "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/credentials" due to version skew - reinstall package (bad package path "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/awserr" for package awserr)

C:\Users\cduncan\workspace\go\src\github.com\veqryn\personal\src\vet_bug>
C:\Users\cduncan\workspace\go\src\github.com\veqryn\personal\src\vet_bug>cat ..\..\vendor\github.com\aws\aws-sdk-go\aws\config.go
package aws

import (
        "net/http"
        "time"

        "github.com/aws/aws-sdk-go/aws/credentials"
        "github.com/aws/aws-sdk-go/aws/endpoints"
)

// UseServiceDefaultRetries instructs the config to use the service's own
@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Mar 29, 2018

In Go 1.10, you generally should not run go vet file.go. You should run go vet on a package. If you want to run vet on a single file, use go tool vet file.go.

But I am at a loss as to why you are seeing what you are seeing. Can anyone else recreate the problem?

@veqryn

This comment has been minimized.

veqryn commented Mar 29, 2018

If you run go vet on a package instead of a file, will it vet your test files too?

I believe this error would only occur on Windows, since it is related to the slash vs backslash. go vet did work without these errors on 1.9.x
cannot import "github.com\\veqryn\\personal/vendor/github.com/aws/aws-sdk-go/aws/credentials"

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Mar 30, 2018

If you run go vet on a package instead of a file, will it vet your test files too?

Yes.

@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Apr 2, 2018

If I follow instructions as per #24587 (comment) I can reproduce the problem:

c:\Users\Alex\dev\src\issue\go\24587>dir
 Volume in drive C has no label.
 Volume Serial Number is 9872-A123

 Directory of c:\Users\Alex\dev\src\issue\go\24587

02/04/2018  05:39 PM    <DIR>          .
02/04/2018  05:39 PM    <DIR>          ..
02/04/2018  05:35 PM               328 util_test.go
02/04/2018  05:39 PM    <DIR>          vendor
02/04/2018  05:35 PM                58 vet_bug.go
02/04/2018  05:35 PM               275 vet_bug_test.go
               3 File(s)            661 bytes
               3 Dir(s)  395,254,607,872,872,456 bytes free

c:\Users\Alex\dev\src\issue\go\24587>go vet util_test.go
# issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws
vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: import path contains backslash; use slash: "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws/awserr"
vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: cannot import "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws/credentials" due to version skew - reinstall package (bad package path "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws/awserr" for package awserr)

c:\Users\Alex\dev\src\issue\go\24587>

I did not have time to investigate why this is happening.

Alex

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Jun 14, 2018

The error messages import path contains backslash is coming from the compiler, of all things. I do not know why the compiler would be seeing backslash import paths when invoked via go vet, when presumably it does not see them when invoked via go build or go test. It might possibly be interesting to see the output of go vet -x. But I suspect that this will need to be debugged by somebody on a WIndows system.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.11, Go1.12 Jun 14, 2018

@alexbrainman

This comment has been minimized.

Member

alexbrainman commented Jun 16, 2018

It might possibly be interesting to see the output of go vet -x

This seems to be "fixed" on master now. I bisected fix to a3c75d9 I have no explanation why this commit "fixes" the issue.

For still broken ca2f85f I can see this:

c:\Users\Alex\dev\src\issue\go\24587>go vet -x util_test.go
WORK=C:\Users\Alex\AppData\Local\Temp\go-build629829662
mkdir -p $WORK\b028\
cat >$WORK\b028\importcfg << 'EOF' # internal
# import config
importmap github.com/aws/aws-sdk-go/aws/awserr=issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws/awserr
importmap github.com/aws/aws-sdk-go/aws/credentials=issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws/credentials
importmap github.com/aws/aws-sdk-go/aws/endpoints=issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws/endpoints
importmap github.com/aws/aws-sdk-go/internal/sdkio=issue\go\24587/vendor/github.com/aws/aws-sdk-go/internal/sdkio
packagefile context=c:\users\alex\dev\go\pkg\windows_amd64\context.a
packagefile issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws/awserr=C:\Users\Alex\AppData\Local\go-build\dd\ddf648788bc1193a4f07ecd81bee3229b2649abfb45afcd2147a75f42f9068f6-d
packagefile issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws/credentials=C:\Users\Alex\AppData\Local\go-build\18\1832e9418ff2af4a81beab754f94cb8c5f39248a59a96c2816f6e7517266fb3a-d
packagefile issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws/endpoints=C:\Users\Alex\AppData\Local\go-build\07\072a8a3ad083fb587d20dfe21dd04c5ee757f7ba5c0518c3fc28398bd67458ed-d
packagefile issue\go\24587/vendor/github.com/aws/aws-sdk-go/internal/sdkio=C:\Users\Alex\AppData\Local\go-build\52\521fa83f44806e2fcbe32f53bf2c4c3fcf7cb2f667ad47e58ff2a38d64527727-d
packagefile io=c:\users\alex\dev\go\pkg\windows_amd64\io.a
packagefile log=c:\users\alex\dev\go\pkg\windows_amd64\log.a
packagefile net/http=c:\users\alex\dev\go\pkg\windows_amd64\net\http.a
packagefile net/url=c:\users\alex\dev\go\pkg\windows_amd64\net\url.a
packagefile os=c:\users\alex\dev\go\pkg\windows_amd64\os.a
packagefile sync=c:\users\alex\dev\go\pkg\windows_amd64\sync.a
packagefile time=c:\users\alex\dev\go\pkg\windows_amd64\time.a
EOF
cd c:\users\alex\dev\src\issue\go\24587\vendor\github.com\aws\aws-sdk-go\aws
"c:\\users\\alex\\dev\\go\\pkg\\tool\\windows_amd64\\compile.exe" -o "C:\\Users\\Alex\\AppData\\Local\\Temp\\go-build629829662\\b028\\_pkg_.a" -trimpath "C:\\Users\\Alex\\AppData\\Local\\Temp\\go-build629829662\\b028" -p "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws" -complete -buildid m1gHqaXUK7LJtLwhlpmg/m1gHqaXUK7LJtLwhlpmg -D "" -importcfg "C:\\Users\\Alex\\AppData\\Local\\Temp\\go-build629829662\\b028\\importcfg" -pack -c=4 "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\config.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\context.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\context_1_7.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\convert_types.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\doc.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\errors.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\jsonvalue.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\logger.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\types.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\url.go" "c:\\users\\alex\\dev\\src\\issue\\go\\24587\\vendor\\github.com\\aws\\aws-sdk-go\\aws\\version.go"
# issue\go\24587/vendor/github.com/aws/aws-sdk-go/aws
vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: import path contains backslash; use slash: "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws/awserr"
vendor\github.com\aws\aws-sdk-go\aws\config.go:7:2: cannot import "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws/credentials" due to version skew - reinstall package (bad package path "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws/awserr" for package awserr)

c:\Users\Alex\dev\src\issue\go\24587>

For fixed a3c75d9 I can see:

c:\Users\Alex\dev\src\issue\go\24587>go vet -x util_test.go
WORK=C:\Users\Alex\AppData\Local\Temp\go-build846846678
mkdir -p $WORK\b001\
cat >$WORK\b001\vet.cfg << 'EOF' # internal
{
        "Compiler": "gc",
        "Dir": "c:\\Users\\Alex\\dev\\src\\issue\\go\\24587",
        "GoFiles": [
                "c:\\Users\\Alex\\dev\\src\\issue\\go\\24587\\util_test.go"
        ],
        "ImportMap": {
                "fmt": "fmt",
                "github.com/aws/aws-sdk-go/aws": "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws",
                "testing": "testing"
        },
        "PackageFile": {
                "fmt": "c:\\users\\alex\\dev\\go\\pkg\\windows_amd64\\fmt.a",
                "issue\\go\\24587/vendor/github.com/aws/aws-sdk-go/aws": "C:\\Users\\Alex\\AppData\\Local\\go-build\\19\\19bae1aa32aca89bf2d5cec56124a047b3dae594a9daca994bb97e0e6a047163-d",
                "testing": "c:\\users\\alex\\dev\\go\\pkg\\windows_amd64\\testing.a"
        },
        "ImportPath": "command-line-arguments",
        "SucceedOnTypecheckFailure": false
}
EOF
cd c:\Users\Alex\dev\src\issue\go\24587
"c:\\users\\alex\\dev\\go\\pkg\\tool\\windows_amd64\\vet.exe" "C:\\Users\\Alex\\AppData\\Local\\Temp\\go-build846846678\\b001\\vet.cfg"

c:\Users\Alex\dev\src\issue\go\24587>

Alex

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Dec 11, 2018

Optimistically closing as fixed based on previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment