(specFilename, inputFilename string, tf *TestFile)
| 144 | } |
| 145 | |
| 146 | func (r *Runner) runTestInput(specFilename, inputFilename string, tf *TestFile) hcl.Diagnostics { |
| 147 | // We'll add the source code of the input file to our own parser, even |
| 148 | // though it'll actually be parsed by the hcldec child process, since that |
| 149 | // way we can produce nice diagnostic messages if hcldec fails to process |
| 150 | // the input file. |
| 151 | src, err := os.ReadFile(inputFilename) |
| 152 | if err == nil { |
| 153 | r.parser.AddFile(inputFilename, &hcl.File{ |
| 154 | Bytes: src, |
| 155 | }) |
| 156 | } |
| 157 | |
| 158 | var diags hcl.Diagnostics |
| 159 | |
| 160 | if tf.ChecksTraversals { |
| 161 | gotTraversals, moreDiags := r.hcldecVariables(specFilename, inputFilename) |
| 162 | diags = append(diags, moreDiags...) |
| 163 | if !moreDiags.HasErrors() { |
| 164 | expected := tf.ExpectedTraversals |
| 165 | for _, got := range gotTraversals { |
| 166 | e := findTraversalSpec(got, expected) |
| 167 | rng := got.SourceRange() |
| 168 | if e == nil { |
| 169 | diags = append(diags, &hcl.Diagnostic{ |
| 170 | Severity: hcl.DiagError, |
| 171 | Summary: "Unexpected traversal", |
| 172 | Detail: "Detected traversal that is not indicated as expected in the test file.", |
| 173 | Subject: &rng, |
| 174 | }) |
| 175 | } else { |
| 176 | moreDiags := checkTraversalsMatch(got, inputFilename, e) |
| 177 | diags = append(diags, moreDiags...) |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Look for any traversals that didn't show up at all. |
| 182 | for _, e := range expected { |
| 183 | if t := findTraversalForSpec(e, gotTraversals); t == nil { |
| 184 | diags = append(diags, &hcl.Diagnostic{ |
| 185 | Severity: hcl.DiagError, |
| 186 | Summary: "Missing expected traversal", |
| 187 | Detail: "This expected traversal was not detected.", |
| 188 | Subject: e.Traversal.SourceRange().Ptr(), |
| 189 | }) |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | } |
| 195 | |
| 196 | val, transformDiags := r.hcldecTransform(specFilename, inputFilename) |
| 197 | if len(tf.ExpectedDiags) == 0 { |
| 198 | diags = append(diags, transformDiags...) |
| 199 | if transformDiags.HasErrors() { |
| 200 | // If hcldec failed then there's no point in continuing. |
| 201 | return diags |
| 202 | } |
| 203 |
no test coverage detected