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

Generated by: LCOV version 1.13