LCOV - code coverage report
Current view: top level - test_api-0.4.8/lib/src/backend - group.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 16 32 50.0 %
Date: 2021-11-28 14:37:50 Functions: 0 0 -

          Line data    Source code
       1             : // Copyright (c) 2015, the Dart project authors.  Please see the AUTHORS file
       2             : // for details. All rights reserved. Use of this source code is governed by a
       3             : // BSD-style license that can be found in the LICENSE file.
       4             : 
       5             : import 'package:stack_trace/stack_trace.dart';
       6             : 
       7             : import 'group_entry.dart';
       8             : import 'metadata.dart';
       9             : import 'suite_platform.dart';
      10             : import 'test.dart';
      11             : 
      12             : /// A group contains one or more tests and subgroups.
      13             : ///
      14             : /// It includes metadata that applies to all contained tests.
      15             : class Group implements GroupEntry {
      16             :   @override
      17             :   final String name;
      18             : 
      19             :   @override
      20             :   final Metadata metadata;
      21             : 
      22             :   @override
      23             :   final Trace? trace;
      24             : 
      25             :   /// The children of this group.
      26             :   final List<GroupEntry> entries;
      27             : 
      28             :   /// Returns a new root-level group.
      29           0 :   Group.root(Iterable<GroupEntry> entries, {Metadata? metadata})
      30           0 :       : this('', entries, metadata: metadata);
      31             : 
      32             :   /// A test to run before all tests in the group.
      33             :   ///
      34             :   /// This is `null` if no `setUpAll` callbacks were declared.
      35             :   final Test? setUpAll;
      36             : 
      37             :   /// A test to run after all tests in the group.
      38             :   ///
      39             :   /// This is `null` if no `tearDown` callbacks were declared.
      40             :   final Test? tearDownAll;
      41             : 
      42             :   /// The number of tests (recursively) in this group.
      43           0 :   int get testCount {
      44           0 :     if (_testCount != null) return _testCount!;
      45           0 :     _testCount = entries.fold<int>(
      46           0 :         0, (count, entry) => count + (entry is Group ? entry.testCount : 1));
      47           0 :     return _testCount!;
      48             :   }
      49             : 
      50             :   int? _testCount;
      51             : 
      52          11 :   Group(this.name, Iterable<GroupEntry> entries,
      53             :       {Metadata? metadata, this.trace, this.setUpAll, this.tearDownAll})
      54          11 :       : entries = List<GroupEntry>.unmodifiable(entries),
      55           0 :         metadata = metadata ?? Metadata();
      56             : 
      57          11 :   @override
      58             :   Group? forPlatform(SuitePlatform platform) {
      59          33 :     if (!metadata.testOn.evaluate(platform)) return null;
      60          22 :     var newMetadata = metadata.forPlatform(platform);
      61          33 :     var filtered = _map((entry) => entry.forPlatform(platform));
      62          11 :     if (filtered.isEmpty && entries.isNotEmpty) return null;
      63          22 :     return Group(name, filtered,
      64             :         metadata: newMetadata,
      65          11 :         trace: trace,
      66          11 :         setUpAll: setUpAll,
      67          11 :         tearDownAll: tearDownAll);
      68             :   }
      69             : 
      70           0 :   @override
      71             :   Group? filter(bool Function(Test) callback) {
      72           0 :     var filtered = _map((entry) => entry.filter(callback));
      73           0 :     if (filtered.isEmpty && entries.isNotEmpty) return null;
      74           0 :     return Group(name, filtered,
      75           0 :         metadata: metadata,
      76           0 :         trace: trace,
      77           0 :         setUpAll: setUpAll,
      78           0 :         tearDownAll: tearDownAll);
      79             :   }
      80             : 
      81             :   /// Returns the entries of this group mapped using [callback].
      82             :   ///
      83             :   /// Any `null` values returned by [callback] will be removed.
      84          11 :   List<GroupEntry> _map(GroupEntry? Function(GroupEntry) callback) {
      85          11 :     return entries
      86          22 :         .map((entry) => callback(entry))
      87          11 :         .whereType<GroupEntry>()
      88          11 :         .toList();
      89             :   }
      90             : }

Generated by: LCOV version 1.14