Skip to content

Commit

Permalink
print reports
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Nov 23, 2022
1 parent 806c358 commit 99b8868
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
26 changes: 23 additions & 3 deletions packages/patrol_cli/lib/src/features/drive/drive_command.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:ansi_styles/extension.dart';
import 'package:dispose_scope/dispose_scope.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:mason_logger/mason_logger.dart';
Expand Down Expand Up @@ -32,6 +33,8 @@ class DriveCommandConfig with _$DriveCommandConfig {
}) = _DriveCommandConfig;
}

const _defaultRepeats = 1;

class DriveCommand extends StagedCommand<DriveCommandConfig> {
DriveCommand({
required DeviceFinder deviceFinder,
Expand Down Expand Up @@ -114,7 +117,7 @@ class DriveCommand extends StagedCommand<DriveCommandConfig> {
'repeat',
abbr: 'n',
help: 'Repeat the test n times.',
defaultsTo: '1',
defaultsTo: '$_defaultRepeats',
);
}

Expand Down Expand Up @@ -175,9 +178,9 @@ class DriveCommand extends StagedCommand<DriveCommandConfig> {
throw const FormatException('`wait` argument is not an int');
}

var repeat = 1;
int repeat;
try {
final repeatStr = argResults?['repeat'] as String? ?? '1';
final repeatStr = argResults?['repeat'] as String? ?? '$_defaultRepeats';
repeat = int.parse(repeatStr);
} on FormatException {
throw const FormatException('`repeat` argument is not an int');
Expand All @@ -190,6 +193,7 @@ class DriveCommand extends StagedCommand<DriveCommandConfig> {
if (repeat != 1) {
_logger.info('Every test target will be run $repeat times');
}
print('repats $repeat');

final attachedDevices = await _deviceFinder.find(devices);

Expand Down Expand Up @@ -273,6 +277,22 @@ class DriveCommand extends StagedCommand<DriveCommandConfig> {
}

final results = await _testRunner.run();

for (final res in results.targetRunResults) {
if (res.allRunsPassed) {
_logger.write(
'${' PASS '.bgGreen.black.bold} ${res.targetName} on ${res.device.id}\n',
);
} else if (res.allTestFailed) {
_logger.write(
'${' FAIL '.bgRed.white.bold} ${res.targetName} on ${res.device.id}\n',
);
} else {
_logger.write(
'${' FLAK '.bgYellow.black.bold} ${res.targetName} on ${res.device.id}\n',
);
}
}
// TODO: present test results

final exitCode = results.allSuccessful ? 0 : 1;
Expand Down
19 changes: 19 additions & 0 deletions packages/patrol_cli/lib/src/features/drive/test_runner.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dispose_scope/dispose_scope.dart';
import 'package:equatable/equatable.dart';
import 'package:path/path.dart' show basename;
import 'package:patrol_cli/src/features/drive/device.dart';

typedef _Callback = Future<void> Function(String target, Device device);
Expand Down Expand Up @@ -28,6 +29,24 @@ class TargetRunResult with EquatableMixin {

final List<TargetRunStatus> runs;

String get targetName => basename(target);

bool get allRunsPassed => runs.every((run) => run == TargetRunStatus.passed);

bool get allTestFailed => runs.every((run) => run != TargetRunStatus.passed);

int get passedRuns {
return runs.where((run) => run == TargetRunStatus.passed).length;
}

int get runsFailedToBuild {
return runs.where((run) => run == TargetRunStatus.failedToBuild).length;
}

int get runsFailedToExecute {
return runs.where((run) => run == TargetRunStatus.failedToExecute).length;
}

@override
List<Object?> get props => [target, device, runs];

Expand Down

0 comments on commit 99b8868

Please sign in to comment.