(filename string)
| 82 | } |
| 83 | |
| 84 | func (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 | } |
no test coverage detected