Skip to content

Commit

Permalink
adapt Dart side to DartGroupEntry
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekpacia committed Aug 15, 2023
1 parent ce6cffc commit c74539b
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 32 deletions.
31 changes: 19 additions & 12 deletions packages/patrol/lib/src/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,20 @@ if you use nativeAutomation with false, we recommend using patrolWidgetTest()'''
);
}

/// Creates a DartTestGroup by visiting the subgroups of [parentGroup].
/// Creates a DartGroupEntry by visiting the subgroups of [parentGroup].
///
/// The initial [parentGroup] is the implicit, unnamed top-level [Group] present
/// in every test case.
@internal
DartTestGroup createDartTestGroup(
DartGroupEntry createDartTestGroup(
Group parentGroup, {
String name = '',
int level = 0,
}) {
final groupDTO = DartTestGroup(name: name);
final groupDTO = DartGroupEntry(
name: name,
type: DartGroupEntry_GroupEntryType.GROUP,
);

for (final entry in parentGroup.entries) {
// Trim names of current groups
Expand All @@ -178,7 +181,7 @@ DartTestGroup createDartTestGroup(
}

if (entry is Group) {
groupDTO.groups.add(
groupDTO.entries.add(
createDartTestGroup(
entry,
name: name,
Expand All @@ -196,7 +199,9 @@ DartTestGroup createDartTestGroup(
throw StateError('Test is not allowed to be defined at level $level');
}

groupDTO.tests.add(DartTestCase(name: name));
groupDTO.entries.add(
DartGroupEntry(name: name, type: DartGroupEntry_GroupEntryType.TEST),
);
} else {
// This should really never happen, because Group and Test are the only
// subclasses of GroupEntry.
Expand All @@ -216,15 +221,17 @@ String deduplicateGroupEntryName(String parentName, String currentName) {
);
}

void printGroupStructure(DartTestGroup group, int indentation) {
void printGroupStructure(DartGroupEntry group, int indentation) {
final indent = ' ' * indentation;
print("$indent-- group: '${group.name}'");

for (final testCase in group.tests) {
print("$indent -- test: '${testCase.name}'");
}

for (final subgroup in group.groups) {
printGroupStructure(subgroup, indentation + 5);
for (final entry in group.entries) {
if (entry.type == DartGroupEntry_GroupEntryType.TEST) {
print("$indent -- test: '${entry.name}'");
} else {
for (final subgroup in entry.entries) {
printGroupStructure(subgroup, indentation + 5);
}
}
}
}
2 changes: 1 addition & 1 deletion packages/patrol/lib/src/native/patrol_app_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PatrolAppService extends PatrolAppServiceBase {

/// The ambient test group that wraps all the other groups and tests in the
/// bundled Dart test file.
final DartTestGroup topLevelDartTestGroup;
final DartGroupEntry topLevelDartTestGroup;

/// A completer that completes with the name of the Dart test file that was
/// requested to execute by the native side.
Expand Down
110 changes: 92 additions & 18 deletions packages/patrol/test/internals_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import 'package:test_api/src/backend/group.dart';
import 'package:test_api/src/backend/invoker.dart';
import 'package:test_api/src/backend/metadata.dart';

typedef GroupEntryType = DartGroupEntry_GroupEntryType;

void main() {
group('createDartTestGroup()', () {
test('fails if a test is defined at top-level', () {
Expand All @@ -20,7 +22,7 @@ void main() {
]);

// when
DartTestGroup callback() => createDartTestGroup(topLevelGroup);
DartGroupEntry callback() => createDartTestGroup(topLevelGroup);

// then
expect(
Expand All @@ -29,7 +31,7 @@ void main() {
);
});

test('smoke test', () {
test('smoke test 1', () {
// given
final topLevelGroup = Group.root([
LocalTest('patrol_test_explorer', Metadata.empty, () {}),
Expand Down Expand Up @@ -59,33 +61,105 @@ void main() {
expect(
dartTestGroup,
equals(
DartTestGroup(
DartGroupEntry(
name: '',
groups: [
DartTestGroup(
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(
name: 'example_test',
groups: [
DartTestGroup(
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(
name: 'alpha',
tests: [
DartTestCase(name: 'first'),
DartTestCase(name: 'second')
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(name: 'first', type: GroupEntryType.TEST),
DartGroupEntry(name: 'second', type: GroupEntryType.TEST),
],
),
DartTestGroup(
DartGroupEntry(
name: 'bravo',
tests: [
DartTestCase(name: 'first'),
DartTestCase(name: 'second'),
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(name: 'first', type: GroupEntryType.TEST),
DartGroupEntry(name: 'second', type: GroupEntryType.TEST),
],
),
],
),
DartTestGroup(
DartGroupEntry(
name: 'open_app_test',
tests: [
DartTestCase(name: 'open maps'),
DartTestCase(name: 'open browser'),
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(name: 'open maps', type: GroupEntryType.TEST),
DartGroupEntry(
name: 'open browser',
type: GroupEntryType.TEST,
),
],
),
],
),
),
);
});

test('smoke test 2', () {
// given
final topLevelGroup = Group.root([
LocalTest('patrol_test_explorer', Metadata.empty, () {}),
Group(
'example_test',
[
_localTest('example_test alpha'),
Group('example_test bravo', [
_localTest('example_test bravo first'),
_localTest('example_test bravo second'),
]),
_localTest('example_test charlie'),
Group('example_test delta', [
_localTest('example_test delta first'),
_localTest('example_test delta second'),
]),
_localTest('example_test echo'),
],
),
]);

// when
final dartTestGroup = createDartTestGroup(topLevelGroup);

// then
expect(
dartTestGroup,
equals(
DartGroupEntry(
name: '',
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(
name: 'example_test',
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(name: 'alpha', type: GroupEntryType.TEST),
DartGroupEntry(
name: 'bravo',
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(name: 'first', type: GroupEntryType.TEST),
DartGroupEntry(name: 'second', type: GroupEntryType.TEST),
],
),
DartGroupEntry(name: 'charlie', type: GroupEntryType.TEST),
DartGroupEntry(
name: 'delta',
type: GroupEntryType.GROUP,
entries: [
DartGroupEntry(name: 'first', type: GroupEntryType.TEST),
DartGroupEntry(name: 'second', type: GroupEntryType.TEST),
],
),
DartGroupEntry(name: 'echo', type: GroupEntryType.TEST),
],
),
],
Expand Down
2 changes: 1 addition & 1 deletion packages/patrol_cli/lib/src/test_bundler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Future<void> main() async {
final nativeAutomator = NativeAutomator(config: NativeAutomatorConfig());
await nativeAutomator.initialize();
final binding = PatrolBinding.ensureInitialized();
final testExplorationCompleter = Completer<DartTestGroup>();
final testExplorationCompleter = Completer<DartGroupEntry>();
// A special test to expore the hierarchy of groups and tests. This is a hack
// around https://github.com/dart-lang/test/issues/1998.
Expand Down

0 comments on commit c74539b

Please sign in to comment.