| 36 | } |
| 37 | |
| 38 | func (r *Runner) runDir(dir string) hcl.Diagnostics { |
| 39 | var diags hcl.Diagnostics |
| 40 | |
| 41 | infos, err := os.ReadDir(dir) |
| 42 | if err != nil { |
| 43 | diags = append(diags, &hcl.Diagnostic{ |
| 44 | Severity: hcl.DiagError, |
| 45 | Summary: "Failed to read test directory", |
| 46 | Detail: fmt.Sprintf("The directory %q could not be opened: %s.", dir, err), |
| 47 | }) |
| 48 | return diags |
| 49 | } |
| 50 | |
| 51 | var tests []string |
| 52 | var subDirs []string |
| 53 | for _, info := range infos { |
| 54 | name := info.Name() |
| 55 | if strings.HasPrefix(name, ".") { |
| 56 | continue |
| 57 | } |
| 58 | |
| 59 | if info.IsDir() { |
| 60 | subDirs = append(subDirs, name) |
| 61 | } |
| 62 | if strings.HasSuffix(name, ".t") { |
| 63 | tests = append(tests, name) |
| 64 | } |
| 65 | } |
| 66 | sort.Strings(tests) |
| 67 | sort.Strings(subDirs) |
| 68 | |
| 69 | for _, filename := range tests { |
| 70 | filename = filepath.Join(dir, filename) |
| 71 | testDiags := r.runTest(filename) |
| 72 | diags = append(diags, testDiags...) |
| 73 | } |
| 74 | |
| 75 | for _, dirName := range subDirs { |
| 76 | dir := filepath.Join(dir, dirName) |
| 77 | dirDiags := r.runDir(dir) |
| 78 | diags = append(diags, dirDiags...) |
| 79 | } |
| 80 | |
| 81 | return diags |
| 82 | } |
| 83 | |
| 84 | func (r *Runner) runTest(filename string) hcl.Diagnostics { |
| 85 | prettyName := r.prettyTestName(filename) |