Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: lib/src/runner/runner_suite.dart

Issue 1422963004: Add RunnerSuite.{on,is}Debugging properties. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « lib/src/runner/load_suite.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.runner.runner_suite; 5 library test.runner.runner_suite;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:async/async.dart'; 9 import 'package:async/async.dart';
10 10
11 import '../backend/operating_system.dart'; 11 import '../backend/operating_system.dart';
12 import '../backend/suite.dart'; 12 import '../backend/suite.dart';
13 import '../backend/group.dart'; 13 import '../backend/group.dart';
14 import '../backend/test.dart'; 14 import '../backend/test.dart';
15 import '../backend/test_platform.dart'; 15 import '../backend/test_platform.dart';
16 import '../utils.dart'; 16 import '../utils.dart';
17 import 'environment.dart'; 17 import 'environment.dart';
18 18
19 /// A suite produced and consumed by the test runner that has runner-specific 19 /// A suite produced and consumed by the test runner that has runner-specific
20 /// logic and lifecycle management. 20 /// logic and lifecycle management.
21 /// 21 ///
22 /// This is separated from [Suite] because the backend library (which will 22 /// This is separated from [Suite] because the backend library (which will
23 /// eventually become its own package) is primarily for test code itself to use, 23 /// eventually become its own package) is primarily for test code itself to use,
24 /// for which the [RunnerSuite] APIs don't make sense. 24 /// for which the [RunnerSuite] APIs don't make sense.
25 ///
26 /// A [RunnerSuite] can be produced and controlled using a
27 /// [RunnerSuiteController].
25 class RunnerSuite extends Suite { 28 class RunnerSuite extends Suite {
26 final Environment environment; 29 final RunnerSuiteController _controller;
27 30
28 /// The memoizer for running [close] exactly once. 31 /// The environment in which this suite runs.
29 final _closeMemo = new AsyncMemoizer(); 32 Environment get environment => _controller._environment;
33
34 /// Whether the suite is paused for debugging.
35 ///
36 /// When using a dev inspector, this may also mean that the entire browser is
37 /// paused.
38 bool get isDebugging => _controller._isDebugging;
39
40 /// A broadcast stream that emits an event whenever the suite is paused for
41 /// debugging or resumed afterwards.
42 ///
43 /// The event is `true` when debugging starts and `false` when it ends.
44 Stream<bool> get onDebugging => _controller._onDebuggingController.stream;
45
46 /// A shortcut constructor for creating a [RunnerSuite] that never goes into
47 /// debugging mode.
48 factory RunnerSuite(Environment environment, Group group, {String path,
49 TestPlatform platform, OperatingSystem os, AsyncFunction onClose}) {
50 var controller = new RunnerSuiteController(environment, group,
51 path: path, platform: platform, os: os, onClose: onClose);
52 return controller.suite;
53 }
54
55 RunnerSuite._(this._controller, Group group, String path,
56 TestPlatform platform, OperatingSystem os)
57 : super(group, path: path, platform: platform, os: os);
58
59 RunnerSuite filter(bool callback(Test test)) {
60 var filtered = group.filter(callback);
61 filtered ??= new Group.root([], metadata: metadata);
62 return new RunnerSuite._(_controller, filtered, path, platform, os);
63 }
64
65 /// Closes the suite and releases any resources associated with it.
66 Future close() => _controller._close();
67 }
68
69 /// A class that exposes and controls a [RunnerSuite].
70 class RunnerSuiteController {
71 /// The suite controlled by this controller.
72 RunnerSuite get suite => _suite;
73 RunnerSuite _suite;
74
75 /// The backing value for [suite.environment].
76 final Environment _environment;
30 77
31 /// The function to call when the suite is closed. 78 /// The function to call when the suite is closed.
32 final AsyncFunction _onClose; 79 final AsyncFunction _onClose;
33 80
34 RunnerSuite(this.environment, Group group, {String path, 81 /// The backing value for [suite.isDebugging].
82 bool _isDebugging = false;
83
84 /// The controller for [suite.onDebugging].
85 final _onDebuggingController = new StreamController<bool>.broadcast();
86
87 RunnerSuiteController(this._environment, Group group, {String path,
35 TestPlatform platform, OperatingSystem os, AsyncFunction onClose}) 88 TestPlatform platform, OperatingSystem os, AsyncFunction onClose})
36 : _onClose = onClose, 89 : _onClose = onClose {
37 super(group, path: path, platform: platform, os: os); 90 _suite = new RunnerSuite._(this, group, path, platform, os);
38
39 RunnerSuite filter(bool callback(Test test)) {
40 var filtered = group.filter(callback);
41 filtered ??= new Group.root([], metadata: metadata);
42 return new RunnerSuite(environment, filtered,
43 platform: platform, os: os, path: path);
44 } 91 }
45 92
46 /// Closes the suite and releases any resources associated with it. 93 /// Sets whether the suite is paused for debugging.
47 Future close() { 94 ///
48 return _closeMemo.runOnce(() async { 95 /// If this is different than [suite.isDebugging], this will automatically
49 if (_onClose != null) await _onClose(); 96 /// send out an event along [suite.onDebugging].
50 }); 97 void setDebugging(bool debugging) {
98 if (debugging == _isDebugging) return;
99 _isDebugging = debugging;
100 _onDebuggingController.add(debugging);
51 } 101 }
102
103 /// The backing function for [suite.close].
104 Future _close() => _closeMemo.runOnce(() async {
105 _onDebuggingController.close();
106 if (_onClose != null) await _onClose();
107 });
108 final _closeMemo = new AsyncMemoizer();
52 } 109 }
OLDNEW
« no previous file with comments | « lib/src/runner/load_suite.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698