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