From 74466f4d35ec47db86d038383134883b707e42a1 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Sun, 12 Aug 2018 10:29:13 -0700 Subject: cmd/hclspecsuite: show source snippets for errors in .hcldec files --- cmd/hclspecsuite/runner.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'cmd') diff --git a/cmd/hclspecsuite/runner.go b/cmd/hclspecsuite/runner.go index e3d1235..448d41c 100644 --- a/cmd/hclspecsuite/runner.go +++ b/cmd/hclspecsuite/runner.go @@ -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, -- cgit v1.2.3