9

Getting an error when trying to run go build ./... from my $GOPATH/src .

no non-test Go files in <dir>

The error is correct there are no test files in <dir> but why is that causing a compile error? Is it a bug?

6
  • The error says there are no non-test files. There's nothing to build in that directory. Commented Oct 23, 2017 at 21:54
  • "from my $GOPATH/src" that doesn't sound right - that builds everything - what are you trying to build? Commented Oct 23, 2017 at 22:27
  • @fstanis everything Commented Oct 23, 2017 at 22:27
  • You are aware that go build ./... doesn't do anything, other than building things and throwing away the results, right? Commented Oct 23, 2017 at 22:44
  • @JimB go install ./... exits with the same error Commented Oct 23, 2017 at 22:46

3 Answers 3

5

Calling it a bug… the build shouldn't fail if the tests compile. Filed here: https://github.com/golang/go/issues/22409

The bug I filed was a duplicate of https://github.com/golang/go/issues/8279 looks like it was broken in 1.3.

Sign up to request clarification or add additional context in comments.

Comments

3

I don't think this is a bug, unless you see somewhere in the docs that contradicts this behaviour you should probably close the issue you've created.

Tests in go normally live in the package they are testing. You have made a new package with package main at the top (invalid if you also have main elsewhere), and then have included no go source files in that tests/main package (invalid as package has no go source files apart from tests, which the compiler complains about explicitly).

Possible solutions for you (assuming this isn't just a hypothetical question):

  • Move tests for main to test_main.go (this is what readers will expect)
  • Add doc.go file to your tests pkg and call it package tests in both files

The reason for putting tests in the same package is to ensure they have access to the entire package, if you want to split them to another package you'll find you have to test as an external user of the pkg - this may be painful. Main is also a special case as well as you don't normally import it.

1 Comment

That issue is closed with won’t fix
1

First, check your $GOPATH has been set correctly. Learn more at here.

Then, check if any '_' in your file name. Remove these '_'s and try again. ;-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.