LCOV - code coverage report
Current view: top level - test_api-0.4.8/lib/src/backend - state.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 5 30 16.7 %
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             : /// The state of a [LiveTest].
       6             : ///
       7             : /// A test's state is made up of two components, its [status] and its [result].
       8             : /// The [status] represents where the test is in its process of running; the
       9             : /// [result] represents the outcome as far as its known.
      10             : class State {
      11             :   /// Where the test is in its process of running.
      12             :   final Status status;
      13             : 
      14             :   /// The outcome of the test, as far as it's known.
      15             :   ///
      16             :   /// Note that if [status] is [Status.pending], [result] will always be
      17             :   /// [Result.success] since the test hasn't yet had a chance to fail.
      18             :   final Result result;
      19             : 
      20             :   /// Whether a test in this state is expected to be done running code.
      21             :   ///
      22             :   /// If [status] is [Status.complete] and [result] doesn't indicate an error, a
      23             :   /// properly-written test case should not be running any more code. However,
      24             :   /// it may have started asynchronous processes without notifying the test
      25             :   /// runner.
      26           0 :   bool get shouldBeDone => status == Status.complete && result.isPassing;
      27             : 
      28          44 :   const State(this.status, this.result);
      29             : 
      30          11 :   @override
      31             :   bool operator ==(other) =>
      32          44 :       other is State && status == other.status && result == other.result;
      33             : 
      34           0 :   @override
      35           0 :   int get hashCode => status.hashCode ^ (7 * result.hashCode);
      36             : 
      37           0 :   @override
      38             :   String toString() {
      39           0 :     if (status == Status.pending) return 'pending';
      40           0 :     if (status == Status.complete) return result.toString();
      41           0 :     if (result == Result.success) return 'running';
      42           0 :     return 'running with $result';
      43             :   }
      44             : }
      45             : 
      46             : /// Where the test is in its process of running.
      47             : class Status {
      48             :   /// The test has not yet begun running.
      49             :   static const pending = Status._('pending');
      50             : 
      51             :   /// The test is currently running.
      52             :   static const running = Status._('running');
      53             : 
      54             :   /// The test has finished running.
      55             :   ///
      56             :   /// Note that even if the test is marked [complete], it may still be running
      57             :   /// code asynchronously. A test is considered complete either once it hits its
      58             :   /// first error or when all [expectAsync] callbacks have been called and any
      59             :   /// returned [Future] has completed, but it's possible for further processing
      60             :   /// to happen, which may cause further errors.
      61             :   static const complete = Status._('complete');
      62             : 
      63             :   /// The name of the status.
      64             :   final String name;
      65             : 
      66           0 :   factory Status.parse(String name) {
      67             :     switch (name) {
      68           0 :       case 'pending':
      69             :         return Status.pending;
      70           0 :       case 'running':
      71             :         return Status.running;
      72           0 :       case 'complete':
      73             :         return Status.complete;
      74             :       default:
      75           0 :         throw ArgumentError('Invalid status name "$name".');
      76             :     }
      77             :   }
      78             : 
      79          11 :   const Status._(this.name);
      80             : 
      81           0 :   @override
      82           0 :   String toString() => name;
      83             : }
      84             : 
      85             : /// The outcome of the test, as far as it's known.
      86             : class Result {
      87             :   /// The test has not yet failed in any way.
      88             :   ///
      89             :   /// Note that this doesn't mean that the test won't fail in the future.
      90             :   static const success = Result._('success');
      91             : 
      92             :   /// The test, or some part of it, has been skipped.
      93             :   ///
      94             :   /// This implies that the test hasn't failed *yet*. However, it this doesn't
      95             :   /// mean that the test won't fail in the future.
      96             :   static const skipped = Result._('skipped');
      97             : 
      98             :   /// The test has failed.
      99             :   ///
     100             :   /// A failure is specifically caused by a [TestFailure] being thrown; any
     101             :   /// other exception causes an error.
     102             :   static const failure = Result._('failure');
     103             : 
     104             :   /// The test has crashed.
     105             :   ///
     106             :   /// Any exception other than a [TestFailure] is considered to be an error.
     107             :   static const error = Result._('error');
     108             : 
     109             :   /// The name of the result.
     110             :   final String name;
     111             : 
     112             :   /// Whether this is a passing result.
     113             :   ///
     114             :   /// A test is considered to have passed if it's a success or if it was
     115             :   /// skipped.
     116           0 :   bool get isPassing => this == success || this == skipped;
     117             : 
     118             :   /// Whether this is a failing result.
     119             :   ///
     120             :   /// A test is considered to have failed if it experiences a failure or an
     121             :   /// error.
     122           0 :   bool get isFailing => !isPassing;
     123             : 
     124           0 :   factory Result.parse(String name) {
     125             :     switch (name) {
     126           0 :       case 'success':
     127             :         return Result.success;
     128           0 :       case 'skipped':
     129             :         return Result.skipped;
     130           0 :       case 'failure':
     131             :         return Result.failure;
     132           0 :       case 'error':
     133             :         return Result.error;
     134             :       default:
     135           0 :         throw ArgumentError('Invalid result name "$name".');
     136             :     }
     137             :   }
     138             : 
     139          11 :   const Result._(this.name);
     140             : 
     141           0 :   @override
     142           0 :   String toString() => name;
     143             : }

Generated by: LCOV version 1.14