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

go/build: reads build tags lines even in the middle of source files #3914

Closed
gopherbot opened this issue Aug 6, 2012 · 8 comments
Closed

Comments

@gopherbot
Copy link

by raul.san@sent.com:

"go test" is not running some test files. The issue is solved when it's placed
the package line in the first line; but it's inconsistent from it can run some test
files having comment lines, new line, and then the package line.

For more information:
https://groups.google.com/forum/#!topic/golang-nuts/BF5alLvHZtg
@remyoudompheng
Copy link
Contributor

Comment 1:

You should attach a minimal set of files that fail.

@remyoudompheng
Copy link
Contributor

Comment 2:

$ cat p_test.go
// Comment.
package modsql
import "testing"
func TestBlob(t *testing.T) { println("hello") }
// +build sqlite
$ go test -v 
can't load package: package testa: no Go source files in /home/remy/travail/go/src/testa
$ go test -v -tags sqlite
=== RUN TestBlob
hello
--- PASS: TestBlob (0.00 seconds)
PASS
ok      testa   0.006s

@gopherbot
Copy link
Author

Comment 3 by raul.san@sent.com:

Note that I use a build constraint in the middle of my code because I'm testing the
output of a function which generates files with that header.
$ cat p_test.go
// Comment.
package foo
import ("fmt"; "testing")
func TestBlob(t *testing.T) { println("hello") }
func ExampleSQL() {
    fmt.Println("// +build sqlite")
    // Output:
/*
// +build sqlite
*/
}
$ go test -v 
can't load package: package .: no Go source files in /home/neo/go/foo
$ go test -v -tags sqlite
=== RUN TestBlob
hello
--- PASS: TestBlob (0.00 seconds)
=== RUN: ExampleSQL
--- PASS: ExampleSQL (0.00 seconds)
PASS
ok      _/home/neo/go/foo   0.006s

@rsc
Copy link
Contributor

rsc commented Aug 6, 2012

Comment 4:

People always depend on bugs. We have to fix them anyway.
Russ

@robpike
Copy link
Contributor

robpike commented Aug 9, 2012

Comment 5:

Labels changed: added priority-soon, removed priority-triage.

Owner changed to @robpike.

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Aug 9, 2012

Comment 6:

I think remy has a fix for this

@remyoudompheng
Copy link
Contributor

Comment 7:

This issue was closed by revision f087764.

Status changed to Fixed.

@robpike
Copy link
Contributor

robpike commented Aug 22, 2012

Comment 8:

Issue #3992 has been merged into this issue.

gopherbot pushed a commit that referenced this issue May 11, 2015
…contents of file.

««« backport 307fafbc2d6f
go/build: correct shouldBuild bug reading whole contents of file.

It was caused by bytes.TrimSpace being able to return a nil
slice.

Fixes #3914.

R=golang-dev, r
CC=golang-dev, remy
https://golang.org/cl/6458091

»»»
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
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