libgo: update to Go1.14rc1 release

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/218017
This commit is contained in:
Ian Lance Taylor 2020-02-05 14:33:27 -08:00
parent 17edb3310d
commit 0b3c2eed35
197 changed files with 1524 additions and 1843 deletions

View File

@ -1,4 +1,4 @@
3e46519cee5c916a9b39480fbac13f4ffc6a93b0
f368afbbd466941dcc6717412d7182e122b40c93
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.

View File

@ -1,4 +1,4 @@
a5bfd9da1d1b24f326399b6b75558ded14514f23
a068054af141c01df5a4519844f4b77273605f4e
The first line of this file holds the git revision number of the
last merge done from the master library sources.

View File

@ -1 +1 @@
go1.14beta1
go1.14rc1

View File

@ -907,7 +907,7 @@
// Main bool // is this the main module?
// Indirect bool // is this module only an indirect dependency of main module?
// Dir string // directory holding files for this module, if any
// GoMod string // path to go.mod file for this module, if any
// GoMod string // path to go.mod file used when loading this module, if any
// GoVersion string // go version used in module
// Error *ModuleError // error loading module
// }
@ -916,6 +916,9 @@
// Err string // the error itself
// }
//
// The file GoMod refers to may be outside the module directory if the
// module is in the module cache or if the -modfile flag is used.
//
// The default output is to print the module path and then
// information about the version and replacement if any.
// For example, 'go list -m all' might print:
@ -1020,7 +1023,9 @@
// execution. The "go mod download" command is useful mainly for pre-filling
// the local cache or to compute the answers for a Go module proxy.
//
// By default, download reports errors to standard error but is otherwise silent.
// By default, download writes nothing to standard output. It may print progress
// messages and errors to standard error.
//
// The -json flag causes download to print a sequence of JSON objects
// to standard output, describing each downloaded module (or failure),
// corresponding to this Go struct:
@ -2346,14 +2351,15 @@
//
// Module support
//
// Go 1.13 includes support for Go modules. Module-aware mode is active by default
// whenever a go.mod file is found in, or in a parent of, the current directory.
// The go command includes support for Go modules. Module-aware mode is active
// by default whenever a go.mod file is found in the current directory or in
// any parent directory.
//
// The quickest way to take advantage of module support is to check out your
// repository, create a go.mod file (described in the next section) there, and run
// go commands from within that file tree.
//
// For more fine-grained control, Go 1.13 continues to respect
// For more fine-grained control, the go command continues to respect
// a temporary environment variable, GO111MODULE, which can be set to one
// of three string values: off, on, or auto (the default).
// If GO111MODULE=on, then the go command requires the use of modules,

View File

