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

Unified Diff: pkg/analyzer_cli/lib/src/batch_mode.dart

Issue 2840703002: Refactoring analyzer_cli for code hygiene. (Closed)
Patch Set: revert some of the file name changes Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/build_mode.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer_cli/lib/src/batch_mode.dart
diff --git a/pkg/analyzer_cli/lib/src/batch_mode.dart b/pkg/analyzer_cli/lib/src/batch_mode.dart
new file mode 100644
index 0000000000000000000000000000000000000000..8b73af1eedf5b97a9854bf4310dd5527c953823d
--- /dev/null
+++ b/pkg/analyzer_cli/lib/src/batch_mode.dart
@@ -0,0 +1,71 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+import 'dart:convert';
+import 'dart:io' show exitCode, stdin;
+
+import 'package:analyzer/error/error.dart';
+
+typedef Future<ErrorSeverity> BatchRunnerHandler(List<String> args);
+
+/// Provides a framework to read command line options from stdin and feed them
+/// to a callback.
+class BatchRunner {
+ final outSink;
+ final errorSink;
+
+ BatchRunner(this.outSink, this.errorSink);
+
+ /// Run the tool in 'batch' mode, receiving command lines through stdin and
+ /// returning pass/fail status through stdout. This feature is intended for
+ /// use in unit testing.
+ void runAsBatch(List<String> sharedArgs, BatchRunnerHandler handler) {
+ outSink.writeln('>>> BATCH START');
+ Stopwatch stopwatch = new Stopwatch();
+ stopwatch.start();
+ int testsFailed = 0;
+ int totalTests = 0;
+ ErrorSeverity batchResult = ErrorSeverity.NONE;
+ // Read line from stdin.
+ Stream cmdLine =
+ stdin.transform(UTF8.decoder).transform(new LineSplitter());
+ cmdLine.listen((String line) async {
+ // Maybe finish.
+ if (line.isEmpty) {
+ var time = stopwatch.elapsedMilliseconds;
+ outSink.writeln(
+ '>>> BATCH END (${totalTests - testsFailed}/$totalTests) ${time}ms');
+ exitCode = batchResult.ordinal;
+ }
+ // Prepare arguments.
+ var lineArgs = line.split(new RegExp('\\s+'));
+ var args = new List<String>();
+ args.addAll(sharedArgs);
+ args.addAll(lineArgs);
+ args.remove('-b');
+ args.remove('--batch');
+ // Analyze single set of arguments.
+ try {
+ totalTests++;
+ ErrorSeverity result = await handler(args);
+ bool resultPass = result != ErrorSeverity.ERROR;
+ if (!resultPass) {
+ testsFailed++;
+ }
+ batchResult = batchResult.max(result);
+ // Write stderr end token and flush.
+ errorSink.writeln('>>> EOF STDERR');
+ String resultPassString = resultPass ? 'PASS' : 'FAIL';
+ outSink.writeln(
+ '>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms');
+ } catch (e, stackTrace) {
+ errorSink.writeln(e);
+ errorSink.writeln(stackTrace);
+ errorSink.writeln('>>> EOF STDERR');
+ outSink.writeln('>>> TEST CRASH');
+ }
+ });
+ }
+}
« no previous file with comments | « no previous file | pkg/analyzer_cli/lib/src/build_mode.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698