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

Side by Side Diff: lib/src/runner/reporter/json.dart

Issue 2099553002: Add an option to run skipped tests. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Code review changes Created 4 years, 5 months 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/loader.dart ('k') | test/runner/compact_reporter_test.dart » ('j') | 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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import '../../backend/group.dart'; 8 import '../../backend/group.dart';
9 import '../../backend/group_entry.dart'; 9 import '../../backend/group_entry.dart';
10 import '../../backend/live_test.dart'; 10 import '../../backend/live_test.dart';
11 import '../../backend/metadata.dart'; 11 import '../../backend/metadata.dart';
12 import '../../backend/state.dart'; 12 import '../../backend/state.dart';
13 import '../../backend/suite.dart'; 13 import '../../backend/suite.dart';
14 import '../../backend/test_platform.dart'; 14 import '../../backend/test_platform.dart';
15 import '../../frontend/expect.dart'; 15 import '../../frontend/expect.dart';
16 import '../../utils.dart'; 16 import '../../utils.dart';
17 import '../engine.dart'; 17 import '../engine.dart';
18 import '../load_suite.dart'; 18 import '../load_suite.dart';
19 import '../reporter.dart'; 19 import '../reporter.dart';
20 import '../version.dart'; 20 import '../version.dart';
21 21
22 /// A reporter that prints machine-readable JSON-formatted test results. 22 /// A reporter that prints machine-readable JSON-formatted test results.
23 class JsonReporter implements Reporter { 23 class JsonReporter implements Reporter {
24 /// Whether to use verbose stack traces. 24 /// Whether to use verbose stack traces.
25 final bool _verboseTrace; 25 final bool _verboseTrace;
26 26
27 /// Whether to emit location information for JS tests. 27 /// Whether to emit location information for JS tests.
28 final bool _jsLocations; 28 final bool _jsLocations;
29 29
30 /// Whether skipped tests are run anyway.
31 final bool _runSkipped;
32
30 /// The engine used to run the tests. 33 /// The engine used to run the tests.
31 final Engine _engine; 34 final Engine _engine;
32 35
33 /// A stopwatch that tracks the duration of the full run. 36 /// A stopwatch that tracks the duration of the full run.
34 final _stopwatch = new Stopwatch(); 37 final _stopwatch = new Stopwatch();
35 38
36 /// Whether we've started [_stopwatch]. 39 /// Whether we've started [_stopwatch].
37 /// 40 ///
38 /// We can't just use `_stopwatch.isRunning` because the stopwatch is stopped 41 /// We can't just use `_stopwatch.isRunning` because the stopwatch is stopped
39 /// when the reporter is paused. 42 /// when the reporter is paused.
(...skipping 16 matching lines...) Expand all
56 59
57 /// The next ID to associate with a [LiveTest]. 60 /// The next ID to associate with a [LiveTest].
58 var _nextID = 0; 61 var _nextID = 0;
59 62
60 /// Watches the tests run by [engine] and prints their results as JSON. 63 /// Watches the tests run by [engine] and prints their results as JSON.
61 /// 64 ///
62 /// If [verboseTrace] is `true`, this will print core library frames. If 65 /// If [verboseTrace] is `true`, this will print core library frames. If
63 /// [jsLocations] is `false`, this will not emit location information for JS 66 /// [jsLocations] is `false`, this will not emit location information for JS
64 /// tests. 67 /// tests.
65 static JsonReporter watch(Engine engine, {bool verboseTrace: false, 68 static JsonReporter watch(Engine engine, {bool verboseTrace: false,
66 bool jsLocations: true}) { 69 bool jsLocations: true, bool runSkipped: false}) {
67 return new JsonReporter._(engine, 70 return new JsonReporter._(engine,
68 verboseTrace: verboseTrace, jsLocations: jsLocations); 71 verboseTrace: verboseTrace,
72 jsLocations: jsLocations,
73 runSkipped: runSkipped);
69 } 74 }
70 75
71 JsonReporter._(this._engine, {bool verboseTrace: false, 76 JsonReporter._(this._engine, {bool verboseTrace: false,
72 bool jsLocations: true}) 77 bool jsLocations: true, bool runSkipped: false})
73 : _verboseTrace = verboseTrace, 78 : _verboseTrace = verboseTrace,
74 _jsLocations = jsLocations { 79 _jsLocations = jsLocations,
80 _runSkipped = runSkipped {
75 _subscriptions.add(_engine.onTestStarted.listen(_onTestStarted)); 81 _subscriptions.add(_engine.onTestStarted.listen(_onTestStarted));
76 82
77 /// Convert the future to a stream so that the subscription can be paused or 83 /// Convert the future to a stream so that the subscription can be paused or
78 /// canceled. 84 /// canceled.
79 _subscriptions.add(_engine.success.asStream().listen(_onDone)); 85 _subscriptions.add(_engine.success.asStream().listen(_onDone));
80 86
81 _subscriptions.add(_engine.onSuiteAdded.listen(null, onDone: () { 87 _subscriptions.add(_engine.onSuiteAdded.listen(null, onDone: () {
82 _emit("allSuites", { 88 _emit("allSuites", {
83 "count": _engine.addedSuites.length 89 "count": _engine.addedSuites.length
84 }); 90 });
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 "metadata": _serializeMetadata(group.metadata), 222 "metadata": _serializeMetadata(group.metadata),
217 "testCount": group.testCount 223 "testCount": group.testCount
218 }, group, suite.platform) 224 }, group, suite.platform)
219 }); 225 });
220 parentID = id; 226 parentID = id;
221 return id; 227 return id;
222 }).toList(); 228 }).toList();
223 } 229 }
224 230
225 /// Serializes [metadata] into a JSON-protocol-compatible map. 231 /// Serializes [metadata] into a JSON-protocol-compatible map.
226 Map _serializeMetadata(Metadata metadata) => 232 Map _serializeMetadata(Metadata metadata) => _runSkipped
227 {"skip": metadata.skip, "skipReason": metadata.skipReason}; 233 ? {"skip": false, "skipReason": null}
234 : {"skip": metadata.skip, "skipReason": metadata.skipReason};
228 235
229 /// A callback called when [liveTest] finishes running. 236 /// A callback called when [liveTest] finishes running.
230 void _onComplete(LiveTest liveTest) { 237 void _onComplete(LiveTest liveTest) {
231 _emit("testDone", { 238 _emit("testDone", {
232 "testID": _liveTestIDs[liveTest], 239 "testID": _liveTestIDs[liveTest],
233 // For backwards-compatibility, report skipped tests as successes. 240 // For backwards-compatibility, report skipped tests as successes.
234 "result": liveTest.state.result == Result.skipped 241 "result": liveTest.state.result == Result.skipped
235 ? "success" 242 ? "success"
236 : liveTest.state.result.toString(), 243 : liveTest.state.result.toString(),
237 "skipped": liveTest.state.result == Result.skipped, 244 "skipped": liveTest.state.result == Result.skipped,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 GroupEntry entry, TestPlatform platform) { 282 GroupEntry entry, TestPlatform platform) {
276 var frame = entry.trace?.frames?.first; 283 var frame = entry.trace?.frames?.first;
277 if (!_jsLocations && platform.isJS) frame = null; 284 if (!_jsLocations && platform.isJS) frame = null;
278 285
279 map["line"] = frame?.line; 286 map["line"] = frame?.line;
280 map["column"] = frame?.column; 287 map["column"] = frame?.column;
281 map["url"] = frame?.uri?.toString(); 288 map["url"] = frame?.uri?.toString();
282 return map; 289 return map;
283 } 290 }
284 } 291 }
OLDNEW
« no previous file with comments | « lib/src/runner/loader.dart ('k') | test/runner/compact_reporter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698