createDartTestGroup function

  1. @internal
DartGroupEntry createDartTestGroup(
  1. Group parentGroup, {
  2. String name = '',
  3. int level = 0,
  4. int maxTestCaseLength = global_state.maxTestLength,
})

Creates a DartGroupEntry by visiting the subgroups of parentGroup.

The initial parentGroup is the implicit, unnamed top-level Group present in every test case.

Implementation

@internal
DartGroupEntry createDartTestGroup(
  Group parentGroup, {
  String name = '',
  int level = 0,
  int maxTestCaseLength = global_state.maxTestLength,
}) {
  final groupDTO = DartGroupEntry(
    name: name,
    type: GroupEntryType.group,
    entries: [],
  );

  for (final entry in parentGroup.entries) {
    // Trim names of current groups

    var name = entry.name;
    if (parentGroup.name.isNotEmpty) {
      // Assume that parentGroupName fits maxTestCaseLength
      // Assume that after cropping, test names are different.

      if (name.length > maxTestCaseLength) {
        name = name.substring(0, maxTestCaseLength);
      }

      name = deduplicateGroupEntryName(parentGroup.name, name);
    }

    if (entry is Group) {
      groupDTO.entries.add(
        createDartTestGroup(
          entry,
          name: name,
          level: level + 1,
          maxTestCaseLength: maxTestCaseLength,
        ),
      );
    } else if (entry is Test) {
      if (entry.name == 'patrol_test_explorer') {
        // Ignore the bogus test that is used to discover the test structure.
        continue;
      }

      if (level < 1) {
        throw StateError('Test is not allowed to be defined at level $level');
      }

      groupDTO.entries.add(
        DartGroupEntry(name: name, type: GroupEntryType.test, entries: []),
      );
    } else {
      // This should really never happen, because Group and Test are the only
      // subclasses of GroupEntry.
      throw StateError('invalid state');
    }
  }

  return groupDTO;
}