judgeSetup function

({TestedSetup? closest, TestedSetup? match, SetupStatus status}) judgeSetup(
  1. DeviceSetup setup, {
  2. List<TestedSetup> known = testedSetups,
})

How setup compares with testedSetups: its status, the matching entry, and the closest proven one when it has none.

Implementation

({SetupStatus status, TestedSetup? match, TestedSetup? closest}) judgeSetup(DeviceSetup setup,
    {List<TestedSetup> known = testedSetups}) {
  final same = known
      .where((t) => t.platform == setup.platform && t.backend == setup.backend && t.runtimeMajor == setup.runtimeMajor);
  final exact = same
      .where((t) => setup.platform != 'ios' || (t.xcodeMajor == setup.xcodeMajor && t.hostMajor == setup.hostMajor));
  if (exact.isNotEmpty) {
    return (status: exact.first.status, match: exact.first, closest: null);
  }
  final pool = same.isNotEmpty ? same : known.where((t) => t.platform == setup.platform && t.backend == setup.backend);
  TestedSetup? closest;
  for (final t in pool) {
    if (closest == null || (t.status.index < closest.status.index)) closest = t;
  }
  return (status: SetupStatus.untested, match: null, closest: closest);
}