modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/issue16037_run.go (about) 1 // +build !nacl,!android 2 // run 3 4 // Copyright 2016 The Go Authors. All rights reserved. 5 // Use of this source code is governed by a BSD-style 6 // license that can be found in the LICENSE file. 7 8 package main 9 10 import ( 11 "bytes" 12 "fmt" 13 "html/template" 14 "io/ioutil" 15 "log" 16 "os" 17 "os/exec" 18 "path/filepath" 19 ) 20 21 var tmpl = template.Must(template.New("main").Parse(` 22 package main 23 24 type T struct { 25 {{range .Names}} 26 {{.Name}} *string 27 {{end}} 28 } 29 30 {{range .Names}} 31 func (t *T) Get{{.Name}}() string { 32 if t.{{.Name}} == nil { 33 return "" 34 } 35 return *t.{{.Name}} 36 } 37 {{end}} 38 39 func main() {} 40 `)) 41 42 func main() { 43 const n = 5000 44 45 type Name struct{ Name string } 46 var t struct{ Names []Name } 47 for i := 0; i < n; i++ { 48 t.Names = append(t.Names, Name{Name: fmt.Sprintf("H%06X", i)}) 49 } 50 51 buf := new(bytes.Buffer) 52 if err := tmpl.Execute(buf, t); err != nil { 53 log.Fatal(err) 54 } 55 56 dir, err := ioutil.TempDir("", "issue16037-") 57 if err != nil { 58 log.Fatal(err) 59 } 60 defer os.RemoveAll(dir) 61 path := filepath.Join(dir, "ridiculous_number_of_fields.go") 62 if err := ioutil.WriteFile(path, buf.Bytes(), 0664); err != nil { 63 log.Fatal(err) 64 } 65 66 out, err := exec.Command("go", "build", "-o="+filepath.Join(dir, "out"), path).CombinedOutput() 67 if err != nil { 68 log.Fatalf("build failed: %v\n%s", err, out) 69 } 70 }