TestFailureDetails.fromMessage constructor

TestFailureDetails.fromMessage(
  1. String text, {
  2. String? phase,
  3. Map<String, dynamic> target = const {},
})

Best-effort structured kind from a free-form failure message.

Implementation

factory TestFailureDetails.fromMessage(
  String text, {
  String? phase,
  Map<String, dynamic> target = const {},
}) {
  final lower = text.toLowerCase();
  final TestFailureKind kind;
  if (lower.contains('ambiguous')) {
    kind = TestFailureKind.ambiguousTarget;
  } else if (lower.contains('not found') ||
      lower.contains('could not find') ||
      lower.contains('missing')) {
    kind = TestFailureKind.elementNotFound;
  } else if (lower.contains('capability') ||
      lower.contains('unavailable') ||
      lower.contains('unsupported')) {
    kind = TestFailureKind.unsupportedCapability;
  } else if (lower.contains('crash') || lower.contains('application error')) {
    kind = TestFailureKind.crash;
  } else if (lower.contains('cleanup') || lower.contains('teardown')) {
    kind = TestFailureKind.cleanup;
  } else if (lower.contains('bootstrap') || lower.contains('launch')) {
    kind = TestFailureKind.bootstrap;
  } else if (lower.contains('incomplete') || lower.contains('transport')) {
    kind = TestFailureKind.incompleteExecution;
  } else {
    kind = TestFailureKind.assertion;
  }
  return TestFailureDetails(
    kind: kind,
    message: text,
    phase: phase,
    target: target,
  );
}