dataCases function Null safety

Iterable<DataCase> dataCases(
  1. {required String directory,
  2. String extension = 'unit',
  3. bool recursive = true}

Parse and return data cases (each a DataCase) from directory.

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.


Iterable<DataCase> dataCases({
  required String directory,
  String extension = 'unit',
  bool recursive = true,
}) {
  var entries =
      Directory(directory).listSync(recursive: recursive, followLinks: false);
  var results = <DataCase>[];
  for (var entry in entries) {
    if (!entry.path.endsWith(extension)) {

    var relativeDir =
        p.relative(p.dirname(entry.path), from: p.dirname(directory));

    results.addAll(dataCasesInFile(path: entry.path, baseDir: relativeDir));

  // The API makes no guarantees on order. This is just here for stability in
  // tests.
  results.sort((a, b) {
    var compare =;
    if (compare != 0) return compare;

    return a.file.compareTo(b.file);
  return results;