github.com/x04/go/src@v0.0.0-20200202162449-3d481ceb3525/runtime/checkptr_test.go (about) 1 // Copyright 2020 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 runtime_test 6 7 import ( 8 "github.com/x04/go/src/internal/testenv" 9 "github.com/x04/go/src/os/exec" 10 "github.com/x04/go/src/strings" 11 "github.com/x04/go/src/testing" 12 ) 13 14 func TestCheckPtr(t *testing.T) { 15 t.Parallel() 16 testenv.MustHaveGoRun(t) 17 18 exe, err := buildTestProg(t, "testprog", "-gcflags=all=-d=checkptr=1") 19 if err != nil { 20 t.Fatal(err) 21 } 22 23 testCases := []struct { 24 cmd string 25 want string 26 }{ 27 {"CheckPtrAlignment", "fatal error: checkptr: unsafe pointer conversion\n"}, 28 {"CheckPtrArithmetic", "fatal error: checkptr: unsafe pointer arithmetic\n"}, 29 {"CheckPtrSize", "fatal error: checkptr: unsafe pointer conversion\n"}, 30 {"CheckPtrSmall", "fatal error: checkptr: unsafe pointer arithmetic\n"}, 31 } 32 33 for _, tc := range testCases { 34 tc := tc 35 t.Run(tc.cmd, func(t *testing.T) { 36 t.Parallel() 37 got, err := testenv.CleanCmdEnv(exec.Command(exe, tc.cmd)).CombinedOutput() 38 if err != nil { 39 t.Log(err) 40 } 41 if !strings.HasPrefix(string(got), tc.want) { 42 t.Errorf("output:\n%s\n\nwant output starting with: %s", got, tc.want) 43 } 44 }) 45 } 46 }