Sunday, November 30, 2025
HomeGolangGo check and examples - Getting Assist

Go check and examples – Getting Assist


I’ve a undertaking with the next simplified construction:

chessImager
  ..
  examples (folder)
  checks (folder)
  ...
  chessImager.go
  ...

If I run my go check ./... from the checks folder, all of the checks works tremendous. But when I run go check ./... from the chessImager folder, I get the next error:

# github.com/Hultan/chessImager/examples
examples/medium.go:10:6: fundamental redeclared on this block
	examples/superior.go:10:6: different declaration of fundamental
examples/different.go:10:6: fundamental redeclared on this block
	examples/superior.go:10:6: different declaration of fundamental
examples/easy.go:10:6: fundamental redeclared on this block
	examples/superior.go:10:6: different declaration of fundamental
?   	github.com/Hultan/chessImager	[no test files]
okay  	github.com/Hultan/chessImager/check	1.997s
FAIL

The examples folder doesn’t include any testable recordsdata (*_test.go), so why is it complaining about that folder? Ought to I as a substitute create sub folders for every instance, to keep away from issues like this?

My undertaking:

It’s because all recordsdata within the instance listing are declared with bundle fundamental and are in the identical bundle. Go will attempt to compile all of them collectively, besides fails when it hits fundamental for a second time. I like to recommend making a subdirectory for every instance with a fundamental perform within the examples listing.

I perceive that half, let me make clear my query.

There are not any testable recordsdata within the instance folder (no recordsdata that ends with _test), so what I ponder is why it even bothers to attempt to compile that folder?

I assumed that it seemed for check recordsdata and compiled what it wanted for that?

And as I wrote the final sentence I believe I spotted what the issue is. I’ve a file known as examples_test.go, that checks that the examples work. That check should set off the compilation of the instance folder.

So your suggestion to make use of sub folders for every instance ought to repair that…Thanx…

Go check additionally makes an attempt to construct all packages, when specified with the wildcard syntax as you probably did. Should you don’t need it to attempt to construct fundamental, then you definitely’ll need to specify the packages one after the other.

Go check additionally makes an attempt to construct all packages, when specified with the wildcard syntax as you probably did. Should you don’t need it to attempt to construct fundamental, then you definitely’ll need to specify the packages one after the other.

Then that’s the rationalization for this conduct.

I talked about examples_test.go earlier than, however that check file has its personal copies of the instance code within the check file, so that ought to not set off the constructing of the examples folder. I didn’t have the code in entrance of me once I replied the primary time.

Thanks for the assistance…

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments