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

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

Issue 1461293005: Add a JSON reporter. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: 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
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; 5 library test.runner;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 9
10 import 'package:async/async.dart'; 10 import 'package:async/async.dart';
11 11
12 import 'backend/test_platform.dart'; 12 import 'backend/test_platform.dart';
13 import 'runner/application_exception.dart'; 13 import 'runner/application_exception.dart';
14 import 'runner/configuration.dart'; 14 import 'runner/configuration.dart';
15 import 'runner/engine.dart'; 15 import 'runner/engine.dart';
16 import 'runner/load_exception.dart'; 16 import 'runner/load_exception.dart';
17 import 'runner/load_suite.dart'; 17 import 'runner/load_suite.dart';
18 import 'runner/loader.dart'; 18 import 'runner/loader.dart';
19 import 'runner/reporter.dart'; 19 import 'runner/reporter.dart';
20 import 'runner/reporter/compact.dart'; 20 import 'runner/reporter/compact.dart';
21 import 'runner/reporter/expanded.dart'; 21 import 'runner/reporter/expanded.dart';
22 import 'runner/reporter/json.dart';
22 import 'runner/runner_suite.dart'; 23 import 'runner/runner_suite.dart';
23 import 'util/io.dart'; 24 import 'util/io.dart';
24 import 'utils.dart'; 25 import 'utils.dart';
25 26
26 /// A class that loads and runs tests based on a [Configuration]. 27 /// A class that loads and runs tests based on a [Configuration].
27 /// 28 ///
28 /// This maintains a [Loader] and an [Engine] and passes test suites from one to 29 /// This maintains a [Loader] and an [Engine] and passes test suites from one to
29 /// the other, as well as printing out tests with a [CompactReporter] or an 30 /// the other, as well as printing out tests with a [CompactReporter] or an
30 /// [ExpandedReporter]. 31 /// [ExpandedReporter].
31 class Runner { 32 class Runner {
(...skipping 14 matching lines...) Expand all
46 47
47 /// The memoizer for ensuring [close] only runs once. 48 /// The memoizer for ensuring [close] only runs once.
48 final _closeMemo = new AsyncMemoizer(); 49 final _closeMemo = new AsyncMemoizer();
49 bool get _closed => _closeMemo.hasRun; 50 bool get _closed => _closeMemo.hasRun;
50 51
51 /// Creates a new runner based on [configuration]. 52 /// Creates a new runner based on [configuration].
52 factory Runner(Configuration config) { 53 factory Runner(Configuration config) {
53 var loader = new Loader(config); 54 var loader = new Loader(config);
54 var engine = new Engine(concurrency: config.concurrency); 55 var engine = new Engine(concurrency: config.concurrency);
55 56
56 var watch = config.reporter == "compact" 57 var reporter;
57 ? CompactReporter.watch 58 switch (config.reporter) {
58 : ExpandedReporter.watch; 59 case "compact":
60 case "expanded":
61 var watch = config.reporter == "compact"
62 ? CompactReporter.watch
63 : ExpandedReporter.watch;
59 64
60 var reporter = watch( 65 reporter = watch(
61 engine, 66 engine,
62 color: config.color, 67 color: config.color,
63 verboseTrace: config.verboseTrace, 68 verboseTrace: config.verboseTrace,
64 printPath: config.paths.length > 1 || 69 printPath: config.paths.length > 1 ||
65 new Directory(config.paths.single).existsSync(), 70 new Directory(config.paths.single).existsSync(),
66 printPlatform: config.platforms.length > 1); 71 printPlatform: config.platforms.length > 1);
72 break;
73
74 case "json":
75 reporter = JsonReporter.watch(engine,
76 verboseTrace: config.verboseTrace);
77 break;
78 }
67 79
68 return new Runner._(config, loader, engine, reporter); 80 return new Runner._(config, loader, engine, reporter);
69 } 81 }
70 82
71 Runner._(this._config, this._loader, this._engine, this._reporter); 83 Runner._(this._config, this._loader, this._engine, this._reporter);
72 84
73 /// Starts the runner. 85 /// Starts the runner.
74 /// 86 ///
75 /// This starts running tests and printing their progress. It returns whether 87 /// This starts running tests and printing their progress. It returns whether
76 /// or not they ran successfully. 88 /// or not they ran successfully.
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 258
247 await inCompletionOrder([ 259 await inCompletionOrder([
248 suite.environment.displayPause(), 260 suite.environment.displayPause(),
249 cancelableNext(stdinLines) 261 cancelableNext(stdinLines)
250 ]).first; 262 ]).first;
251 } finally { 263 } finally {
252 _reporter.resume(); 264 _reporter.resume();
253 } 265 }
254 } 266 }
255 } 267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698