Metadata constructor

Metadata({
  1. PlatformSelector? testOn,
  2. Timeout? timeout,
  3. bool? skip,
  4. bool? verboseTrace,
  5. bool? chainStackTraces,
  6. int? retry,
  7. String? skipReason,
  8. Iterable<String>? tags,
  9. Map<PlatformSelector, Metadata>? onPlatform,
  10. Map<BooleanSelector, Metadata>? forTag,
  11. String? languageVersionComment,
})

Creates new Metadata.

testOn defaults to PlatformSelector.all.

If forTag contains metadata that applies to tags, that metadata is included inline in the returned value. The values directly passed to the constructor take precedence over tag-specific metadata.

Implementation

factory Metadata(
    {PlatformSelector? testOn,
    Timeout? timeout,
    bool? skip,
    bool? verboseTrace,
    bool? chainStackTraces,
    int? retry,
    String? skipReason,
    Iterable<String>? tags,
    Map<PlatformSelector, Metadata>? onPlatform,
    Map<BooleanSelector, Metadata>? forTag,
    String? languageVersionComment}) {
  // Returns metadata without forTag resolved at all.
  Metadata unresolved() => Metadata._(
      testOn: testOn,
      timeout: timeout,
      skip: skip,
      verboseTrace: verboseTrace,
      chainStackTraces: chainStackTraces,
      retry: retry,
      skipReason: skipReason,
      tags: tags,
      onPlatform: onPlatform,
      forTag: forTag,
      languageVersionComment: languageVersionComment);

  // If there's no tag-specific metadata, or if none of it applies, just
  // return the metadata as-is.
  if (forTag == null || tags == null) return unresolved();
  tags = Set.from(tags);
  forTag = Map.from(forTag);

  // Otherwise, resolve the tag-specific components. Doing this eagerly means
  // we only have to resolve suite- or group-level tags once, rather than
  // doing it for every test individually.
  var empty = Metadata._();
  var merged = forTag.keys.toList().fold(empty, (Metadata merged, selector) {
    if (!selector.evaluate(tags!.contains)) return merged;
    return merged.merge(forTag!.remove(selector)!);
  });

  if (merged == empty) return unresolved();
  return merged.merge(unresolved());
}