run method

  1. @override
void run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
void run() async {
  final argMorphemeYaml = argResults.getOptionMorphemeYaml();

  final String? apps = argResults?['apps']?.toString().snakeCase;
  final String? feature = argResults?['feature']?.toString().snakeCase;
  final String? page = argResults?['page']?.toString().snakeCase;

  final argApps = apps != null ? '-a $apps' : '';
  final argFeature = feature != null ? '-f $feature' : '';
  final argPage = page != null ? '-p $page' : '';

  final String? reporter = argResults?['reporter'];
  final argReporter = reporter != null ? '--reporter $reporter' : '';

  final String? fileReporter = argResults?['file-reporter'];
  final argFileReporter =
      fileReporter != null ? '--file-reporter $fileReporter' : '';

  final command =
      'morpheme test --morpheme-yaml $argMorphemeYaml $argApps $argFeature $argPage --coverage $argReporter $argFileReporter';

  await command.run;

  YamlHelper.validateMorphemeYaml(argMorphemeYaml);
  final morphemeYaml = YamlHelper.loadFileYaml(argMorphemeYaml);

  if (!morphemeYaml.containsKey('coverage')) {
    StatusHelper.failed('morpheme.yaml not contain coverage config!');
  }

  if (Platform.isWindows) {
    printMessage(
        'you must install perl and lcov then lcov remove file will be ignore to coverage manually & generate report to html manually.');
  }

  if (which('lcov').notfound) {
    StatusHelper.failed(
        'lcov not found, failed to remove ignore file to test.');
  }

  final lcovDir = join(current, 'coverage', 'merge_lcov.info')
      .toString()
      .replaceAll('/', separator);
  final outputHtmlDir = morphemeYaml['coverage']['output_html_dir']
      ?.toString()
      .replaceAll('/', separator);
  final removeFile = (morphemeYaml['coverage']['remove'] as List).join(' ');

  printMessage(
      "lcov --remove $lcovDir $removeFile -o $lcovDir --ignore-errors unused");

  await "lcov --remove $lcovDir $removeFile -o $lcovDir --ignore-errors unused"
      .run;

  if (which('genhtml').notfound) {
    StatusHelper.failed('failed cannot generate report lcov html.');
  }
  await 'genhtml $lcovDir -o $outputHtmlDir'.run;

  StatusHelper.success('Coverage report generated to $outputHtmlDir');
}