Load walks the file tree rooted at the current working directory, looking for Markdown files containing tests. Any file whose name ends with ".md" is considered a Markdown file. Files containing no tests are ignored.
()
| 98 | // Markdown files containing tests. Any file whose name ends with ".md" is |
| 99 | // considered a Markdown file. Files containing no tests are ignored. |
| 100 | func Load() ([]*File, error) { |
| 101 | var files []*File |
| 102 | err := filepath.WalkDir(".", func(path string, d fs.DirEntry, err error) error { |
| 103 | if err != nil || d.IsDir() || !strings.HasSuffix(path, ".md") { |
| 104 | return err |
| 105 | } |
| 106 | b, err := os.ReadFile(path) |
| 107 | if err != nil { |
| 108 | return err |
| 109 | } |
| 110 | inputs, tests, err := parseMarkdown(b) |
| 111 | if err != nil { |
| 112 | var le lineError |
| 113 | if errors.As(err, &le) { |
| 114 | return fmt.Errorf("%s:%d: %s", path, le.line, le.msg) |
| 115 | } |
| 116 | return fmt.Errorf("%s: %w", path, err) |
| 117 | } |
| 118 | if len(tests) > 0 { |
| 119 | files = append(files, &File{ |
| 120 | Path: path, |
| 121 | Inputs: inputs, |
| 122 | Tests: tests, |
| 123 | }) |
| 124 | } |
| 125 | return nil |
| 126 | }) |
| 127 | return files, err |
| 128 | } |
| 129 | |
| 130 | // Run runs the file's tests. It runs relative-directory-style tests (Test.Dir |
| 131 | // != "") in parallel, with the shell working directory set to Test.Dir, and it |