github.com/hashicorp/hcl/v2@v2.20.0/hclwrite/fuzz/fuzz_test.go (about) 1 // Copyright (c) HashiCorp, Inc. 2 // SPDX-License-Identifier: MPL-2.0 3 4 package fuzzhclwrite 5 6 import ( 7 "io/ioutil" 8 "testing" 9 10 "github.com/hashicorp/hcl/v2" 11 "github.com/hashicorp/hcl/v2/hclwrite" 12 ) 13 14 func FuzzParseConfig(f *testing.F) { 15 f.Fuzz(func(t *testing.T, data []byte) { 16 file, diags := hclwrite.ParseConfig(data, "<fuzz-conf>", hcl.Pos{Line: 1, Column: 1}) 17 18 if diags.HasErrors() { 19 t.Logf("Error when parsing JSON %v", data) 20 for _, diag := range diags { 21 t.Logf("- %s", diag.Error()) 22 } 23 return 24 } 25 26 _, err := file.WriteTo(ioutil.Discard) 27 28 if err != nil { 29 t.Fatalf("error writing to file: %s", err) 30 } 31 }) 32 }