MCPcopy
hub / github.com/hashicorp/hcl / runTest

Method runTest

cmd/hclspecsuite/runner.go:84–144  ·  view source on GitHub ↗
(filename string)

Source from the content-addressed store, hash-verified

82}
83
84func (r *Runner) runTest(filename string) hcl.Diagnostics {
85 prettyName := r.prettyTestName(filename)
86 tf, diags := r.LoadTestFile(filename)
87 if diags.HasErrors() {
88 // We'll still log, so it's clearer which test the diagnostics belong to.
89 if r.logBegin != nil {
90 r.logBegin(prettyName, nil)
91 }
92 if r.logProblems != nil {
93 r.logProblems(prettyName, nil, diags)
94 return nil // don't duplicate the diagnostics we already reported
95 }
96 return diags
97 }
98
99 if r.logBegin != nil {
100 r.logBegin(prettyName, tf)
101 }
102
103 basePath := filename[:len(filename)-2]
104 specFilename := basePath + ".hcldec"
105 nativeFilename := basePath + ".hcl"
106 jsonFilename := basePath + ".hcl.json"
107
108 // We'll add the source code of the spec file to our own parser, even
109 // though it'll actually be parsed by the hcldec child process, since that
110 // way we can produce nice diagnostic messages if hcldec fails to process
111 // the spec file.
112 src, err := os.ReadFile(specFilename)
113 if err == nil {
114 r.parser.AddFile(specFilename, &hcl.File{
115 Bytes: src,
116 })
117 }
118
119 if _, err := os.Stat(specFilename); err != nil {
120 diags = append(diags, &hcl.Diagnostic{
121 Severity: hcl.DiagError,
122 Summary: "Missing .hcldec file",
123 Detail: fmt.Sprintf("No specification file for test %s: %s.", prettyName, err),
124 })
125 return diags
126 }
127
128 if _, err := os.Stat(nativeFilename); err == nil {
129 moreDiags := r.runTestInput(specFilename, nativeFilename, tf)
130 diags = append(diags, moreDiags...)
131 }
132
133 if _, err := os.Stat(jsonFilename); err == nil {
134 moreDiags := r.runTestInput(specFilename, jsonFilename, tf)
135 diags = append(diags, moreDiags...)
136 }
137
138 if r.logProblems != nil {
139 r.logProblems(prettyName, nil, diags)
140 return nil // don't duplicate the diagnostics we already reported
141 }

Callers 1

runDirMethod · 0.95

Calls 5

prettyTestNameMethod · 0.95
LoadTestFileMethod · 0.95
runTestInputMethod · 0.95
HasErrorsMethod · 0.80
AddFileMethod · 0.80

Tested by

no test coverage detected