mirror of
https://github.com/golang/go
synced 2024-11-19 05:24:42 -07:00
9c309ee22f
go/packages needs to call `go list` multiple times, which causes redundant work and slows down goimports. If we reimplement `go list` in memory, we can reuse state, saving time. `go list` also does work we don't really need, like adding stuff to go.mod, and skipping that saves more time. We start with `go list -m`, which does MVS and such. The remaining work is mostly mapping import paths and directories through the in-scope modules to make sure we're giving the right answers. Unfortunately this is quite subtle, and I don't know where all the traps are. I did my best. cmd/go already has tests for `go list`, of course, and packagestest is not well suited to tests of this complexity. So I ripped off the script tests in cmd/go that seemed relevant and made sure that our logic returns the right stuff in each case. I'm sure that there are more cases to cover, but this hit all the stuff I knew about and quite a bit I didn't. Since we may want to use the go/packages code path in the future, e.g. for Bazel, I left that in place. It won't be used unless the magic env var is set. Files in internal and imports/testdata/mod were copied verbatim from cmd/go. Change-Id: I1248d99c400c1a0c7ef180d4460b9b8a3db0246b Reviewed-on: https://go-review.googlesource.com/c/158097 Run-TryBot: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
87 lines
2.0 KiB
Plaintext
87 lines
2.0 KiB
Plaintext
rsc.io/quote/v2@v2.0.1
|
|
|
|
-- .mod --
|
|
module rsc.io/quote/v2
|
|
|
|
require rsc.io/sampler v1.3.0
|
|
-- .info --
|
|
{"Version":"v2.0.1","Name":"754f68430672776c84704e2d10209a6ec700cd64","Short":"754f68430672","Time":"2018-07-09T16:25:34Z"}
|
|
-- go.mod --
|
|
module rsc.io/quote/v2
|
|
|
|
require rsc.io/sampler v1.3.0
|
|
-- quote.go --
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package quote collects pithy sayings.
|
|
package quote // import "rsc.io/quote"
|
|
|
|
import "rsc.io/sampler"
|
|
|
|
// Hello returns a greeting.
|
|
func HelloV2() string {
|
|
return sampler.Hello()
|
|
}
|
|
|
|
// Glass returns a useful phrase for world travelers.
|
|
func GlassV2() string {
|
|
// See http://www.oocities.org/nodotus/hbglass.html.
|
|
return "I can eat glass and it doesn't hurt me."
|
|
}
|
|
|
|
// Go returns a Go proverb.
|
|
func GoV2() string {
|
|
return "Don't communicate by sharing memory, share memory by communicating."
|
|
}
|
|
|
|
// Opt returns an optimization truth.
|
|
func OptV2() string {
|
|
// Wisdom from ken.
|
|
return "If a program is too slow, it must have a loop."
|
|
}
|
|
-- quote_test.go --
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package quote
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func init() {
|
|
os.Setenv("LC_ALL", "en")
|
|
}
|
|
|
|
func TestHello(t *testing.T) {
|
|
hello := "Hello, world."
|
|
if out := Hello(); out != hello {
|
|
t.Errorf("Hello() = %q, want %q", out, hello)
|
|
}
|
|
}
|
|
|
|
func TestGlass(t *testing.T) {
|
|
glass := "I can eat glass and it doesn't hurt me."
|
|
if out := Glass(); out != glass {
|
|
t.Errorf("Glass() = %q, want %q", out, glass)
|
|
}
|
|
}
|
|
|
|
func TestGo(t *testing.T) {
|
|
go1 := "Don't communicate by sharing memory, share memory by communicating."
|
|
if out := Go(); out != go1 {
|
|
t.Errorf("Go() = %q, want %q", out, go1)
|
|
}
|
|
}
|
|
|
|
func TestOpt(t *testing.T) {
|
|
opt := "If a program is too slow, it must have a loop."
|
|
if out := Opt(); out != opt {
|
|
t.Errorf("Opt() = %q, want %q", out, opt)
|
|
}
|
|
}
|