Skip to content
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/go: unable to test a package if it's import path is main #10738

Closed
martinellison opened this issue May 7, 2015 · 6 comments
Closed

cmd/go: unable to test a package if it's import path is main #10738

martinellison opened this issue May 7, 2015 · 6 comments

Comments

@martinellison
Copy link

It seems that calling a package using a directory main has special (bad) effects. Please document this in the documentation for the package statement.

You also might want to issue a warning if anyone tries to define a package use a folder called main.

Corrected to reflect minux' comment below.

@minux
Copy link
Member

minux commented May 7, 2015 via email

@martinellison
Copy link
Author

Sorry, I've checked further. The problem is actually having a directory called main. I had naively assumed that with one package per directory, one should call the directory the same name as the package it contains. Apparently, this does not work for package main. (So what minux says is correct, but there is still a problem; I have updated the original post).

@adg
Copy link
Contributor

adg commented May 7, 2015

What are the "bad effects"?

@martinellison
Copy link
Author

  1. When I try go test main I get: /tmp/go-build550118144/main/_test/_testmain.go:9: cannot import "main" and FAIL main [build failed]
  2. When I try godoc main (1) godoc treats main as a command not a package and (2) godoc does not document my funcs and vars (even if they are Public).

See https://groups.google.com/forum/#!topic/golang-nuts/ubYw0OQXLvA

@minux minux changed the title Please document package 'main' cmd/go: unable to test a package if it's import path is main May 7, 2015
@minux
Copy link
Member

minux commented May 7, 2015

The problem is that the test driver (_testmain.go) needs to import the
package and if the import path is "main", gc will refuse to import it.

The reason is simple, the packages in Go program must have unique import
paths, but as the main package must have the import path "main", you can't
import another "main" package.

This is working as intended.

@minux minux closed this as completed May 7, 2015
@martinellison
Copy link
Author

ok, but this should be documented so other newbies do not make the same
mistake.

Regards,
Martin

On 7 May 2015 at 14:09, Minux Ma notifications@github.com wrote:

Closed #10738 #10738.


Reply to this email directly or view it on GitHub
#10738 (comment).

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants