golang.org/x/tools@v0.21.0/go/analysis/passes/buildssa/buildssa_test.go (about) 1 // Copyright 2018 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package buildssa_test 6 7 import ( 8 "fmt" 9 "os" 10 "testing" 11 12 "golang.org/x/tools/go/analysis/analysistest" 13 "golang.org/x/tools/go/analysis/passes/buildssa" 14 ) 15 16 func Test(t *testing.T) { 17 testdata := analysistest.TestData() 18 result := analysistest.Run(t, testdata, buildssa.Analyzer, "a")[0].Result 19 20 ssainfo := result.(*buildssa.SSA) 21 got := fmt.Sprint(ssainfo.SrcFuncs) 22 want := `[a.Fib (a.T).fib a._ a._]` 23 if got != want { 24 t.Errorf("SSA.SrcFuncs = %s, want %s", got, want) 25 for _, f := range ssainfo.SrcFuncs { 26 f.WriteTo(os.Stderr) 27 } 28 } 29 } 30 31 func TestGenericDecls(t *testing.T) { 32 testdata := analysistest.TestData() 33 result := analysistest.Run(t, testdata, buildssa.Analyzer, "b")[0].Result 34 35 ssainfo := result.(*buildssa.SSA) 36 got := fmt.Sprint(ssainfo.SrcFuncs) 37 want := `[(*b.Pointer[T]).Load b.Load b.LoadPointer]` 38 if got != want { 39 t.Errorf("SSA.SrcFuncs = %s, want %s", got, want) 40 for _, f := range ssainfo.SrcFuncs { 41 f.WriteTo(os.Stderr) 42 } 43 } 44 } 45 46 func TestImporting(t *testing.T) { 47 testdata := analysistest.TestData() 48 result := analysistest.Run(t, testdata, buildssa.Analyzer, "c")[0].Result 49 50 ssainfo := result.(*buildssa.SSA) 51 got := fmt.Sprint(ssainfo.SrcFuncs) 52 want := `[c.A c.B]` 53 if got != want { 54 t.Errorf("SSA.SrcFuncs = %s, want %s", got, want) 55 for _, f := range ssainfo.SrcFuncs { 56 f.WriteTo(os.Stderr) 57 } 58 } 59 }