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

bufio: can't TestReaderSize #45373

Closed
awmorgan opened this issue Apr 3, 2021 · 5 comments
Closed

bufio: can't TestReaderSize #45373

awmorgan opened this issue Apr 3, 2021 · 5 comments

Comments

@awmorgan
Copy link

awmorgan commented Apr 3, 2021

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

$ go version
go version go1.16.3 darwin/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/billmorgan/Library/Caches/go-build"
GOENV="/Users/billmorgan/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/billmorgan/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/billmorgan/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Volumes/git/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/rp/fpc8t1293dn1r6jycrqn0hlw0000gn/T/go-build2935965998=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I Cloned the repo. checked out release-branch.go1.16. cd'd to src/bufio and tried to run: go test -run TestReaderSize

What did you expect to see?

test passed

What did you see instead?

/Volumes/git/go/src/bufio (release-branch.go1.16)$ go version
go version go1.16.3 darwin/amd64
/Volumes/git/go/src/bufio (release-branch.go1.16)$ git log -1 --pretty=format:"%h %an %ad"
9baddd3f21 Dmitri Shuralyov Thu Apr 1 11:28:29 2021 -0400
/Volumes/git/go/src/bufio (release-branch.go1.16)$ go test -run TestReaderSize
# std/bufio_test [std/bufio.test]
./bufio_test.go:1456:41: undefined: DefaultBufSize
./bufio_test.go:1465:41: undefined: DefaultBufSize
./scan_test.go:23:6: undefined: IsSpace
./scan_test.go:193:3: s.MaxTokenSize undefined (type *bufio.Scanner has no field or method MaxTokenSize)
./scan_test.go:229:3: s.MaxTokenSize undefined (type *bufio.Scanner has no field or method MaxTokenSize)
./scan_test.go:353:8: s.ErrOrEOF undefined (type *bufio.Scanner has no field or method ErrOrEOF)
./scan_test.go:408:9: scanner.MaxTokenSize undefined (type *bufio.Scanner has no field or method MaxTokenSize)
FAIL    std/bufio [build failed]
/Volumes/git/go/src/bufio (release-branch.go1.16)$ 
@awmorgan
Copy link
Author

awmorgan commented Apr 3, 2021

I found out that if I run all.bash and build, then run the test with that newly built version the test passes, but for some reason running the test with the installed version it fails. They're the same versions, both 1.16.3. So I get different results depending on what directory the go command is in when I run the test.

@ahmetakturk
Copy link
Contributor

Exported things in *_test.go files are only visible for the test package in the same directory. When using old Go for running new Go's bufio_test, new one can't refer exported things in old Go's bufio/export_test.go file, because the import statement import . "bufio" in new Go's bufio_test refers to old Go's bufio package in this situation.

I think there is no bug here.

@awmorgan
Copy link
Author

awmorgan commented Apr 4, 2021

OK thanks. Where is the package import search order specified?

@ianlancetaylor
Copy link
Contributor

There is no package import search order as such, because the package paths mentioned in import statements are unique (https://golang.org/cmd/go/#hdr-Package_lists_and_patterns).

All code in *_test.go files can only be seen when running go test for that package. They can not be imported by other packages.

Closing the issue because this is working as intended.

@awmorgan
Copy link
Author

awmorgan commented Apr 5, 2021

Thanks @ianlancetaylor. That page states: If no import paths are given, the action applies to the package in the current directory.
Maybe it should be amended to say: If no import paths are given, the action applies to the package in the current directory unless the current directory holds package source code for a std lib package, in which case the GOROOT is used for the action.

@golang golang locked and limited conversation to collaborators Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants