Where is the test error log located?

2,119 views
Skip to first unread message

Ted Stockwell

unread,
Jun 8, 2012, 2:24:12 PM6/8/12
to golang-nuts
Hi All,

Apologies for being dense but I cannot figure out how to get 'go test'
to produce a log file.
Also, where is the error log located?

Thanks...

minux

unread,
Jun 8, 2012, 2:27:07 PM6/8/12
to Ted Stockwell, golang-nuts
On Sat, Jun 9, 2012 at 2:24 AM, Ted Stockwell <emor...@yahoo.com> wrote:
Apologies for being dense but I cannot figure out how to get 'go test'
to produce a log file.
Also, where is the error log located?
'go test' normally outputs directly to stdout/stderr.

if you want error log in a file, you can redirect stdout and stderr yourself.

Ted Stockwell

unread,
Jun 8, 2012, 2:44:29 PM6/8/12
to golang-nuts


On Jun 8, 1:27 pm, minux <minux...@gmail.com> wrote:
> On Sat, Jun 9, 2012 at 2:24 AM, Ted Stockwell <emorn...@yahoo.com> wrote:
> > Apologies for being dense but I cannot figure out how to get 'go test'
> > to produce a log file.
> > Also, where is the error log located?
>
> 'go test' normally outputs directly to stdout/stderr.
>
> if you want error log in a file, you can redirect stdout and stderr
> yourself.

Really? I'm missing something.


I've tried printing stuff out with testing.T.LogF and fmt.Printf and I
get nothing.
Like this...

package qwerty
import (
"fmt"
"testing"
)
func TestSomething(t *testing.T) {
t.Logf("hello")
fmt.Printf("hello")
}

I run my tests like this...

go test -v qwerty

"hello" never shows up anywhere. What am I missing?

minux

unread,
Jun 8, 2012, 2:50:56 PM6/8/12
to Ted Stockwell, golang-nuts


On Sat, Jun 9, 2012 at 2:44 AM, Ted Stockwell <emor...@yahoo.com> wrote:
I've tried printing stuff out with testing.T.LogF and fmt.Printf and I
get nothing.
Like this...

 package qwerty
 import (
  "fmt"
  "testing"
 )
 func TestSomething(t *testing.T) {
   t.Logf("hello")
   fmt.Printf("hello")
 }

I run my tests like this...

 go test -v qwerty

"hello" never shows up anywhere.  What am I missing?
$ go test -v qwerty_test.go 
=== RUN TestSomething
hello--- PASS: TestSomething (0.00 seconds)
qwerty_test.go:7: hello
PASS
ok   command-line-arguments 0.024s

in general, go test (without -v) won't show test outputs (simply discarded).

Ted Stockwell

unread,
Jun 8, 2012, 3:10:32 PM6/8/12
to golang-nuts


On Jun 8, 1:50 pm, minux <minux...@gmail.com> wrote:
>
> $ go test -v qwerty_test.go
> === RUN TestSomething
> hello--- PASS: TestSomething (0.00 seconds)
> qwerty_test.go:7: hello
> PASS
> ok   command-line-arguments 0.024s
>
> in general, go test (without -v) won't show test outputs (simply discarded).

Thanks for your help, I've figured it out.
My code had an error in it where I was calling panic and passing a
nil.
This somehow causes the test to immediately end (and thus never
calling the statements that do printing).
YET, the pass does not fail.

Try running this and you'll see what I mean...

package qwerty
import (
"fmt"
"testing"
)
func TestSomething(t *testing.T) {
panic(nil)
t.Logf("hello")
fmt.Printf("hello")
}



Is this a bug?

DisposaBoy

unread,
Jun 8, 2012, 4:36:01 PM6/8/12
to golan...@googlegroups.com
I'm not sure if it's a bug or not but that behaviour looks reasonable to me. If you're going to panic then you do so with an error, if that error is `nil` meaning there's no error then there's more to be done.

Ian Lance Taylor

unread,
Jun 8, 2012, 5:32:19 PM6/8/12
to DisposaBoy, golan...@googlegroups.com
DisposaBoy <dispo...@dby.me> writes:

> I'm not sure if it's a bug or not but that behaviour looks reasonable to
> me. If you're going to panic then you do so with an error, if that error is
> `nil` meaning there's no error then there's more to be done.

In general, if you call recover, there is no way to distinguish between
panic(nil) and no panic at all.

Ian

DisposaBoy

unread,
Jun 8, 2012, 5:38:05 PM6/8/12
to golan...@googlegroups.com, DisposaBoy


On Friday, June 8, 2012 10:32:19 PM UTC+1, Ian Lance Taylor wrote:
DisposaBoy writes:

That was kinda my point... looks like I accidentally a word. I meant to say "there's *nothing* more to be done" as opposed to "there's more..." 

Ted Stockwell

unread,
Jun 9, 2012, 12:37:38 AM6/9/12
to golang-nuts


On Jun 8, 3:36 pm, DisposaBoy <disposa...@dby.me> wrote:

>
> > Is this a bug?
>
> I'm not sure if it's a bug or not but that behaviour looks reasonable to
> me. If you're going to panic then you do so with an error, if that error is
> `nil` meaning there's no error then there's more to be done.

Is there any useful purpose for panic(nil)?
Seems like panic(nil) is just something for developers to trip over
now and then.
Maybe it would be better if calling panic(nil) just called panic("It
is illegal to falsely shout fire in a theatre")

Ian Lance Taylor

unread,
Jun 9, 2012, 12:17:23 PM6/9/12
to Ted Stockwell, golang-nuts
Special cases should only be added when they bring a clear advantage. I
don't think that is the case here. While I agree that panic(nil) is
best avoided, it works fine if nothing above you has deferred a call to
recover.

Ian
Reply all
Reply to author
Forward
0 new messages