1
2
3
4
5 package debug_test
6
7 import (
8 "reflect"
9 "runtime/debug"
10 "strings"
11 "testing"
12 )
13
14
15 func strip(s string) string {
16 replaced := strings.ReplaceAll(s, "\n\t\t", "\n")
17 if len(replaced) > 0 && replaced[0] == '\n' {
18 replaced = replaced[1:]
19 }
20 return replaced
21 }
22
23 func FuzzParseBuildInfoRoundTrip(f *testing.F) {
24
25 f.Add(strip(`
26 path rsc.io/fortune
27 mod rsc.io/fortune v1.0.0
28 `))
29
30
31 f.Add(`path cmd/test2json`)
32
33
34 f.Add(strip(`
35 go 1.18
36 path example.com/m
37 mod example.com/m (devel)
38 build -compiler=gc
39 `))
40
41
42 f.Add(strip(`
43 go 1.18
44 path example.com/m
45 build -compiler=gc
46 `))
47
48
49 f.Add(strip(`
50 go 1.18
51 path example.com/m
52 build CRAZY_ENV="requires\nescaping"
53 `))
54
55 f.Fuzz(func(t *testing.T, s string) {
56 bi, err := debug.ParseBuildInfo(s)
57 if err != nil {
58
59 t.Log(err)
60 return
61 }
62
63
64
65 s2 := bi.String()
66 bi2, err := debug.ParseBuildInfo(s2)
67 if err != nil {
68 t.Fatalf("%v:\n%s", err, s2)
69 }
70
71 if !reflect.DeepEqual(bi2, bi) {
72 t.Fatalf("Parsed representation differs.\ninput:\n%s\noutput:\n%s", s, s2)
73 }
74 })
75 }
76
View as plain text