@ -638,7 +638,7 @@ func (tg *testgoData) grepStderrNot(match, msg string) {
}
// grepBothNot looks for a regular expression in the test run's
// standard output or stand error and fails, logging msg, if it is
// standard output or standard error and fails, logging msg, if it is
// found.
func (tg *testgoData) grepBothNot(match, msg string) {
tg.t.Helper()
@ -913,6 +913,7 @@ func TestNewReleaseRebuildsStalePackagesInGOPATH(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
// Copy the runtime packages into a temporary GOROOT
// so that we can change files.
@ -1026,28 +1027,6 @@ func TestInternalPackagesOutsideGOROOTAreRespected(t *testing.T) {
tg.grepBoth(`testinternal2(\/|\\)p\.go\:3\:8\: use of internal package .*internal/w not allowed`, "wrote error message for testdata/testinternal2")
}
func TestRunInternal(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
dir := filepath.Join(tg.pwd(), "testdata")
tg.setenv("GOPATH", dir)
tg.run("run", filepath.Join(dir, "src/run/good.go"))
tg.runFail("run", filepath.Join(dir, "src/run/bad.go"))
tg.grepStderr(`testdata(\/|\\)src(\/|\\)run(\/|\\)bad\.go\:3\:8\: use of internal package run/subdir/internal/private not allowed`, "unexpected error for run/bad.go")
}
func TestRunPkg(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
dir := filepath.Join(tg.pwd(), "testdata")
tg.setenv("GOPATH", dir)
tg.run("run", "hello")
tg.grepStderr("hello, world", "did not find hello, world")
tg.cd(filepath.Join(dir, "src/hello"))
tg.run("run", ".")
tg.grepStderr("hello, world", "did not find hello, world")
}
func TestInternalPackageErrorsAreHandled(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
@ -1062,56 +1041,6 @@ func TestInternalCache(t *testing.T) {
tg.grepStderr("internal", "did not fail to build p")
}
func TestImportCommandMatch(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/importcom"))
tg.run("build", "./testdata/importcom/works.go")
}
func TestImportCommentMismatch(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/importcom"))
tg.runFail("build", "./testdata/importcom/wrongplace.go")
tg.grepStderr(`wrongplace expects import "my/x"`, "go build did not mention incorrect import")
}
func TestImportCommentSyntaxError(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/importcom"))
tg.runFail("build", "./testdata/importcom/bad.go")
tg.grepStderr("cannot parse import comment", "go build did not mention syntax error")
}
func TestImportCommentConflict(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/importcom"))
tg.runFail("build", "./testdata/importcom/conflict.go")
tg.grepStderr("found import comments", "go build did not mention comment conflict")
}
func TestImportCycle(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata/importcycle"))
tg.runFail("build", "selfimport")
count := tg.grepCountBoth("import cycle not allowed")
if count == 0 {
t.Fatal("go build did not mention cyclical import")
}
if count > 1 {
t.Fatal("go build mentioned import cycle more than once")
}
// Don't hang forever.
tg.run("list", "-e", "-json", "selfimport")
}
// cmd/go: custom import path checking should not apply to Go packages without import comment.
func TestIssue10952(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
@ -1217,24 +1146,6 @@ func TestAccidentalGitCheckout(t *testing.T) {
}
}
func TestErrorMessageForSyntaxErrorInTestGoFileSaysFAIL(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("test", "syntaxerror")
tg.grepStderr("x_test.go:", "did not diagnose error")
tg.grepStdout("FAIL", "go test did not say FAIL")
}
func TestWildcardsDoNotLookInUselessDirectories(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("list", "...")
tg.grepBoth("badpkg", "go list ... failure does not mention badpkg")
tg.run("list", "m...")
}
func TestRelativeImportsGoTest(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
@ -1673,6 +1584,7 @@ func TestDefaultGOPATHGet(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.setenv("GOPATH", "")
tg.tempDir("home")
tg.setenv(homeEnvName(), tg.path("home"))
@ -1697,6 +1609,7 @@ func TestDefaultGOPATHGet(t *testing.T) {
func TestDefaultGOPATHPrintedSearchList(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.setenv("GOPATH", "")
tg.tempDir("home")
tg.setenv(homeEnvName(), tg.path("home"))
@ -1819,16 +1732,6 @@ func TestGoTestMutexprofileDashOControlsBinaryLocation(t *testing.T) {
tg.wantExecutable("myerrors.test"+exeSuffix, "go test -mutexprofile -o myerrors.test did not create myerrors.test")
}
func TestGoBuildNonMain(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
// TODO: tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("build", "-buildmode=exe", "-o", "not_main"+exeSuffix, "not_main")
tg.grepStderr("-buildmode=exe requires exactly one main package", "go build with -o and -buildmode=exe should on a non-main package should throw an error")
tg.mustNotExist("not_main" + exeSuffix)
}
func TestGoTestDashCDashOControlsBinaryLocation(t *testing.T) {
skipIfGccgo(t, "gccgo has no standard packages")
tooSlow(t)
@ -2192,33 +2095,6 @@ func TestCoverageNoStatements(t *testing.T) {
tg.grepStdout("[no statements]", "expected [no statements] for pkg4")
}
func TestCoverageImportMainLoop(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("test", "importmain/test")
tg.grepStderr("not an importable package", "did not detect import main")
tg.runFail("test", "-cover", "importmain/test")
tg.grepStderr("not an importable package", "did not detect import main")
}
func TestCoveragePattern(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.makeTempdir()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
// If coverpkg=sleepy... expands by package loading
// (as opposed to pattern matching on deps)
// then it will try to load sleepybad, which does not compile,
// and the test command will fail.
tg.run("test", "-coverprofile="+tg.path("cover.out"), "-coverpkg=sleepy...", "-run=^$", "sleepy1")
}
func TestCoverageErrorLine(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tooSlow(t)
@ -2291,20 +2167,6 @@ func TestCoverageDashC(t *testing.T) {
tg.wantExecutable(tg.path("coverdep"), "go -test -c -coverprofile did not create executable")
}
func TestPluginNonMain(t *testing.T) {
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
pkg := filepath.Join(wd, "testdata", "testdep", "p2")
tg := testgo(t)
defer tg.cleanup()
tg.runFail("build", "-buildmode=plugin", pkg)
}
func TestTestEmpty(t *testing.T) {
if !canRace {
t.Skip("no race detector")
@ -2389,39 +2251,6 @@ func main() {
tg.grepStderrNot(`os.Stat .* no such file or directory`, "unexpected stat of archive file")
}
func TestCoverageWithCgo(t *testing.T) {
skipIfGccgo(t, "gccgo has no cover tool")
tooSlow(t)
if !canCgo {
t.Skip("skipping because cgo not enabled")
}
for _, dir := range []string{"cgocover", "cgocover2", "cgocover3", "cgocover4"} {
t.Run(dir, func(t *testing.T) {
tg := testgo(t)
tg.parallel()
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "-short", "-cover", dir)
data := tg.getStdout() + tg.getStderr()
checkCoverage(tg, data)
})
}
}
func TestCgoAsmError(t *testing.T) {
if !canCgo {
t.Skip("skipping because cgo not enabled")
}
tg := testgo(t)
tg.parallel()
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("build", "cgoasm")
tg.grepBoth("package using cgo has Go assembly file", "did not detect Go assembly file")
}
func TestCgoDependsOnSyscall(t *testing.T) {
if testing.Short() {
t.Skip("skipping test that removes $GOROOT/pkg/*_race in short mode")
@ -2435,6 +2264,8 @@ func TestCgoDependsOnSyscall(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
files, err := filepath.Glob(filepath.Join(runtime.GOROOT(), "pkg", "*_race"))
tg.must(err)
for _, file := range files {
@ -2648,14 +2479,6 @@ func TestListTemplateContextFunction(t *testing.T) {
}
}
// cmd/go: "go test" should fail if package does not build
func TestIssue7108(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("test", "notest")
}
func TestGoBuildTestOnly(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
@ -2677,17 +2500,6 @@ func TestGoBuildTestOnly(t *testing.T) {
tg.run("install", "./testonly...")
}
func TestGoTestDetectsTestOnlyImportCycles(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("test", "-c", "testcycle/p3")
tg.grepStderr("import cycle not allowed in test", "go test testcycle/p3 produced unexpected error")
tg.runFail("test", "-c", "testcycle/q1")
tg.grepStderr("import cycle not allowed in test", "go test testcycle/q1 produced unexpected error")
}
func TestGoTestFooTestWorks(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
@ -2715,29 +2527,6 @@ func TestGoTestMainAsNormalTest(t *testing.T) {
tg.grepBoth(okPattern, "go test did not say ok")
}
func TestGoTestMainTwice(t *testing.T) {
if testing.Short() {
t.Skip("Skipping in short mode")
}
tg := testgo(t)
defer tg.cleanup()
tg.makeTempdir()
tg.setenv("GOCACHE", tg.tempdir)
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "-v", "multimain")
if strings.Count(tg.getStdout(), "notwithstanding") != 2 {
t.Fatal("tests did not run twice")
}
}
func TestGoTestFlagsAfterPackage(t *testing.T) {
tooSlow(t)
tg := testgo(t)
defer tg.cleanup()
tg.run("test", "testdata/flag_test.go", "-v", "-args", "-v=7") // Two distinct -v flags.
tg.run("test", "-v", "testdata/flag_test.go", "-args", "-v=7") // Two distinct -v flags.
}
func TestGoTestXtestonlyWorks(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
@ -2829,20 +2618,6 @@ func TestGoGenerateXTestPkgName(t *testing.T) {
}
}
func TestGoGenerateBadImports(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("skipping because windows has no echo command")
}
// This package has an invalid import causing an import cycle,
// but go generate is supposed to still run.
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("generate", "gencycle")
tg.grepStdout("hello world", "go generate gencycle did not run generator")
}
func TestGoGetCustomDomainWildcard(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
testenv.MustHaveExecPath(t, "git")
@ -3268,43 +3043,6 @@ func TestGoTestRaceInstallCgo(t *testing.T) {
}
}
func TestGoTestRaceFailures(t *testing.T) {
tooSlow(t)
if !canRace {
t.Skip("skipping because race detector not supported")
}
tg := testgo(t)
tg.parallel()
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "testrace")
tg.runFail("test", "-race", "testrace")
tg.grepStdout("FAIL: TestRace", "TestRace did not fail")
tg.grepBothNot("PASS", "something passed")
tg.runFail("test", "-race", "testrace", "-run", "XXX", "-bench", ".")
tg.grepStdout("FAIL: BenchmarkRace", "BenchmarkRace did not fail")
tg.grepBothNot("PASS", "something passed")
}
func TestGoTestImportErrorStack(t *testing.T) {
const out = `package testdep/p1 (test)
imports testdep/p2
imports testdep/p3: build constraints exclude all Go files `
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("test", "testdep/p1")
if !strings.Contains(tg.stderr.String(), out) {
t.Fatalf("did not give full import stack:\n\n%s", tg.stderr.String())
}
}
func TestGoGetUpdate(t *testing.T) {
// golang.org/issue/9224.
// The recursive updating was trying to walk to
@ -3627,27 +3365,6 @@ func TestGoGetUpdateAllDoesNotTryToLoadDuplicates(t *testing.T) {
tg.grepStderrNot("duplicate loads of", "did not remove old packages from cache")
}
// Issue 17119 more duplicate load errors
func TestIssue17119(t *testing.T) {
testenv.MustHaveExternalNetwork(t)
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("build", "dupload")
tg.grepBothNot("duplicate load|internal error", "internal error")
}
func TestFatalInBenchmarkCauseNonZeroExitStatus(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
// TODO: tg.parallel()
tg.runFail("test", "-run", "^$", "-bench", ".", "./testdata/src/benchfatal")
tg.grepBothNot("^ok", "test passed unexpectedly")
tg.grepBoth("FAIL.*benchfatal", "test did not run everything")
}
func TestBinaryOnlyPackages(t *testing.T) {
tooSlow(t)
@ -3813,16 +3530,6 @@ func TestMatchesNoTests(t *testing.T) {
tg.grepBoth(noMatchesPattern, "go test did not say [no tests to run]")
}
func TestMatchesNoTestsDoesNotOverrideBuildFailure(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.runFail("test", "-run", "ThisWillNotMatch", "syntaxerror")
tg.grepBothNot(noMatchesPattern, "go test did say [no tests to run]")
tg.grepBoth("FAIL", "go test did not say FAIL")
}
func TestMatchesNoBenchmarksIsOK(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
@ -3850,18 +3557,6 @@ func TestMatchesOnlyBenchmarkIsOK(t *testing.T) {
tg.grepBoth(okPattern, "go test did not say ok")
}
func TestBenchmarkLabels(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
// TODO: tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "-run", "^$", "-bench", ".", "bench")
tg.grepStdout(`(?m)^goos: `+runtime.GOOS, "go test did not print goos")
tg.grepStdout(`(?m)^goarch: `+runtime.GOARCH, "go test did not print goarch")
tg.grepStdout(`(?m)^pkg: bench`, "go test did not say pkg: bench")
tg.grepBothNot(`(?s)pkg:.*pkg:`, "go test said pkg multiple times")
}
func TestBenchmarkLabelsOutsideGOPATH(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
@ -4261,25 +3956,6 @@ func TestCgoFlagContainsSpace(t *testing.T) {
tg.grepStderrNot(`"-L[^"]+c flags".*"-L[^"]+c flags"`, "found too many quoted ld flags")
}
// Issue #20435.
func TestGoTestRaceCoverModeFailures(t *testing.T) {
tooSlow(t)
if !canRace {
t.Skip("skipping because race detector not supported")
}
tg := testgo(t)
tg.parallel()
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "testrace")
tg.runFail("test", "-race", "-covermode=set", "testrace")
tg.grepStderr(`-covermode must be "atomic", not "set", when -race is enabled`, "-race -covermode=set was allowed")
tg.grepBothNot("PASS", "something passed")
}
// Issue 9737: verify that GOARM and GO386 affect the computed build ID.
func TestBuildIDContainsArchModeEnv(t *testing.T) {
if testing.Short() {
@ -4319,60 +3995,6 @@ func main() {}`)
}))
}
func TestTestRegexps(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "-cpu=1", "-run=X/Y", "-bench=X/Y", "-count=2", "-v", "testregexp")
var lines []string
for _, line := range strings.SplitAfter(tg.getStdout(), "\n") {
if strings.Contains(line, "=== RUN") || strings.Contains(line, "--- BENCH") || strings.Contains(line, "LOG") {
lines = append(lines, line)
}
}
// Important parts:
// TestX is run, twice
// TestX/Y is run, twice
// TestXX is run, twice
// TestZ is not run
// BenchmarkX is run but only with N=1, once
// BenchmarkXX is run but only with N=1, once
// BenchmarkX/Y is run in full, twice
want := `=== RUN TestX
TestX: x_test.go:6: LOG: X running
=== RUN TestX/Y
TestX/Y: x_test.go:8: LOG: Y running
=== RUN TestXX
TestXX: z_test.go:10: LOG: XX running
=== RUN TestX
TestX: x_test.go:6: LOG: X running
=== RUN TestX/Y
TestX/Y: x_test.go:8: LOG: Y running
=== RUN TestXX
TestXX: z_test.go:10: LOG: XX running
BenchmarkX: x_test.go:13: LOG: X running N=1
BenchmarkX/Y: x_test.go:15: LOG: Y running N=1
BenchmarkX/Y: x_test.go:15: LOG: Y running N=100
BenchmarkX/Y: x_test.go:15: LOG: Y running N=10000
BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000
BenchmarkX/Y: x_test.go:15: LOG: Y running N=100000000
BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000000
BenchmarkX/Y: x_test.go:15: LOG: Y running N=1
BenchmarkX/Y: x_test.go:15: LOG: Y running N=100
BenchmarkX/Y: x_test.go:15: LOG: Y running N=10000
BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000
BenchmarkX/Y: x_test.go:15: LOG: Y running N=100000000
BenchmarkX/Y: x_test.go:15: LOG: Y running N=1000000000
BenchmarkXX: z_test.go:18: LOG: XX running N=1
`
have := strings.Join(lines, "")
if have != want {
t.Errorf("reduced output:<<<\n%s>>> want:<<<\n%s>>>", have, want)
}
}
func TestListTests(t *testing.T) {
tooSlow(t)
var tg *testgoData
@ -4408,6 +4030,7 @@ func TestBuildmodePIE(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempFile("main.go", `package main; func main() { print("hello") }`)
src := tg.path("main.go")
@ -4571,6 +4194,7 @@ func TestUpxCompression(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempFile("main.go", `package main; import "fmt"; func main() { fmt.Print("hello upx") }`)
src := tg.path("main.go")
@ -4964,14 +4588,6 @@ func TestInstallDeps(t *testing.T) {
tg.mustExist(p1)
}
func TestGoTestMinusN(t *testing.T) {
// Intent here is to verify that 'go test -n' works without crashing.
// This reuses flag_test.go, but really any test would do.
tg := testgo(t)
defer tg.cleanup()
tg.run("test", "testdata/flag_test.go", "-n", "-args", "-v=7")
}
func TestGoTestJSON(t *testing.T) {
skipIfGccgo(t, "gccgo does not have standard packages")
tooSlow(t)
@ -5109,6 +4725,7 @@ func init() {}
func TestBadCommandLines(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.tempFile("src/x/x.go", "package x\n")
tg.setenv("GOPATH", tg.path("."))
@ -5329,6 +4946,7 @@ func TestCgoCache(t *testing.T) {
func TestFilepathUnderCwdFormat(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.run("test", "-x", "-cover", "log")
tg.grepStderrNot(`\.log\.cover\.go`, "-x output should contain correctly formatted filepath under cwd")
}
@ -5433,16 +5051,6 @@ func TestCDAndGOPATHAreDifferent(t *testing.T) {
}
}
// Issue 26242.
func TestGoTestWithoutTests(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
tg.run("test", "testnorun")
tg.grepStdout(`testnorun\t\[no test files\]`, "do not want test to run")
}
// Issue 25579.
func TestGoBuildDashODevNull(t *testing.T) {
tooSlow(t)

View File

@ -178,7 +178,9 @@ func runClean(cmd *base.Command, args []string) {
}
}
if err != nil {
base.Errorf("go clean -testcache: %v", err)
if _, statErr := os.Stat(dir); !os.IsNotExist(statErr) {
base.Errorf("go clean -testcache: %v", err)
}
}
}
}

View File

@ -211,7 +211,7 @@ applied to a Go struct, but now a Module struct:
Main bool // is this the main module?
Indirect bool // is this module only an indirect dependency of main module?
Dir string // directory holding files for this module, if any
GoMod string // path to go.mod file for this module, if any
GoMod string // path to go.mod file used when loading this module, if any
GoVersion string // go version used in module
Error *ModuleError // error loading module
}
@ -220,6 +220,9 @@ applied to a Go struct, but now a Module struct:
Err string // the error itself
}
The file GoMod refers to may be outside the module directory if the
module is in the module cache or if the -modfile flag is used.
The default output is to print the module path and then
information about the version and replacement if any.
For example, 'go list -m all' might print:
@ -387,15 +390,24 @@ func runList(cmd *base.Command, args []string) {
modload.InitMod() // Parses go.mod and sets cfg.BuildMod.
if cfg.BuildMod == "vendor" {
const actionDisabledFormat = "go list -m: can't %s using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)"
if *listVersions {
base.Fatalf(actionDisabledFormat, "determine available versions")
}
if *listU {
base.Fatalf(actionDisabledFormat, "determine available upgrades")
}
for _, arg := range args {
// In vendor mode, the module graph is incomplete: it contains only the
// explicit module dependencies and the modules that supply packages in
// the import graph. Reject queries that imply more information than that.
if arg == "all" {
base.Fatalf("go list -m: can't compute 'all' using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")
base.Fatalf(actionDisabledFormat, "compute 'all'")
}
if strings.Contains(arg, "...") {
base.Fatalf("go list -m: can't match module patterns using the vendor directory\n\t(Use -mod=mod or -mod=readonly to bypass.)")
base.Fatalf(actionDisabledFormat, "match module patterns")
}
}
}

View File

@ -30,7 +30,9 @@ The go command will automatically download modules as needed during ordinary
execution. The "go mod download" command is useful mainly for pre-filling
the local cache or to compute the answers for a Go module proxy.
By default, download reports errors to standard error but is otherwise silent.
By default, download writes nothing to standard output. It may print progress
messages and errors to standard error.
The -json flag causes download to print a sequence of JSON objects
to standard output, describing each downloaded module (or failure),
corresponding to this Go struct:

View File

@ -13,7 +13,6 @@ import (
"os"
"path/filepath"
"strings"
"time"
"cmd/go/internal/base"
"cmd/go/internal/cfg"
@ -28,8 +27,6 @@ import (
var PkgMod string // $GOPATH/pkg/mod; set by package modload
const logFindingDelay = 1 * time.Second
func cacheDir(path string) (string, error) {
if PkgMod == "" {
return "", fmt.Errorf("internal error: modfetch.PkgMod not set")
@ -140,11 +137,6 @@ func (r *cachingRepo) Versions(prefix string) ([]string, error) {
err error
}
c := r.cache.Do("versions:"+prefix, func() interface{} {
logTimer := time.AfterFunc(logFindingDelay, func() {
fmt.Fprintf(os.Stderr, "go: finding versions for %s\n", r.path)
})
defer logTimer.Stop()
list, err := r.r.Versions(prefix)
return cached{list, err}
}).(cached)
@ -167,11 +159,6 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
return cachedInfo{info, nil}
}
logTimer := time.AfterFunc(logFindingDelay, func() {
fmt.Fprintf(os.Stderr, "go: finding %s %s\n", r.path, rev)
})
defer logTimer.Stop()
info, err = r.r.Stat(rev)
if err == nil {
// If we resolved, say, 1234abcde to v0.0.0-20180604122334-1234abcdef78,
@ -199,11 +186,6 @@ func (r *cachingRepo) Stat(rev string) (*RevInfo, error) {
func (r *cachingRepo) Latest() (*RevInfo, error) {
c := r.cache.Do("latest:", func() interface{} {
logTimer := time.AfterFunc(logFindingDelay, func() {
fmt.Fprintf(os.Stderr, "go: finding %s latest\n", r.path)
})
defer logTimer.Stop()
info, err := r.r.Latest()
// Save info for likely future Stat call.

View File

@ -682,8 +682,11 @@ func (r *gitRepo) RecentTag(rev, prefix, major string) (tag string, err error) {
semtag := line[len(prefix):]
// Consider only tags that are valid and complete (not just major.minor prefixes).
if c := semver.Canonical(semtag); c != "" && strings.HasPrefix(semtag, c) && (major == "" || semver.Major(c) == major) {
highest = semver.Max(highest, semtag)
// NOTE: Do not replace the call to semver.Compare with semver.Max.
// We want to return the actual tag, not a canonicalized version of it,
// and semver.Max currently canonicalizes (see golang.org/issue/32700).
if c := semver.Canonical(semtag); c != "" && strings.HasPrefix(semtag, c) && (major == "" || semver.Major(c) == major) && semver.Compare(semtag, highest) > 0 {
highest = semtag
}
}

View File

@ -191,22 +191,6 @@ func (r *codeRepo) appendIncompatibleVersions(list, incompatible []string) ([]st
return list, nil
}
// We assume that if the latest release of any major version has a go.mod
// file, all subsequent major versions will also have go.mod files (and thus
// be ineligible for use as +incompatible versions).
// If we're wrong about a major version, users will still be able to 'go get'
// specific higher versions explicitly — they just won't affect 'latest' or
// appear in 'go list'.
//
// Conversely, we assume that if the latest release of any major version lacks
// a go.mod file, all versions also lack go.mod files. If we're wrong, we may
// include a +incompatible version that isn't really valid, but most
// operations won't try to use that version anyway.
//
// These optimizations bring
// 'go list -versions -m github.com/openshift/origin' down from 1m58s to 0m37s.
// That's still not great, but a substantial improvement.
versionHasGoMod := func(v string) (bool, error) {
_, err := r.code.ReadFile(v, "go.mod", codehost.MaxGoMod)
if err == nil {
@ -241,32 +225,41 @@ func (r *codeRepo) appendIncompatibleVersions(list, incompatible []string) ([]st
}
}
var lastMajor string
var (
lastMajor string
lastMajorHasGoMod bool
)
for i, v := range incompatible {
major := semver.Major(v)
if major == lastMajor {
list = append(list, v+"+incompatible")
if major != lastMajor {
rem := incompatible[i:]
j := sort.Search(len(rem), func(j int) bool {
return semver.Major(rem[j]) != major
})
latestAtMajor := rem[j-1]
var err error
lastMajor = major
lastMajorHasGoMod, err = versionHasGoMod(latestAtMajor)
if err != nil {
return nil, err
}
}
if lastMajorHasGoMod {
// The latest release of this major version has a go.mod file, so it is
// not allowed as +incompatible. It would be confusing to include some
// minor versions of this major version as +incompatible but require
// semantic import versioning for others, so drop all +incompatible
// versions for this major version.
//
// If we're wrong about a minor version in the middle, users will still be
// able to 'go get' specific tags for that version explicitly — they just
// won't appear in 'go list' or as the results for queries with inequality
// bounds.
continue
}
rem := incompatible[i:]
j := sort.Search(len(rem), func(j int) bool {
return semver.Major(rem[j]) != major
})
latestAtMajor := rem[j-1]
ok, err := versionHasGoMod(latestAtMajor)
if err != nil {
return nil, err
}
if ok {
// This major version has a go.mod file, so it is not allowed as
// +incompatible. Subsequent major versions are likely to also have
// go.mod files, so stop here.
break
}
lastMajor = major
list = append(list, v+"+incompatible")
}
@ -708,7 +701,7 @@ func (r *codeRepo) findDir(version string) (rev, dir string, gomod []byte, err e
return "", "", nil, fmt.Errorf("reading %s/%s at revision %s: %v", r.pathPrefix, file1, rev, err1)
}
mpath1 := modfile.ModulePath(gomod1)
found1 := err1 == nil && isMajor(mpath1, r.pathMajor)
found1 := err1 == nil && (isMajor(mpath1, r.pathMajor) || r.canReplaceMismatchedVersionDueToBug(mpath1))
var file2 string
if r.pathMajor != "" && r.codeRoot != r.modPath && !strings.HasPrefix(r.pathMajor, ".") {
@ -817,6 +810,17 @@ func isMajor(mpath, pathMajor string) bool {
return pathMajor[1:] == mpathMajor[1:]
}
// canReplaceMismatchedVersionDueToBug reports whether versions of r
// could replace versions of mpath with otherwise-mismatched major versions
// due to a historical bug in the Go command (golang.org/issue/34254).
func (r *codeRepo) canReplaceMismatchedVersionDueToBug(mpath string) bool {
// The bug caused us to erroneously accept unversioned paths as replacements
// for versioned gopkg.in paths.
unversioned := r.pathMajor == ""
replacingGopkgIn := strings.HasPrefix(mpath, "gopkg.in/")
return unversioned && replacingGopkgIn
}
func (r *codeRepo) GoMod(version string) (data []byte, err error) {
if version != module.CanonicalVersion(version) {
return nil, fmt.Errorf("version %s is not canonical", version)

View File

@ -112,7 +112,7 @@ func moduleInfo(m module.Version, fromBuildList bool) *modinfo.ModulePublic {
}
if HasModRoot() {
info.Dir = ModRoot()
info.GoMod = filepath.Join(info.Dir, "go.mod")
info.GoMod = ModFilePath()
if modFile.Go != nil {
info.GoVersion = modFile.Go.Version
}

View File

@ -21,14 +21,15 @@ which source files are used in a given build.
Module support
Go 1.13 includes support for Go modules. Module-aware mode is active by default
whenever a go.mod file is found in, or in a parent of, the current directory.
The go command includes support for Go modules. Module-aware mode is active
by default whenever a go.mod file is found in the current directory or in
any parent directory.
The quickest way to take advantage of module support is to check out your
repository, create a go.mod file (described in the next section) there, and run
go commands from within that file tree.
For more fine-grained control, Go 1.13 continues to respect
For more fine-grained control, the go command continues to respect
a temporary environment variable, GO111MODULE, which can be set to one
of three string values: off, on, or auto (the default).
If GO111MODULE=on, then the go command requires the use of modules,

View File

@ -203,7 +203,12 @@ func Import(path string) (m module.Version, dir string, err error) {
latest := map[string]string{} // path -> version
for _, r := range modFile.Replace {
if maybeInModule(path, r.Old.Path) {
latest[r.Old.Path] = semver.Max(r.Old.Version, latest[r.Old.Path])
// Don't use semver.Max here; need to preserve +incompatible suffix.
v := latest[r.Old.Path]
if semver.Compare(r.Old.Version, v) > 0 {
v = r.Old.Version
}
latest[r.Old.Path] = v
}
}
@ -264,6 +269,8 @@ func Import(path string) (m module.Version, dir string, err error) {
return module.Version{}, "", &ImportMissingError{Path: path}
}
fmt.Fprintf(os.Stderr, "go: finding module for package %s\n", path)
candidates, err := QueryPackage(path, "latest", Allowed)
if err != nil {
if errors.Is(err, os.ErrNotExist) {

View File

@ -1324,6 +1324,21 @@ func fetch(mod module.Version) (dir string, isLocal bool, err error) {
if !filepath.IsAbs(dir) {
dir = filepath.Join(ModRoot(), dir)
}
// Ensure that the replacement directory actually exists:
// dirInModule does not report errors for missing modules,
// so if we don't report the error now, later failures will be
// very mysterious.
if _, err := os.Stat(dir); err != nil {
if os.IsNotExist(err) {
// Semantically the module version itself “exists” — we just don't
// have its source code. Remove the equivalence to os.ErrNotExist,
// and make the message more concise while we're at it.
err = fmt.Errorf("replacement directory %s does not exist", r.Path)
} else {
err = fmt.Errorf("replacement directory %s: %w", r.Path, err)
}
return dir, true, module.VersionError(mod, err)
}
return dir, true, nil
}
mod = r

View File

@ -79,7 +79,7 @@ func queryProxy(proxy, path, query, current string, allowed func(module.Version)
if current != "" && !semver.IsValid(current) {
return nil, fmt.Errorf("invalid previous version %q", current)
}
if cfg.BuildMod != "" && cfg.BuildMod != "mod" {
if cfg.BuildMod == "vendor" {
return nil, errQueryDisabled
}
if allowed == nil {

View File

@ -64,7 +64,7 @@ var queryTests = []struct {
git add go.mod
git commit -m v1 go.mod
git tag start
for i in v0.0.0-pre1 v0.0.0 v0.0.1 v0.0.2 v0.0.3 v0.1.0 v0.1.1 v0.1.2 v0.3.0 v1.0.0 v1.1.0 v1.9.0 v1.9.9 v1.9.10-pre1 v1.9.10-pre2+metadata; do
for i in v0.0.0-pre1 v0.0.0 v0.0.1 v0.0.2 v0.0.3 v0.1.0 v0.1.1 v0.1.2 v0.3.0 v1.0.0 v1.1.0 v1.9.0 v1.9.9 v1.9.10-pre1 v1.9.10-pre2+metadata unversioned; do
echo before $i >status
git add status
git commit -m "before $i" status
@ -107,6 +107,7 @@ var queryTests = []struct {
{path: queryRepo, query: "v0.2", err: `no matching versions for query "v0.2"`},
{path: queryRepo, query: "v0.0", vers: "v0.0.3"},
{path: queryRepo, query: "v1.9.10-pre2+metadata", vers: "v1.9.10-pre2.0.20190513201126-42abcb6df8ee"},
{path: queryRepo, query: "ed5ffdaa", vers: "v1.9.10-pre2.0.20191220134614-ed5ffdaa1f5e"},
// golang.org/issue/29262: The major version for for a module without a suffix
// should be based on the most recent tag (v1 as appropriate, not v0
@ -162,10 +163,14 @@ var queryTests = []struct {
{path: queryRepoV2, query: "v2.6.0-pre1", vers: "v2.6.0-pre1"},
{path: queryRepoV2, query: "latest", vers: "v2.5.5"},
// e0cf3de987e6 is the latest commit on the master branch, and it's actually
// v1.19.10-pre1, not anything resembling v3: attempting to query it as such
// should fail.
// Commit e0cf3de987e6 is actually v1.19.10-pre1, not anything resembling v3,
// and it has a go.mod file with a non-v3 module path. Attempting to query it
// as the v3 module should fail.
{path: queryRepoV3, query: "e0cf3de987e6", err: `vcs-test.golang.org/git/querytest.git/v3@v3.0.0-20180704024501-e0cf3de987e6: invalid version: go.mod has non-.../v3 module path "vcs-test.golang.org/git/querytest.git" (and .../v3/go.mod does not exist) at revision e0cf3de987e6`},
// The querytest repo does not have any commits tagged with major version 3,
// and the latest commit in the repo has a go.mod file specifying a non-v3 path.
// That should prevent us from resolving any version for the /v3 path.
{path: queryRepoV3, query: "latest", err: `no matching versions for query "latest"`},
{path: emptyRepo, query: "latest", vers: "v0.0.0-20180704023549-7bb914627242"},

View File

@ -227,8 +227,8 @@ func (a *Action) trimpath() string {
// For "go build -trimpath", rewrite package source directory
// to a file system-independent path (just the import path).
if cfg.BuildTrimpath {
if m := a.Package.Module; m != nil {
rewrite += ";" + m.Dir + "=>" + m.Path + "@" + m.Version
if m := a.Package.Module; m != nil && m.Version != "" {
rewrite += ";" + a.Package.Dir + "=>" + m.Path + "@" + m.Version + strings.TrimPrefix(a.Package.ImportPath, m.Path)
} else {
rewrite += ";" + a.Package.Dir + "=>" + a.Package.ImportPath
}

View File

@ -1 +0,0 @@
module m

View File

@ -1,4 +0,0 @@
package x
import _ "appengine"
import _ "nonexistent.rsc.io" // domain does not exist

View File

@ -1,16 +0,0 @@
package flag_test
import (
"flag"
"log"
"testing"
)
var v = flag.Int("v", 0, "v flag")
// Run this as go test pkg -v=7
func TestVFlagIsSet(t *testing.T) {
if *v != 7 {
log.Fatal("v flag not set")
}
}

View File

@ -1,3 +0,0 @@
package p
import "bad"

View File

@ -1,3 +0,0 @@
package p
import "conflict"

View File

@ -1 +0,0 @@
package bad // import

View File

@ -1 +0,0 @@
package conflict // import "a"

View File

@ -1 +0,0 @@
package conflict /* import "b" */

View File

@ -1 +0,0 @@
package x // import "works/x"

View File

@ -1 +0,0 @@
package x // important! not an import comment

View File

@ -1 +0,0 @@
package x // import "my/x"

View File

@ -1,3 +0,0 @@
package p
import _ "works/x"

View File

@ -1,3 +0,0 @@
package p
import "wrongplace"

View File

@ -1,3 +0,0 @@
package selfimport
import "selfimport"

View File

@ -40,7 +40,7 @@ Scripts also have access to these other environment variables:
goversion=<current Go version; for example, 1.12>
:=<OS-specific path list separator>
The scripts supporting files are unpacked relative to $GOPATH/src (aka $WORK/gopath/src)
The scripts' supporting files are unpacked relative to $GOPATH/src (aka $WORK/gopath/src)
and then the script begins execution in that directory as well. Thus the example above runs
in $WORK/gopath/src with GOPATH=$WORK/gopath and $WORK/gopath/src/hello.go
containing the listed contents.

View File

@ -9,6 +9,13 @@ go clean -testcache
go test x_test.go
! stdout 'cached'
# golang.org/issue/29100: 'go clean -testcache' should succeed
# if the cache directory doesn't exist at all.
# It should not write a testexpire.txt file, since there are no
# test results that need to be invalidated in the first place.
env GOCACHE=$WORK/nonexistent
go clean -testcache
! exists $WORK/nonexistent
-- x/x_test.go --
package x_test
@ -16,4 +23,4 @@ import (
"testing"
)
func TestMain(t *testing.T) {
}
}

View File

@ -8,6 +8,10 @@
# See: https://github.com/golang/go/issues/8912
[linux] [ppc64] skip
# External linking is not supported on linux/riscv64.
# See: https://github.com/golang/go/issues/36739
[linux] [riscv64] skip
# External linking is not supported on darwin/386 (10.14+).
# See: https://github.com/golang/go/issues/31751
[darwin] [386] skip

View File

@ -33,7 +33,7 @@ grep 'rsc.io/quote v1.5.1$' go.mod
# 'go get all' should consider test dependencies with or without -t.
cp go.mod.empty go.mod
go get all
go get -d all
grep 'rsc.io/quote v1.5.2$' go.mod
-- go.mod.empty --

View File

@ -75,12 +75,14 @@ go: example.com/badchain/a@v1.1.0 requires
module declares its path as: badchain.example.com/c
but was required as: example.com/badchain/c
-- list-missing-expected --
go: finding module for package example.com/badchain/c
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
go: m/use imports
example.com/badchain/c: example.com/badchain/c@v1.1.0: parsing go.mod:
module declares its path as: badchain.example.com/c
but was required as: example.com/badchain/c
-- list-missing-test-expected --
go: finding module for package example.com/badchain/c
go: found example.com/badchain/c in example.com/badchain/c v1.1.0
go: m/testuse tested by
m/testuse.test imports

View File

@ -34,6 +34,11 @@ go list all
go clean -modcache
go list all
# -mod=readonly must not cause 'go list -m' to fail.
# (golang.org/issue/36478)
go list -m all
! stderr 'cannot query module'
# -mod=readonly should reject inconsistent go.mod files
# (ones that would be rewritten).
go mod edit -require rsc.io/sampler@v1.2.0

View File

@ -15,10 +15,28 @@ env GOSUMDB=off
# Replacing gopkg.in/[…].vN with a repository with a root go.mod file
# specifying […].vN and a compatible version should succeed, even if
# the replacement path is not a gopkg.in path.
cd dot-to-dot
go list gopkg.in/src-d/go-git.v4
cd 4-to-4
go list -m gopkg.in/src-d/go-git.v4
-- dot-to-dot/go.mod --
# Previous versions of the "go" command accepted v0 and v1 pseudo-versions
# as replacements for gopkg.in/[…].v4.
# As a special case, we continue to accept those.
cd ../4-to-0
go list -m gopkg.in/src-d/go-git.v4
cd ../4-to-1
go list -m gopkg.in/src-d/go-git.v4
cd ../4-to-incompatible
go list -m gopkg.in/src-d/go-git.v4
# A mismatched gopkg.in path should not be able to replace a different major version.
cd ../3-to-gomod-4
! go list -m gopkg.in/src-d/go-git.v3
stderr '^go: gopkg\.in/src-d/go-git\.v3@v3.0.0-20190801152248-0d1a009cbb60: invalid version: go\.mod has non-\.\.\.\.v3 module path "gopkg\.in/src-d/go-git\.v4" at revision 0d1a009cbb60$'
-- 4-to-4/go.mod --
module golang.org/issue/34254
go 1.13
@ -26,3 +44,36 @@ go 1.13
require gopkg.in/src-d/go-git.v4 v4.13.1
replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git/v4 v4.13.1
-- 4-to-1/go.mod --
module golang.org/issue/34254
go 1.13
require gopkg.in/src-d/go-git.v4 v4.13.1
replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git v1.0.1-0.20190801152248-0d1a009cbb60
-- 4-to-0/go.mod --
module golang.org/issue/34254
go 1.13
require gopkg.in/src-d/go-git.v4 v4.13.1
replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git v0.0.0-20190801152248-0d1a009cbb60
-- 4-to-incompatible/go.mod --
module golang.org/issue/34254
go 1.13
require gopkg.in/src-d/go-git.v4 v4.13.1
replace gopkg.in/src-d/go-git.v4 v4.13.1 => github.com/src-d/go-git v4.6.0+incompatible
-- 3-to-gomod-4/go.mod --
module golang.org/issue/34254
go 1.13
require gopkg.in/src-d/go-git.v3 v3.2.0
// This replacement has a go.mod file declaring its path to be
// gopkg.in/src-d/go-git.v4, so it cannot be used as a replacement for v3.
replace gopkg.in/src-d/go-git.v3 v3.2.0 => gopkg.in/src-d/go-git.v3 v3.0.0-20190801152248-0d1a009cbb60

View File

@ -28,7 +28,8 @@ stdout 'example.com/v v1.12.0 => ./v12'
cd fail
! go list all
stdout 'localhost.fail'
stderr '^can.t load package: m.go:3:8: module w@latest found \(v0.0.0-00010101000000-000000000000, replaced by ../w\), but does not contain package w$'
stderr '^can''t load package: m.go:4:2: module w@latest found \(v0.0.0-00010101000000-000000000000, replaced by ../w\), but does not contain package w$'
stderr '^can''t load package: m.go:5:2: nonexist@v0.1.0: replacement directory ../nonexist does not exist$'
-- go.mod --
module example.com/m
@ -54,6 +55,10 @@ replace (
example.com/v => ./v
)
replace (
example.com/i v2.0.0+incompatible => ./i2
)
-- m.go --
package main
import (
@ -61,6 +66,7 @@ import (
_ "example.com/x/v3"
_ "example.com/y/z/w"
_ "example.com/v"
_ "example.com/i"
)
func main() {}
@ -115,10 +121,18 @@ module v.localhost
-- v/v.go --
package v
-- i2/go.mod --
module example.com/i
-- i2/i.go --
package i
-- fail/m.go --
package main
import _ "w"
import (
_ "w"
_ "nonexist"
)
func main() {}
@ -127,3 +141,4 @@ module localhost.fail
replace w => ../w
replace nonexist v0.1.0 => ../nonexist

View File

@ -1,46 +0,0 @@
env GO111MODULE=on
go list -e -f '{{.Incomplete}}' runbad1.go
stdout true
! go run runbad1.go
stderr 'use of internal package m/x/internal not allowed'
go list -e -f '{{.Incomplete}}' runbad2.go
stdout true
! go run runbad2.go
stderr 'use of internal package m/x/internal/y not allowed'
go list -e -f '{{.Incomplete}}' runok.go
stdout false
go run runok.go
-- go.mod --
module m
-- x/internal/internal.go --
package internal
-- x/internal/y/y.go --
package y
-- internal/internal.go --
package internal
-- internal/z/z.go --
package z
-- runbad1.go --
package main
import _ "m/x/internal"
func main() {}
-- runbad2.go --
package main
import _ "m/x/internal/y"
func main() {}
-- runok.go --
package main
import _ "m/internal"
import _ "m/internal/z"
func main() {}

View File

@ -38,6 +38,12 @@ stdout 'src[\\/]vendor[\\/]x'
go list -mod=vendor -f '{{.Version}} {{.Dir}}' -m x
stdout '^v1.0.0 $'
# -mod=vendor should cause 'go list' flags that look up versions to fail.
! go list -mod=vendor -versions -m x
stderr '^go list -m: can''t determine available versions using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
! go list -mod=vendor -u -m x
stderr '^go list -m: can''t determine available upgrades using the vendor directory\n\t\(Use -mod=mod or -mod=readonly to bypass.\)$'
# 'go list -mod=vendor -m' on a transitive dependency that does not
# provide vendored packages should give a helpful error rather than
# 'not a known dependency'.

View File

@ -11,6 +11,15 @@ cp go.sum go.sum.orig
go mod init example.com/m
grep example.com/m go.alt.mod
# 'go env GOMOD' should print the path to the real file.
# 'go env' does not recognize the '-modfile' flag.
go env GOMOD
stdout '^\$WORK[/\\]gopath[/\\]src[/\\]go.mod$'
# 'go list -m' should print the effective go.mod file as GoMod though.
go list -m -f '{{.GoMod}}'
stdout '^go.alt.mod$'
# go mod edit should operate on the alternate file
go mod edit -require rsc.io/quote@v1.5.2
grep rsc.io/quote go.alt.mod

View File

@ -1,11 +1,21 @@
env GO111MODULE=off
! go test badtest/...
! go test badtest/badexec
! stdout ^ok
stdout ^FAIL\tbadtest/badexec
! go test badtest/badsyntax
! stdout ^ok
stdout ^FAIL\tbadtest/badsyntax
! go test badtest/badvar
! stdout ^ok
stdout ^FAIL\tbadtest/badvar
! go test notest
! stdout ^ok
stderr '^notest.hello.go:6:1: .*declaration' # Exercise issue #7108
-- badtest/badexec/x_test.go --
package badexec
@ -30,3 +40,10 @@ package badvar_test
func f() {
_ = notdefined
}
-- notest/hello.go --
package notest
func hello() {
println("hello world")
}
Hello world

View File

@ -1 +0,0 @@
// C code!

View File

@ -1 +0,0 @@
package badc

View File

@ -1 +0,0 @@
pkg badpkg

View File

@ -1,6 +0,0 @@
package bench
import "testing"
func Benchmark(b *testing.B) {
}

View File

@ -1,7 +0,0 @@
package benchfatal
import "testing"
func BenchmarkThatCallsFatal(b *testing.B) {
b.Fatal("called by benchmark")
}

View File

@ -1,8 +0,0 @@
package p
/*
// hi
*/
import "C"
func F() {}

View File

@ -1,2 +0,0 @@
TEXT asm(SB),$0
RET

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1,7 +0,0 @@
package p
import "testing"
func TestF(t *testing.T) {
F()
}

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1,10 +0,0 @@
package p_test
import (
. "cgocover2"
"testing"
)
func TestF(t *testing.T) {
F()
}

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1 +0,0 @@
package p

View File

@ -1,10 +0,0 @@
package p_test
import (
. "cgocover3"
"testing"
)
func TestF(t *testing.T) {
F()
}

View File

@ -1 +0,0 @@
package p

View File

@ -1,19 +0,0 @@
package p
/*
void
f(void)
{
}
*/
import "C"
var b bool
func F() {
if b {
for {
}
}
C.f()
}

View File

@ -1,10 +0,0 @@
package p_test
import (
. "cgocover4"
"testing"
)
func TestF(t *testing.T) {
F()
}

View File

@ -1,8 +0,0 @@
package main
import (
_ "dupload/p2"
_ "p"
)
func main() {}

View File

@ -1 +0,0 @@
package p

View File

@ -1,3 +0,0 @@
package p2
import _ "dupload/vendor/p"

View File

@ -1 +0,0 @@
package p

View File

@ -1,5 +0,0 @@
//go:generate echo hello world
package gencycle
import _ "gencycle"

View File

@ -1,5 +0,0 @@
package main
import _ "importmain/test"
func main() {}

View File

@ -1 +0,0 @@
package test

View File

@ -1,6 +0,0 @@
package test_test
import "testing"
import _ "importmain/ismain"
func TestCase(t *testing.T) {}

View File

@ -1,16 +0,0 @@
package multimain_test
import "testing"
func TestMain(m *testing.M) {
// Some users run m.Run multiple times, changing
// some kind of global state between runs.
// This used to work so I guess now it has to keep working.
// See golang.org/issue/23129.
m.Run()
m.Run()
}
func Test(t *testing.T) {
t.Log("notwithstanding")
}

View File

@ -1,3 +0,0 @@
package not_main
func F() {}

View File

@ -1,6 +0,0 @@
package notest
func hello() {
println("hello world")
}
Hello world

View File

@ -1,5 +0,0 @@
package main
import _ "run/subdir/internal/private"
func main() {}

View File

@ -1,5 +0,0 @@
package main
import _ "run/internal"
func main() {}

View File

@ -1 +0,0 @@
package internal

View File

@ -1 +0,0 @@
package private

View File

@ -1,10 +0,0 @@
package p
import (
"testing"
"time"
)
func Test1(t *testing.T) {
time.Sleep(200 * time.Millisecond)
}

View File

@ -1,10 +0,0 @@
package p
import (
"testing"
"time"
)
func Test1(t *testing.T) {
time.Sleep(200 * time.Millisecond)
}

View File

@ -1,5 +0,0 @@
package p
// missing import
var _ = io.DoesNotExist

View File

@ -1 +0,0 @@
package p

View File

@ -1,4 +0,0 @@
package p
func f() (x.y, z int) {
}

View File

@ -1,7 +0,0 @@
package p1
import _ "testcycle/p2"
func init() {
println("p1 init")
}

View File

@ -1,6 +0,0 @@
package p1
import "testing"
func Test(t *testing.T) {
}

View File

@ -1,7 +0,0 @@
package p2
import _ "testcycle/p3"
func init() {
println("p2 init")
}

View File

@ -1,5 +0,0 @@
package p3
func init() {
println("p3 init")
}

View File

@ -1,10 +0,0 @@
package p3
import (
"testing"
_ "testcycle/p1"
)
func Test(t *testing.T) {
}

View File

@ -1 +0,0 @@
package q1

View File

@ -1,6 +0,0 @@
package q1
import "testing"
import _ "testcycle/q1"
func Test(t *testing.T) {}

View File

@ -1 +0,0 @@
package p1

View File

@ -1,3 +0,0 @@
package p1
import _ "testdep/p2"

View File

@ -1,3 +0,0 @@
package p2
import _ "testdep/p3"

View File

@ -1,3 +0,0 @@
// +build ignore
package ignored

View File

@ -1,5 +0,0 @@
package p
func init() {
panic("go test must not link and run test binaries without tests")
}

View File

@ -1,31 +0,0 @@
package testrace
import "testing"
func TestRace(t *testing.T) {
for i := 0; i < 10; i++ {
c := make(chan int)
x := 1
go func() {
x = 2
c <- 1
}()
x = 3
<-c
_ = x
}
}
func BenchmarkRace(b *testing.B) {
for i := 0; i < b.N; i++ {
c := make(chan int)
x := 1
go func() {
x = 2
c <- 1
}()
x = 3
<-c
_ = x
}
}

View File

@ -1,17 +0,0 @@
package x
import "testing"
func TestX(t *testing.T) {
t.Logf("LOG: X running")
t.Run("Y", func(t *testing.T) {
t.Logf("LOG: Y running")
})
}
func BenchmarkX(b *testing.B) {
b.Logf("LOG: X running N=%d", b.N)
b.Run("Y", func(b *testing.B) {
b.Logf("LOG: Y running N=%d", b.N)
})
}

View File

@ -1,19 +0,0 @@
package x
import "testing"
func TestZ(t *testing.T) {
t.Logf("LOG: Z running")
}
func TestXX(t *testing.T) {
t.Logf("LOG: XX running")
}
func BenchmarkZ(b *testing.B) {
b.Logf("LOG: Z running N=%d", b.N)
}
func BenchmarkXX(b *testing.B) {
b.Logf("LOG: XX running N=%d", b.N)
}

View File

@ -116,9 +116,10 @@ func DialWithDialer(dialer *net.Dialer, network, addr string, config *Config) (*
if timeout != 0 {
errChannel = make(chan error, 2)
time.AfterFunc(timeout, func() {
timer := time.AfterFunc(timeout, func() {
errChannel <- timeoutError{}
})
defer timer.Stop()
}
rawConn, err := dialer.Dial(network, addr)

View File

@ -159,7 +159,7 @@ static Boolean isRootCertificate(SecCertificateRef cert, CFErrorRef *errRef) {
//
// Note: The CFDataRef returned in pemRoots and untrustedPemRoots must
// be released (using CFRelease) after we've consumed its content.
int CopyPEMRoots(CFDataRef *pemRoots, CFDataRef *untrustedPemRoots, bool debugDarwinRoots) {
static int CopyPEMRoots(CFDataRef *pemRoots, CFDataRef *untrustedPemRoots, bool debugDarwinRoots) {
int i;
if (debugDarwinRoots) {

View File

@ -219,10 +219,26 @@ func (c *Certificate) systemVerify(opts *VerifyOptions) (chains [][]*Certificate
if err != nil {
return nil, err
}
if len(chain) < 1 {
return nil, errors.New("x509: internal error: system verifier returned an empty chain")
}
chains = append(chains, chain)
// Mitigate CVE-2020-0601, where the Windows system verifier might be
// tricked into using custom curve parameters for a trusted root, by
// double-checking all ECDSA signatures. If the system was tricked into
// using spoofed parameters, the signature will be invalid for the correct
// ones we parsed. (We don't support custom curves ourselves.)
for i, parent := range chain[1:] {
if parent.PublicKeyAlgorithm != ECDSA {
continue
}
if err := parent.CheckSignature(chain[i].SignatureAlgorithm,
chain[i].RawTBSCertificate, chain[i].Signature); err != nil {
return nil, err
}
}
return chains, nil
return [][]*Certificate{chain}, nil
}
func loadSystemRoots() (*CertPool, error) {

View File

@ -629,7 +629,8 @@ func TestPoolExhaustOnCancel(t *testing.T) {
go func() {
rows, err := db.Query("SELECT|people|name,photo|")
if err != nil {
t.Fatalf("Query: %v", err)
t.Errorf("Query: %v", err)
return
}
rows.Close()
saturateDone.Done()
@ -637,6 +638,9 @@ func TestPoolExhaustOnCancel(t *testing.T) {
}
saturate.Wait()
if t.Failed() {
t.FailNow()
}
state = 2
// Now cancel the request while it is waiting.

Some files were not shown because too many files have changed in this diff Show More