run method

  1. @override
Future<void> run()
override

Runs this command.

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

Implementation

@override
Future<void> run() async {
  final shardIndex = argResults?.option('shard-index');
  final shardCount = argResults?.option('shard-count');
  final seed = argResults?.option('seed');
  final testPath = argResults?.option('test-path');

  if (shardIndex != null && !InputUtils.isNumericPositive(shardIndex)) {
    CliLogger.logError(
      'Invalid shard index. It should be a positive number. Please provide it via --shard-index option.',
    );
    return _exitWrapper.exit(1);
  }

  if (shardCount != null &&
      !InputUtils.isNumericGreaterThanZero(shardCount)) {
    CliLogger.logError(
      'Invalid shard count. It should be a number greater than 0. Please provide it via --shard-count option.',
    );
    return _exitWrapper.exit(1);
  }

  final shardIndexNumeric = int.tryParse(shardIndex ?? '');
  final shardCountNumeric = int.tryParse(shardCount ?? '') ?? 1;

  if (shardIndexNumeric != null && shardIndexNumeric >= shardCountNumeric) {
    CliLogger.logError(
      "Shard index can't be greater or equals than shard count.",
    );
    return _exitWrapper.exit(1);
  }

  if (seed != null && !InputUtils.isNumericPositive(seed)) {
    CliLogger.logError(
      'Invalid seed. It should be a positive number. Please provide it via --seed option.',
    );
    return _exitWrapper.exit(1);
  }

  if (testPath == null || testPath.isEmpty == true) {
    CliLogger.logError(
      'Invalid test path. Please provide it via --test-path option.',
    );
    return _exitWrapper.exit(1);
  }

  final seedNumeric = int.tryParse(seed ?? '');

  final result = await _testGroupInterferenceDetection.run(
    shardCount: shardCountNumeric,
    seed: seedNumeric,
    testPath: testPath,
    shardIndex: shardIndexNumeric,
  );

  if (result.interferenceFound) {
    return _exitWrapper.exit(result.interferenceFound ? 0 : 1);
  } else {
    return _exitWrapper.exit(1);
  }
}