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

cmd/go: go test -h output doesn't work with less #28087

Closed
willfaught opened this issue Oct 9, 2018 · 4 comments
Closed

cmd/go: go test -h output doesn't work with less #28087

willfaught opened this issue Oct 9, 2018 · 4 comments
Labels
FrozenDueToAge GoCommand cmd/go WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@willfaught
Copy link
Contributor

What did you do?

I tried to read the go test -h doc with less, like I usually do.

What did you expect to see?

$ go test -h | less

Then, fullscreen:

usage: go test [build/test flags] [packages] [build/test flags & test binary flags]
[...]
:

What did you see instead?

$ go test -h | less

Then, fullscreen:

[...]
In the first example, the -x and the second -v are passed through to the
test binary unchanged and with no effect on the go command itself.
In the second example, the argument math is passed through to the test
binary, instead of being interpreted as the package list.
(END)

The head of the doc is off screen, and pressing the less navigation keys j/k/g/G clears the screen and just shows an empty file:

[...]
~
~
~
~
~
~
~
(END)

System details

go version go1.11.1 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/will/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/will/Developer/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
GOROOT/bin/go version: go version go1.11.1 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.11.1
uname -v: Darwin Kernel Version 17.7.0: Thu Jun 21 22:53:14 PDT 2018; root:xnu-4570.71.2~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.6
BuildVersion:	17G65
lldb --version: lldb-1000.11.37.1
  Swift-4.2
@dmitshur dmitshur changed the title go test -h output doesn't work with less cmd/go: go test -h output doesn't work with less Oct 9, 2018
@dmitshur dmitshur added the GoCommand cmd/go label Oct 9, 2018
@dmitshur
Copy link
Contributor

dmitshur commented Oct 9, 2018

-h is not a valid flag for go help, so go test -h writes usage to stderr, not stdout, and exits with a non-zero exit code. The pipe only sends stdout to less.

The correct command to view help for go test is via the go help command:

go help test

Since it's a valid command, it prints to stdout and exits with zero exit code. So, you can do what you want:

go help test | less

As far as I know, this behavior is consistent with Unix-y tools.

E.g., git help writes help to stdout and exists with zero code. git -help writes "unknown option: -help" and usage to stderr and exists with non-zero code.

If you wanted to read go test -h output with less, despite it not being a valid flag, you can just redirect stderr to stdout before piping to less:

go test -h 2>&1 | less

@dmitshur dmitshur added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 9, 2018
@mvdan
Copy link
Member

mvdan commented Oct 9, 2018

I don't think -h is an invalid flag. I'm using go build here to demonstrate because go test -h is massive (that's #26999):

$ go build -h
usage: go build [-o output] [-i] [build flags] [packages]
Run 'go help build' for details.
$ go build -asdf
flag provided but not defined: -asdf
usage: go build [-o output] [-i] [build flags] [packages]
Run 'go help build' for details.

However, I agree that it's normal for usage text to be printed to stderr. A shorter version of what Dmitri suggested above, if you're on Bash, is go test -h |& less.

The issue I linked above would also fix your issue, I believe. go test -h should not output pages of text.

@dmitshur
Copy link
Contributor

dmitshur commented Oct 9, 2018

Thanks for the correction @mvdan, -h is indeed a valid flag.

@willfaught
Copy link
Contributor Author

I see what you guys are saying. go test -h should behave like go build -h anyway. My issue was more that the behavior seemed to have changed, but I'll just use go help in the future, so it's not an issue.

@golang golang locked and limited conversation to collaborators Oct 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants