currentProjectName function
The pubspec name of the package the tests belong to, for labelling.
Walks up from from to the nearest pubspec. Returns empty rather than
throwing: a missing name makes rig ls less informative, which is not
worth failing a test run over.
Implementation
String currentProjectName({Directory? from}) {
var dir = from ?? Directory.current;
while (true) {
final pubspec = File(p.join(dir.path, 'pubspec.yaml'));
if (pubspec.existsSync()) {
final name = _readName(pubspec);
if (name != null) return name;
}
final parent = dir.parent;
if (parent.path == dir.path) return '';
dir = parent;
}
}