From 83362c3779f5f48611068d488a03ea7bbaddc81e Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 21 Feb 2019 12:51:16 -0500 Subject: [PATCH] go/gcexportdata: use a constant from a frozen package for testing Switch from test to use net/rpc instead of text/scanner, since net/rpc is a frozen package that is guaranteed not to change. Change-Id: I6ece679bc16737fa9a75ac896f9eb2190317a498 Reviewed-on: https://go-review.googlesource.com/c/163204 Run-TryBot: Rebecca Stambler TryBot-Result: Gobot Gobot Reviewed-by: Dmitri Shuralyov --- go/gcexportdata/example_test.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/go/gcexportdata/example_test.go b/go/gcexportdata/example_test.go index 3a205abf1d..c2a18561f6 100644 --- a/go/gcexportdata/example_test.go +++ b/go/gcexportdata/example_test.go @@ -70,15 +70,15 @@ func ExampleRead() { // ExampleNewImporter demonstrates usage of NewImporter to provide type // information for dependencies when type-checking Go source code. func ExampleNewImporter() { - const src = `package myscanner + const src = `package myrpc -// choosing a package that is unlikely to change across releases -import "text/scanner" +// choosing a package that doesn't change across releases +import "net/rpc" -const scanIdents = scanner.ScanIdents +const defaultRPCPath = rpc.DefaultRPCPath ` fset := token.NewFileSet() - f, err := parser.ParseFile(fset, "myscanner.go", src, 0) + f, err := parser.ParseFile(fset, "myrpc.go", src, 0) if err != nil { log.Fatal(err) } @@ -86,13 +86,13 @@ const scanIdents = scanner.ScanIdents packages := make(map[string]*types.Package) imp := gcexportdata.NewImporter(fset, packages) conf := types.Config{Importer: imp} - pkg, err := conf.Check("myscanner", fset, []*ast.File{f}, nil) + pkg, err := conf.Check("myrpc", fset, []*ast.File{f}, nil) if err != nil { log.Fatal(err) } // object from imported package - pi := packages["text/scanner"].Scope().Lookup("ScanIdents") + pi := packages["net/rpc"].Scope().Lookup("DefaultRPCPath") fmt.Printf("const %s.%s %s = %s // %s\n", pi.Pkg().Path(), pi.Name(), @@ -102,7 +102,7 @@ const scanIdents = scanner.ScanIdents ) // object in source package - twopi := pkg.Scope().Lookup("scanIdents") + twopi := pkg.Scope().Lookup("defaultRPCPath") fmt.Printf("const %s %s = %s // %s\n", twopi.Name(), twopi.Type(), @@ -112,8 +112,8 @@ const scanIdents = scanner.ScanIdents // Output: // - // const text/scanner.ScanIdents untyped int = 4 // $GOROOT/src/text/scanner/scanner.go:62:1 - // const scanIdents untyped int = 4 // myscanner.go:6:7 + // const net/rpc.DefaultRPCPath untyped string = "/_goRPC_" // $GOROOT/src/net/rpc/server.go:146:1 + // const defaultRPCPath untyped string = "/_goRPC_" // myrpc.go:6:7 } func slashify(posn token.Position) token.Position {