validateReport function

String validateReport(
  1. Program program
)

The report printed by ball validate <input.ball.json> (no trailing newline). On the valid path this is the Valid: … block; on the invalid path the Invalid: … block. The native verb routes it to stdout/stderr and picks the exit code via validateOk.

Implementation

String validateReport(Program program) {
  final errors = validationErrors(program);
  if (errors.isEmpty) {
    var totalFns = 0;
    for (final m in program.modules) {
      totalFns += m.functions.length;
    }
    return 'Valid: "${program.name}" v${program.version}\n'
        '  ${program.modules.length} modules, $totalFns functions';
  }

  final lines = <String>[];
  lines.add('Invalid: ${errors.length} error(s) found');
  for (final e in errors) {
    lines.add('  - $e');
  }
  return lines.join('\n');
}