mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
cmd/go/internal/imports: remove test dependency on json internals
TestScan loads encoding/json and verifies that various imports match expectations. The new v2 encoding/json violates these expectations. Since this test is testing the ScanDir function, not encoding/json, change it to use a test package with defined imports instead. Change-Id: I68a0813ccf37daadbd6ea52872a8ac132141e82a Reviewed-on: https://go-review.googlesource.com/c/go/+/665795 Reviewed-by: Alan Donovan <adonovan@google.com> TryBot-Bypass: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com>
This commit is contained in:
parent
fcd73b0ac3
commit
64371adcf4
@ -17,26 +17,26 @@ import (
|
||||
func TestScan(t *testing.T) {
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
imports, testImports, err := ScanDir(filepath.Join(testenv.GOROOT(t), "src/encoding/json"), Tags())
|
||||
imports, testImports, err := ScanDir(filepath.Join(testenv.GOROOT(t), "src/cmd/go/internal/imports/testdata/test"), Tags())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
foundBase64 := false
|
||||
foundFmt := false
|
||||
for _, p := range imports {
|
||||
if p == "encoding/base64" {
|
||||
foundBase64 = true
|
||||
if p == "fmt" {
|
||||
foundFmt = true // test package imports fmt directly
|
||||
}
|
||||
if p == "encoding/binary" {
|
||||
// A dependency but not an import
|
||||
t.Errorf("json reported as importing encoding/binary but does not")
|
||||
t.Errorf("testdata/test reported as importing encoding/binary but does not")
|
||||
}
|
||||
if p == "net/http" {
|
||||
// A test import but not an import
|
||||
t.Errorf("json reported as importing net/http but does not")
|
||||
t.Errorf("testdata/test reported as importing net/http but does not")
|
||||
}
|
||||
}
|
||||
if !foundBase64 {
|
||||
t.Errorf("json missing import encoding/base64 (%q)", imports)
|
||||
if !foundFmt {
|
||||
t.Errorf("testdata/test missing import fmt (%q)", imports)
|
||||
}
|
||||
|
||||
foundHTTP := false
|
||||
@ -44,13 +44,13 @@ func TestScan(t *testing.T) {
|
||||
if p == "net/http" {
|
||||
foundHTTP = true
|
||||
}
|
||||
if p == "unicode/utf16" {
|
||||
if p == "fmt" {
|
||||
// A package import but not a test import
|
||||
t.Errorf("json reported as test-importing unicode/utf16 but does not")
|
||||
t.Errorf("testdata/test reported as test-importing fmt but does not")
|
||||
}
|
||||
}
|
||||
if !foundHTTP {
|
||||
t.Errorf("json missing test import net/http (%q)", testImports)
|
||||
t.Errorf("testdata/test missing test import net/http (%q)", testImports)
|
||||
}
|
||||
}
|
||||
func TestScanDir(t *testing.T) {
|
||||
|
5
src/cmd/go/internal/imports/testdata/test/child/child.go
vendored
Normal file
5
src/cmd/go/internal/imports/testdata/test/child/child.go
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
package child
|
||||
|
||||
import "encoding/binary"
|
||||
|
||||
var V = binary.MaxVarintLen16
|
0
src/cmd/go/internal/imports/testdata/test/tags.txt
vendored
Normal file
0
src/cmd/go/internal/imports/testdata/test/tags.txt
vendored
Normal file
10
src/cmd/go/internal/imports/testdata/test/test.go
vendored
Normal file
10
src/cmd/go/internal/imports/testdata/test/test.go
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"cmd/go/internal/imports/testdata/test/child"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func F() {
|
||||
fmt.Println(child.V)
|
||||
}
|
9
src/cmd/go/internal/imports/testdata/test/test_test.go
vendored
Normal file
9
src/cmd/go/internal/imports/testdata/test/test_test.go
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
package test_test
|
||||
|
||||
import (
|
||||
_ "net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
}
|
2
src/cmd/go/internal/imports/testdata/test/want.txt
vendored
Normal file
2
src/cmd/go/internal/imports/testdata/test/want.txt
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
cmd/go/internal/imports/testdata/test/child
|
||||
fmt
|
Loading…
x
Reference in New Issue
Block a user