1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
package fuzzhclsyntax
import (
"testing"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hclsyntax"
)
func FuzzParseTemplate(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
_, diags := hclsyntax.ParseTemplate(data, "<fuzz-tmpl>", hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
t.Logf("Error when parsing template %v", data)
for _, diag := range diags {
t.Logf("- %s", diag.Error())
}
}
})
}
func FuzzParseTraversalAbs(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
_, diags := hclsyntax.ParseTraversalAbs(data, "<fuzz-trav>", hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
t.Logf("Error when parsing traversal %v", data)
for _, diag := range diags {
t.Logf("- %s", diag.Error())
}
}
})
}
func FuzzParseExpression(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
_, diags := hclsyntax.ParseExpression(data, "<fuzz-expr>", hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
t.Logf("Error when parsing expression %v", data)
for _, diag := range diags {
t.Logf("- %s", diag.Error())
}
}
})
}
func FuzzParseConfig(f *testing.F) {
f.Fuzz(func(t *testing.T, data []byte) {
_, diags := hclsyntax.ParseConfig(data, "<fuzz-conf>", hcl.Pos{Line: 1, Column: 1})
if diags.HasErrors() {
t.Logf("Error when parsing config %v", data)
for _, diag := range diags {
t.Logf("- %s", diag.Error())
}
}
})
}
|