Skip to content

Commit 64371ad

Browse files
neildgopherbot
authored andcommitted
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>
1 parent fcd73b0 commit 64371ad

File tree

6 files changed

+37
-11
lines changed

6 files changed

+37
-11
lines changed

src/cmd/go/internal/imports/scan_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@ import (
1717
func TestScan(t *testing.T) {
1818
testenv.MustHaveGoBuild(t)
1919

20-
imports, testImports, err := ScanDir(filepath.Join(testenv.GOROOT(t), "src/encoding/json"), Tags())
20+
imports, testImports, err := ScanDir(filepath.Join(testenv.GOROOT(t), "src/cmd/go/internal/imports/testdata/test"), Tags())
2121
if err != nil {
2222
t.Fatal(err)
2323
}
24-
foundBase64 := false
24+
foundFmt := false
2525
for _, p := range imports {
26-
if p == "encoding/base64" {
27-
foundBase64 = true
26+
if p == "fmt" {
27+
foundFmt = true // test package imports fmt directly
2828
}
2929
if p == "encoding/binary" {
3030
// A dependency but not an import
31-
t.Errorf("json reported as importing encoding/binary but does not")
31+
t.Errorf("testdata/test reported as importing encoding/binary but does not")
3232
}
3333
if p == "net/http" {
3434
// A test import but not an import
35-
t.Errorf("json reported as importing net/http but does not")
35+
t.Errorf("testdata/test reported as importing net/http but does not")
3636
}
3737
}
38-
if !foundBase64 {
39-
t.Errorf("json missing import encoding/base64 (%q)", imports)
38+
if !foundFmt {
39+
t.Errorf("testdata/test missing import fmt (%q)", imports)
4040
}
4141

4242
foundHTTP := false
4343
for _, p := range testImports {
4444
if p == "net/http" {
4545
foundHTTP = true
4646
}
47-
if p == "unicode/utf16" {
47+
if p == "fmt" {
4848
// A package import but not a test import
49-
t.Errorf("json reported as test-importing unicode/utf16 but does not")
49+
t.Errorf("testdata/test reported as test-importing fmt but does not")
5050
}
5151
}
5252
if !foundHTTP {
53-
t.Errorf("json missing test import net/http (%q)", testImports)
53+
t.Errorf("testdata/test missing test import net/http (%q)", testImports)
5454
}
5555
}
5656
func TestScanDir(t *testing.T) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package child
2+
3+
import "encoding/binary"
4+
5+
var V = binary.MaxVarintLen16

src/cmd/go/internal/imports/testdata/test/tags.txt

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package test
2+
3+
import (
4+
"cmd/go/internal/imports/testdata/test/child"
5+
"fmt"
6+
)
7+
8+
func F() {
9+
fmt.Println(child.V)
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package test_test
2+
3+
import (
4+
_ "net/http"
5+
"testing"
6+
)
7+
8+
func Test(t *testing.T) {
9+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
cmd/go/internal/imports/testdata/test/child
2+
fmt

0 commit comments

Comments
 (0)