Skip to content

go/test: Testable examples #50737

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
thomascoquet opened this issue Jan 21, 2022 · 1 comment
Closed

go/test: Testable examples #50737

thomascoquet opened this issue Jan 21, 2022 · 1 comment

Comments

@thomascoquet
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.18beta1 linux/amd64

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="auto"
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/thomascoquet/.cache/go-build"
GOENV="/home/thomascoquet/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/thomascoquet/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/thomascoquet/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/thomascoquet/sdk/go1.18beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/thomascoquet/sdk/go1.18beta1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/thomascoquet/Work/nd/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1691419429=/tmp/go-build -gno-record-gcc-switches"

What did you do?

func ExampleTest() {
	w := tabwriter.NewWriter(os.Stdout, 6, 2, 2, ' ', 0)
	fmt.Fprintln(w, "a\tb\tc\t")
	fmt.Fprintln(w, "aa\tbb\tcc\t")
	fmt.Fprintln(w, "aaa\tbbb\tccc\t")
	w.Flush()

	// Output:
	// a     b     c
	// aa    bb    cc
	// aaa   bbb   ccc
}

What did you expect to see?

No error.

What did you see instead?

--- FAIL: ExampleTest (0.00s)
got:
a     b     c     
aa    bb    cc    
aaa   bbb   ccc
want:
a     b     c
aa    bb    cc
aaa   bbb   ccc
FAIL

Reason

gofmt strips trailing whitespaces in comments. Therefore it is impossible to have a proper match if gofmt is applied.

I suggest to remove trailing whitespaces as well before comparing both (comment and stdout).

@mvdan
Copy link
Member

mvdan commented Jan 21, 2022

Duplicate of #26460, which is open.

@mvdan mvdan closed this as completed Jan 21, 2022
@golang golang locked and limited conversation to collaborators Jan 21, 2023
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

3 participants