|
6 | 6 | // simply running "go test" compared replicating the test using "go run". |
7 | 7 | // Script-style tests don't have this convenience. |
8 | 8 | // |
| 9 | +// Ztests are specified in YAML files. Multiple ztests can be specified in a |
| 10 | +// single file by separating them with a line containing three dashes ("---"). |
| 11 | +// |
9 | 12 | // In the SPQ style, ztest runs a SuperSQL program on an input and checks |
10 | 13 | // for an expected output. |
11 | 14 | // |
12 | | -// A SPQ-style test is defined in a YAML file. |
13 | | -// |
14 | 15 | // spq: count() |
15 | 16 | // |
16 | 17 | // input: | |
@@ -171,8 +172,15 @@ func Load(dirname string) ([]Bundle, error) { |
171 | 172 | } |
172 | 173 | testname := strings.TrimSuffix(filename, dotyaml) |
173 | 174 | filename = filepath.Join(dirname, filename) |
174 | | - zt, err := FromYAMLFile(filename) |
175 | | - bundles = append(bundles, Bundle{testname, filename, zt, err}) |
| 175 | + zts, err := FromYAMLFile(filename) |
| 176 | + if err != nil { |
| 177 | + bundles = append(bundles, Bundle{testname, filename, nil, err}) |
| 178 | + continue |
| 179 | + } |
| 180 | + for _, zt := range zts { |
| 181 | + testname := fmt.Sprintf("%s/%d", testname, zt.Line) |
| 182 | + bundles = append(bundles, Bundle{testname, filename, zt, nil}) |
| 183 | + } |
176 | 184 | } |
177 | 185 | return bundles, nil |
178 | 186 | } |
@@ -254,6 +262,7 @@ func (f *File) load(dir string) ([]byte, *regexp.Regexp, error) { |
254 | 262 |
|
255 | 263 | // ZTest defines a ztest. |
256 | 264 | type ZTest struct { |
| 265 | + Line int `yaml:"-"` |
257 | 266 | Skip string `yaml:"skip,omitempty"` |
258 | 267 | Tag string `yaml:"tag,omitempty"` |
259 | 268 |
|
@@ -297,20 +306,27 @@ func (z *ZTest) check() error { |
297 | 306 | return nil |
298 | 307 | } |
299 | 308 |
|
300 | | -// FromYAMLFile loads a ZTest from the YAML file named filename. |
301 | | -func FromYAMLFile(filename string) (*ZTest, error) { |
302 | | - f, err := yamlparser.ParseFile(filename, 0) |
| 309 | +// FromYAMLFile loads ztests from the named YAML file. |
| 310 | +func FromYAMLFile(name string) ([]*ZTest, error) { |
| 311 | + f, err := yamlparser.ParseFile(name, 0) |
303 | 312 | if err != nil { |
304 | 313 | return nil, err |
305 | 314 | } |
306 | | - if len(f.Docs) != 1 { |
307 | | - return nil, errors.New("file must contain one YAML document") |
308 | | - } |
309 | | - var z ZTest |
310 | | - if err := yaml.NodeToValue(f.Docs[0].Body, &z, yaml.DisallowUnknownField()); err != nil { |
311 | | - return nil, err |
| 315 | + var zs []*ZTest |
| 316 | + for _, d := range f.Docs { |
| 317 | + var z ZTest |
| 318 | + if err := yaml.NodeToValue(d.Body, &z, yaml.DisallowUnknownField()); err != nil { |
| 319 | + return nil, err |
| 320 | + } |
| 321 | + if s := d.Start; s != nil { |
| 322 | + // s is a YAML directives end marker ("---"). |
| 323 | + z.Line = s.Position.Line + 1 |
| 324 | + } else { |
| 325 | + z.Line = 1 |
| 326 | + } |
| 327 | + zs = append(zs, &z) |
312 | 328 | } |
313 | | - return &z, nil |
| 329 | + return zs, nil |
314 | 330 | } |
315 | 331 |
|
316 | 332 | func (z *ZTest) ShouldSkip(path string) string { |
@@ -392,7 +408,7 @@ func (z *ZTest) Run(t *testing.T, path, filename string) { |
392 | 408 | err = z.RunInternal(t.Context()) |
393 | 409 | } |
394 | 410 | if err != nil { |
395 | | - t.Fatalf("%s: %s", filename, err) |
| 411 | + t.Fatalf("%s:%d: %s", filename, z.Line, err) |
396 | 412 | } |
397 | 413 | } |
398 | 414 |
|
|
0 commit comments