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

testing: Logf's documentation is not precise #16423

Closed
yaojingguo opened this issue Jul 19, 2016 · 3 comments
Closed

testing: Logf's documentation is not precise #16423

yaojingguo opened this issue Jul 19, 2016 · 3 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@yaojingguo
Copy link
Contributor

  1. What version of Go are you using (go version)?
go version go1.6.2 linux/amd64

Logf's documentation says:

Logf formats its arguments according to the format, analogous to
Printf, and records the text in the error log. For tests, the text
will be printed only if the test fails or the -test.v flag is set.
For benchmarks, the text is always printed to avoid having
performance depend on the value of the -test.v flag.

Consider this code:

package test

import (
    "testing"
)

func TestLog(t *testing.T) {
    t.Logf("text")
    t.Logf("text\n")
}

Running the tet case with "go test -v -run TestLog" produces::

=== RUN   TestLog
--- PASS: TestLog (0.00s)
    log_test.go:8: text
    log_test.go:9: text
PASS
ok      github.com/yaojingguo/test  0.001s

t.Logf("text") and t.Logf("text\n") produces the same result. So it
can be concluded that Logf appends a new line to a string without
a ending new line. I think that it is better to mention this behavior
in Logf's documentation.

@ianlancetaylor ianlancetaylor added this to the Go1.8 milestone Jul 19, 2016
@0xmohit
Copy link
Contributor

0xmohit commented Jul 19, 2016

The current documentation does mention that; however, it could have been more clear.

log.Printf says:

Printf calls Output to print to the standard logger. Arguments are handled
in the manner of fmt.Printf.

and log.Output says:

Output writes the output for a logging event. The string s contains the text
to print after the prefix specified by the flags of the Logger. A newline is
appended if the last character of s is not already a newline. Calldepth is
the count of the number of frames to skip when computing the file name and
line number if Llongfile or Lshortfile is set; a value of 1 will print the
details for the caller of Output.

Maybe analogous to Printf could use log.Printf instead of Printf thereby avoiding confusion with fmt.Printf.

@robpike robpike self-assigned this Jul 19, 2016
@yaojingguo
Copy link
Contributor Author

testing.T's Logf formats a message with decorate function. decorate formats a message in a different way than log.Printf. For example, it indents the the first line of the message with a tab. And it intents second and subsequent lines with two tabs, etc.

And testing.B.Logf's documentation has the same problem as testing.T.Logf.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 10, 2016
@gopherbot
Copy link

CL https://golang.org/cl/31255 mentions this issue.

@golang golang locked and limited conversation to collaborators Oct 16, 2017
@rsc rsc unassigned robpike Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants