cmd/hclspecsuite: show source snippets for errors in .hcldec files

This commit is contained in:
Martin Atkins 2018-08-12 10:29:13 -07:00
parent a5c0f7fdcc
commit 74466f4d35
1 changed files with 11 additions and 0 deletions

View File

@ -97,6 +97,17 @@ func (r *Runner) runTest(filename string) hcl.Diagnostics {
nativeFilename := basePath + ".hcl"
jsonFilename := basePath + ".hcl.json"
// We'll add the source code of the spec file to our own parser, even
// though it'll actually be parsed by the hcldec child process, since that
// way we can produce nice diagnostic messages if hcldec fails to process
// the spec file.
src, err := ioutil.ReadFile(specFilename)
if err == nil {
r.parser.AddFile(specFilename, &hcl.File{
Bytes: src,
})
}
if _, err := os.Stat(specFilename); err != nil {
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,