dataCasesUnder function

Iterable<DataCase> dataCasesUnder({
  1. required Symbol library,
  2. String subdirectory = '',
  3. String extension = 'unit',
  4. bool recursive = true,
})

Parse and yield data cases (each a DataCase) from the directory containing library, optionally under subdirectory.

By default, only read data cases from files with a .unit extension. Data cases are read from files located immediately in directory, or recursively, according to recursive.

The typical use case of this method is to declare a library at the top of a Dart test file, then reference the symbol with a pound sign. Example:

library my_package.test.this_test;

import 'package:expected_output/expected_output.dart';
import 'package:test/test.dart';

void main() {
  for (var dataCase in dataCasesUnder(library: #my_package.test.this_test)) {
    // ...
  }
}

Implementation

Iterable<DataCase> dataCasesUnder({
  required Symbol library,
  String subdirectory = '',
  String extension = 'unit',
  bool recursive = true,
}) sync* {
  var directory = p.join(
      p.dirname(currentMirrorSystem().findLibrary(library).uri.toFilePath()),
      subdirectory);
  for (var dataCase in dataCases(
      directory: directory, extension: extension, recursive: recursive)) {
    yield dataCase;
  }
}