github.com/powerman/golang-tools@v0.1.11-0.20220410185822-5ad214d8d803/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 "github.com/powerman/golang-tools/go/analysis/analysistest" 13 "github.com/powerman/golang-tools/go/analysis/passes/buildssa" 14 "github.com/powerman/golang-tools/internal/typeparams" 15 ) 16 17 func Test(t *testing.T) { 18 testdata := analysistest.TestData() 19 result := analysistest.Run(t, testdata, buildssa.Analyzer, "a")[0].Result 20 21 ssainfo := result.(*buildssa.SSA) 22 got := fmt.Sprint(ssainfo.SrcFuncs) 23 want := `[a.Fib (a.T).fib]` 24 if got != want { 25 t.Errorf("SSA.SrcFuncs = %s, want %s", got, want) 26 for _, f := range ssainfo.SrcFuncs { 27 f.WriteTo(os.Stderr) 28 } 29 } 30 } 31 32 func TestGenericDecls(t *testing.T) { 33 if !typeparams.Enabled { 34 t.Skip("TestGenericDecls requires type parameters.") 35 } 36 testdata := analysistest.TestData() 37 result := analysistest.Run(t, testdata, buildssa.Analyzer, "b")[0].Result 38 39 ssainfo := result.(*buildssa.SSA) 40 got := fmt.Sprint(ssainfo.SrcFuncs) 41 want := `[(*b.Pointer[T]).Load b.Load b.LoadPointer]` 42 if got != want { 43 t.Errorf("SSA.SrcFuncs = %s, want %s", got, want) 44 for _, f := range ssainfo.SrcFuncs { 45 f.WriteTo(os.Stderr) 46 } 47 } 48 } 49 50 func TestImporting(t *testing.T) { 51 if !typeparams.Enabled { 52 t.Skip("TestImporting depends on testdata/b/b/go which uses type parameters.") 53 } 54 testdata := analysistest.TestData() 55 result := analysistest.Run(t, testdata, buildssa.Analyzer, "c")[0].Result 56 57 ssainfo := result.(*buildssa.SSA) 58 got := fmt.Sprint(ssainfo.SrcFuncs) 59 want := `[c.A c.B]` 60 if got != want { 61 t.Errorf("SSA.SrcFuncs = %s, want %s", got, want) 62 for _, f := range ssainfo.SrcFuncs { 63 f.WriteTo(os.Stderr) 64 } 65 } 66 }