-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: cmd/go: support cgo in test files #18647
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
Comments
Allowing cgo in tests adds complication. Why is it important to do this? |
From the outside, I was surprised when I learned that cgo cannot appear in tests and thought it felt arbitrary. I still don't even really understand why, I just work around it. I do think it can be rather annoying as well. If I define a Go function which takes a It would be great if test files could call C functions, but I really be glad if I were just able to reference C types. |
@minux, do you know how many lines would need to change in the go command for this? If it's a small change then maybe it's OK to do. |
I understand that this is handy, but I started to look into it and got stuck pretty quickly. The info about the package is https://golang.org/pkg/go/build/#Package and you'd need to add TestCgoFiles and maybe XTestCgoFiles, but then what about CgoCFLAGS? Does that collect all of them? What about CFiles, HFiles, etc? It seems like a lot of trouble when there's a reasonable workaround for this not-too-common case already. |
Closing since it is very difficult and doesn't seem worth it. |
Currently it's impossible to use cgo in x_test.go files.
Given that we support coverage tests on cgo using packages,
there really is no reason that we can't support using cgo in
test files (and besides, we don't need to rewrite any x_test.go
files, so I don't know why we have such a limitation in the first
place. perhaps it's because we doesn't has a TestCgoFiles
field in go/build.Package?)
The main problem of not supporting cgo in test file is:
because there is no test build tag, there is no way to
export a cgo function for test that is not also included in the
package (true, deadcode elimination might remove those
functions, but what about C helpers needed by such function?
our linker can't do deadcode elimination on C functions).
The text was updated successfully, but these errors were encountered: