|
| 1 | +// Copyright (c) 2017, 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 | +import 'dart:io'; |
| 6 | +import 'dart:collection'; |
| 7 | + |
| 8 | +import '../engine.dart'; |
| 9 | +import '../configuration.dart'; |
| 10 | +import '../reporter.dart'; |
| 11 | +import '../reporter/compact.dart'; |
| 12 | +import '../reporter/expanded.dart'; |
| 13 | +import '../reporter/json.dart'; |
| 14 | +import '../../util/io.dart'; |
| 15 | + |
| 16 | +/// Constructs a reporter for the provided engine with the provided |
| 17 | +/// configuration. |
| 18 | +typedef Reporter ReporterFactory(Configuration configuration, Engine engine); |
| 19 | + |
| 20 | +/// Container for a reporter description and corresponding factory. |
| 21 | +class ReporterDetails { |
| 22 | + final String description; |
| 23 | + final ReporterFactory factory; |
| 24 | + ReporterDetails(this.description, this.factory); |
| 25 | +} |
| 26 | + |
| 27 | +/// All reporters and their corresponding details. |
| 28 | +final UnmodifiableMapView<String, ReporterDetails> allReporters = |
| 29 | + new UnmodifiableMapView<String, ReporterDetails>(_allReporters); |
| 30 | + |
| 31 | +final _allReporters = <String, ReporterDetails>{ |
| 32 | + "expanded": new ReporterDetails( |
| 33 | + "A separate line for each update.", |
| 34 | + (config, engine) => ExpandedReporter.watch(engine, |
| 35 | + color: config.color, |
| 36 | + printPath: config.paths.length > 1 || |
| 37 | + new Directory(config.paths.single).existsSync(), |
| 38 | + printPlatform: config.suiteDefaults.platforms.length > 1)), |
| 39 | + "compact": new ReporterDetails("A single line, updated continuously.", |
| 40 | + (_, engine) => CompactReporter.watch(engine)), |
| 41 | + "json": new ReporterDetails( |
| 42 | + "A machine-readable format (see https://goo.gl/gBsV1a).", |
| 43 | + (_, engine) => JsonReporter.watch(engine)), |
| 44 | +}; |
| 45 | + |
| 46 | +final defaultReporter = |
| 47 | + inTestTests ? 'expanded' : (Platform.isWindows ? 'expanded' : 'compact'); |
| 48 | + |
| 49 | +/// **Do not call this function without express permission from the test package |
| 50 | +/// authors**. |
| 51 | +/// |
| 52 | +/// This globally registers a reporter. |
| 53 | +void registerReporter(String name, ReporterDetails reporterDetails) { |
| 54 | + _allReporters[name] = reporterDetails; |
| 55 | +} |
0 commit comments