printMatrixPlan function

Future<int> printMatrixPlan(
  1. List<SmfModule> modules,
  2. List<String> options, {
  3. Role<Object>? native,
  4. void out(
    1. String line
    )?,
  5. void err(
    1. String line
    )?,
})

Prints the plan of modules (see matrixPlanOf) as one line of JSON, for --plan of a matrix tool with options, which may be --every-combination, and returns the exit code: 0; 1, when the cases of the contract harness failed, with their problems instead; and 64, with the usage, for other options. out gets the plan, by default the standard output, and err the problems and the usage, by default the standard error.

Implementation

Future<int> printMatrixPlan(
  List<SmfModule> modules,
  List<String> options, {
  Role? native,
  void Function(String line)? out,
  void Function(String line)? err,
}) async {
  // coverage:ignore-start
  // The defaults print to the terminal, as the jobs of CI read it; the
  // tests give their own.
  final printOut = out ?? _stdout;
  final printErr = err ?? _stderr;
  // coverage:ignore-end
  final everyCombination = switch (options) {
    [] => false,
    ['--every-combination'] => true,
    _ => null,
  };
  if (everyCombination == null) {
    printErr(
      'Usage: dart run tool/matrix.dart --plan [--every-combination]\n'
      'Prints, as one line of JSON, the plan of the jobs of CI that check '
      'the matrix: a pairwise covering of the apps with every module, or, '
      'with --every-combination, all of them up to $maxEveryCombination and '
      'a 3-wise covering of more.',
    );
    return 64;
  }
  final (:plan, :problems) = await matrixPlanOf(
    modules,
    everyCombination: everyCombination,
    native: native,
  );
  if (problems.isNotEmpty) {
    printErr('Problems:');
    problems.forEach(printErr);
    return 1;
  }
  printOut(jsonEncode(plan));
  return 0;
}