byName method

List<TestStep> byName(
  1. String spec
)

Looks up tests by partial id. Accepted forms:

  • name → any test whose name equals name
  • pkg:name → restricted to pkg
  • pkg:g1/g2/name → fully qualified
  • g1/.../name → restricted by group chain in any package

Returns every match. Throws if nothing matches.

Implementation

List<TestStep> byName(String spec) {
  final colon = spec.indexOf(':');
  final String? pkg;
  final String tail;
  if (colon == -1) {
    pkg = null;
    tail = spec;
  } else {
    pkg = spec.substring(0, colon);
    tail = spec.substring(colon + 1);
  }
  final slash = tail.lastIndexOf('/');
  final List<String> groupChain;
  final String name;
  if (slash == -1) {
    groupChain = const [];
    name = tail;
  } else {
    groupChain = tail.substring(0, slash).split('/');
    name = tail.substring(slash + 1);
  }

  final matches = _tests.where((t) {
    if (pkg != null && t.packageName != pkg) return false;
    if (groupChain.isNotEmpty && !_listEquals(t.groupChain, groupChain)) {
      return false;
    }
    return t.name == name;
  }).toList();

  if (matches.isEmpty) {
    throw StateError(
      'testeador: no captured test matches "$spec". '
      'Known names sample: ${_sampleNames()}.',
    );
  }
  return matches.map((t) => t.toStep()).toList();
}