summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMartin Atkins <mart@degeneration.co.uk>2018-08-12 10:29:13 -0700
committerMartin Atkins <mart@degeneration.co.uk>2018-08-12 10:29:13 -0700
commit74466f4d35ec47db86d038383134883b707e42a1 (patch)
treedc4214719ed0e603289aa69a10d176a1dc6eb9c6 /cmd
parenta5c0f7fdcce278f8aab81a222c9800cd62c907d3 (diff)
cmd/hclspecsuite: show source snippets for errors in .hcldec files
Diffstat (limited to 'cmd')
-rw-r--r--cmd/hclspecsuite/runner.go11
1 files changed, 11 insertions, 0 deletions
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,