mirror of
https://github.com/golang/go
synced 2024-11-05 21:26:11 -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>
89 lines
1.8 KiB
Plaintext
89 lines
1.8 KiB
Plaintext
rsc.io/QUOTE v1.5.2
|
|
|
|
-- .mod --
|
|
module rsc.io/QUOTE
|
|
|
|
require rsc.io/quote v1.5.2
|
|
-- .info --
|
|
{"Version":"v1.5.2","Name":"","Short":"","Time":"2018-07-15T16:25:34Z"}
|
|
-- go.mod --
|
|
module rsc.io/QUOTE
|
|
|
|
require rsc.io/quote v1.5.2
|
|
-- QUOTE/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 LOUD SAYINGS.
|
|
package QUOTE
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"rsc.io/quote"
|
|
)
|
|
|
|
// HELLO RETURNS A GREETING.
|
|
func HELLO() string {
|
|
return strings.ToUpper(quote.Hello())
|
|
}
|
|
|
|
// GLASS RETURNS A USEFUL PHRASE FOR WORLD TRAVELERS.
|
|
func GLASS() string {
|
|
return strings.ToUpper(quote.GLASS())
|
|
}
|
|
|
|
// GO RETURNS A GO PROVERB.
|
|
func GO() string {
|
|
return strings.ToUpper(quote.GO())
|
|
}
|
|
|
|
// OPT RETURNS AN OPTIMIZATION TRUTH.
|
|
func OPT() string {
|
|
return strings.ToUpper(quote.OPT())
|
|
}
|
|
-- QUOTE/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)
|
|
}
|
|
}
|