Test file is not being run from go test

2,943 views
Skip to first unread message

Archos

unread,
Aug 6, 2012, 2:24:50 PM8/6/12
to golan...@googlegroups.com
I've a test file which is not being parsed/read by "go test". How is it possible?
Note that I'm using the flag -v to check it.

Rémy Oudompheng

unread,
Aug 6, 2012, 2:29:37 PM8/6/12
to golang-nuts
You should give details.

Rémy.

Patrick Mylund Nielsen

unread,
Aug 6, 2012, 2:33:00 PM8/6/12
to Archos, golan...@googlegroups.com
-v doesn't make a difference in behavior.

Include your filenames and contents.

Archos

unread,
Aug 6, 2012, 2:43:12 PM8/6/12
to golan...@googlegroups.com, Archos
I've testes using "go test modsql_test.go" and it shows an error related to undefined functions. This is strange because the package name is right

This is the file which is not being run:
https://github.com/kless/modsql/blob/master/modsql_test.go#L7

In change, there is not problem for this one:
https://github.com/kless/modsql/blob/master/column_test.go#L7

Rémy Oudompheng

unread,
Aug 6, 2012, 2:46:36 PM8/6/12
to Archos, golan...@googlegroups.com
On 2012/8/6 Archos <raul...@sent.com> wrote:
> I've testes using "go test modsql_test.go" and it shows an error related to
> undefined functions. This is strange because the package name is right
>
> This is the file which is not being run:
> https://github.com/kless/modsql/blob/master/modsql_test.go#L7
>
> In change, there is not problem for this one:
> https://github.com/kless/modsql/blob/master/column_test.go#L7

I'm not sure what you are doing: most test files expect to be included
in the package they are testing to work properly. I don't understand
how it is possible that you can go test column_test.go since it uses a
Column() function which is not defined anywhere.

Rémy.

Archos

unread,
Aug 6, 2012, 2:49:35 PM8/6/12
to golan...@googlegroups.com
Those functions are defined in the package, i.e. Column is defined in file column.go:

https://github.com/kless/modsql/blob/master/column.go

Archos

unread,
Aug 6, 2012, 2:52:52 PM8/6/12
to golan...@googlegroups.com
In addition, I can give faith respect to that both tests were run ok until today, when I've done several changes in the API.
Anyway, the subject is that it does not sense, at least for me, that go test can not run that test file.

Patrick Mylund Nielsen

unread,
Aug 6, 2012, 2:52:46 PM8/6/12
to Archos, golan...@googlegroups.com
What error do you get?

Try putting "package modsql" on line 1 of both files.

Archos

unread,
Aug 6, 2012, 2:57:17 PM8/6/12
to golan...@googlegroups.com
Oh my god, my head was to explode; it works when I put the package line in the first line.
But why, what has happened here? I don't understand it.

Rémy Oudompheng

unread,
Aug 6, 2012, 2:57:26 PM8/6/12
to Archos, golan...@googlegroups.com
On 2012/8/6 Archos <raul...@sent.com>:
> Those functions are defined in the package, i.e. Column is defined in file
> column.go:
>
> https://github.com/kless/modsql/blob/master/column.go

The go tool does not see that file nor the surrounding package if you
specify a filename. Se "go help packages" to know how to specify the
input of the go tool.

Rémy.

Archos

unread,
Aug 6, 2012, 3:04:29 PM8/6/12
to golan...@googlegroups.com
I'im using "to test -v" to run all tests in that directory, and modsql_test file of  is only run when I put the package line in the first line. The why? I don't know but this is a fact that it's hapenning to me with that file.

Patrick Mylund Nielsen

unread,
Aug 6, 2012, 3:06:32 PM8/6/12
to Archos, golan...@googlegroups.com
http://golang.org/ref/spec#Package_clause 

"A package clause begins each source file and defines the package to which the file belongs."

I assume go test only checks line 1 of _test.go files. I'm not sure if this is a bug since the spec isn't clear, but it probably is a bug that the behavior isn't consistent between tools. You should file an issue for this.

Archos

unread,
Aug 6, 2012, 3:35:17 PM8/6/12
to golan...@googlegroups.com

Rémy Oudompheng

unread,
Aug 6, 2012, 3:41:18 PM8/6/12
to Archos, golan...@googlegroups.com
On 2012/8/6 Archos <raul...@sent.com> wrote:
> http://code.google.com/p/go/issues/detail?id=3914

The go tool is confused by your // +build sqlite in the middle of the file.
Running go test -tags sqlite takes it into account.

It's probably either a bug or a feature in the parsing of build tags.

Rémy.
Reply all
Reply to author
Forward
0 new messages