LCOV - code coverage report
Current view: top level - test-0.12.24+8/lib/src/backend - group.dart (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 14 26 53.8 %
Date: 2017-10-10 20:17:03 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 'operating_system.dart';
      10             : import 'test.dart';
      11             : import 'test_platform.dart';
      12             : 
      13             : /// A group contains one or more tests and subgroups.
      14             : ///
      15             : /// It includes metadata that applies to all contained tests.
      16             : class Group implements GroupEntry {
      17             :   final String name;
      18             : 
      19             :   final Metadata metadata;
      20             : 
      21             :   final Trace trace;
      22             : 
      23             :   /// The children of this group.
      24             :   final List<GroupEntry> entries;
      25             : 
      26             :   /// Returns a new root-level group.
      27             :   Group.root(Iterable<GroupEntry> entries, {Metadata metadata})
      28           0 :       : this(null, entries, metadata: metadata);
      29             : 
      30             :   /// A test to run before all tests in the group.
      31             :   ///
      32             :   /// This is `null` if no `setUpAll` callbacks were declared.
      33             :   final Test setUpAll;
      34             : 
      35             :   /// A test to run after all tests in the group.
      36             :   ///
      37             :   /// This is `null` if no `tearDown` callbacks were declared.
      38             :   final Test tearDownAll;
      39             : 
      40             :   /// The number of tests (recursively) in this group.
      41             :   int get testCount {
      42           0 :     if (_testCount != null) return _testCount;
      43           0 :     _testCount = entries.fold(
      44           0 :         0, (count, entry) => count + (entry is Group ? entry.testCount : 1));
      45           0 :     return _testCount;
      46             :   }
      47             : 
      48             :   int _testCount;
      49             : 
      50             :   Group(this.name, Iterable<GroupEntry> entries,
      51             :       {Metadata metadata, this.trace, this.setUpAll, this.tearDownAll})
      52           5 :       : entries = new List<GroupEntry>.unmodifiable(entries),
      53           5 :         metadata = metadata == null ? new Metadata() : metadata;
      54             : 
      55             :   Group forPlatform(TestPlatform platform, {OperatingSystem os}) {
      56          15 :     if (!metadata.testOn.evaluate(platform, os: os)) return null;
      57          10 :     var newMetadata = metadata.forPlatform(platform, os: os);
      58          10 :     var filtered = _map((entry) => entry.forPlatform(platform, os: os));
      59           5 :     if (filtered.isEmpty && entries.isNotEmpty) return null;
      60          10 :     return new Group(name, filtered,
      61             :         metadata: newMetadata,
      62           5 :         trace: trace,
      63           5 :         setUpAll: setUpAll,
      64           5 :         tearDownAll: tearDownAll);
      65             :   }
      66             : 
      67             :   Group filter(bool callback(Test test)) {
      68           0 :     var filtered = _map((entry) => entry.filter(callback));
      69           0 :     if (filtered.isEmpty && entries.isNotEmpty) return null;
      70           0 :     return new Group(name, filtered,
      71           0 :         metadata: metadata,
      72           0 :         trace: trace,
      73           0 :         setUpAll: setUpAll,
      74           0 :         tearDownAll: tearDownAll);
      75             :   }
      76             : 
      77             :   /// Returns the entries of this group mapped using [callback].
      78             :   ///
      79             :   /// Any `null` values returned by [callback] will be removed.
      80             :   List<GroupEntry> _map(GroupEntry callback(GroupEntry entry)) {
      81           5 :     return entries
      82          10 :         .map((entry) => callback(entry))
      83           5 :         .where((entry) => entry != null)
      84           5 :         .toList();
      85             :   }
      86             : }

Generated by: LCOV version 1.13