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

Side by Side Diff: pkg/analyzer_cli/test/build_mode_test.dart

Issue 2998603002: Make AnalyzerWorkerLoop AsyncWorkerLoop. (Closed)
Patch Set: Created 3 years, 4 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 | « pkg/analyzer_cli/lib/src/build_mode.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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 analyzer_cli.test.built_mode; 5 library analyzer_cli.test.built_mode;
6 6
7 import 'package:analyzer/file_system/memory_file_system.dart'; 7 import 'package:analyzer/file_system/memory_file_system.dart';
8 import 'package:analyzer_cli/src/build_mode.dart'; 8 import 'package:analyzer_cli/src/build_mode.dart';
9 import 'package:analyzer_cli/src/driver.dart'; 9 import 'package:analyzer_cli/src/driver.dart';
10 import 'package:analyzer_cli/src/options.dart'; 10 import 'package:analyzer_cli/src/options.dart';
11 import 'package:bazel_worker/bazel_worker.dart'; 11 import 'package:bazel_worker/bazel_worker.dart';
12 import 'package:bazel_worker/testing.dart'; 12 import 'package:bazel_worker/testing.dart';
13 import 'package:protobuf/protobuf.dart'; 13 import 'package:protobuf/protobuf.dart';
14 import 'package:test/test.dart'; 14 import 'package:test/test.dart';
15 import 'package:test_reflective_loader/test_reflective_loader.dart'; 15 import 'package:test_reflective_loader/test_reflective_loader.dart';
16 16
17 main() { 17 main() {
18 defineReflectiveTests(WorkerLoopTest); 18 defineReflectiveTests(WorkerLoopTest);
19 } 19 }
20 20
21 typedef void _TestWorkerLoopAnalyze(CommandLineOptions options); 21 typedef void _TestWorkerLoopAnalyze(CommandLineOptions options);
22 22
23 /** 23 /**
24 * [AnalyzerWorkerLoop] for testing. 24 * [AnalyzerWorkerLoop] for testing.
25 */ 25 */
26 class TestAnalyzerWorkerLoop extends AnalyzerWorkerLoop { 26 class TestAnalyzerWorkerLoop extends AnalyzerWorkerLoop {
27 final _TestWorkerLoopAnalyze _analyze; 27 final _TestWorkerLoopAnalyze _analyze;
28 28
29 TestAnalyzerWorkerLoop(SyncWorkerConnection connection, [this._analyze]) 29 TestAnalyzerWorkerLoop(AsyncWorkerConnection connection, [this._analyze])
30 : super(new MemoryResourceProvider(), connection); 30 : super(new MemoryResourceProvider(), connection);
31 31
32 @override 32 @override
33 void analyze(CommandLineOptions options) { 33 void analyze(CommandLineOptions options) {
34 if (_analyze != null) { 34 if (_analyze != null) {
35 _analyze(options); 35 _analyze(options);
36 } 36 }
37 } 37 }
38 } 38 }
39 39
40 @reflectiveTest 40 @reflectiveTest
41 class WorkerLoopTest { 41 class WorkerLoopTest {
42 final TestStdinSync stdinStream = new TestStdinSync(); 42 final TestStdinAsync stdinStream = new TestStdinAsync();
43 final TestStdoutStream stdoutStream = new TestStdoutStream(); 43 final TestStdoutStream stdoutStream = new TestStdoutStream();
44 TestSyncWorkerConnection connection; 44 TestAsyncWorkerConnection connection;
45 45
46 WorkerLoopTest() { 46 WorkerLoopTest() {
47 connection = 47 connection =
48 new TestSyncWorkerConnection(this.stdinStream, this.stdoutStream); 48 new TestAsyncWorkerConnection(this.stdinStream, this.stdoutStream);
49 } 49 }
50 50
51 void setUp() {} 51 void setUp() {}
52 52
53 test_run() { 53 test_run() async {
54 var request = new WorkRequest(); 54 var request = new WorkRequest();
55 request.arguments.addAll([ 55 request.arguments.addAll([
56 '--build-summary-input=/tmp/1.sum', 56 '--build-summary-input=/tmp/1.sum',
57 '--build-summary-input=/tmp/2.sum', 57 '--build-summary-input=/tmp/2.sum',
58 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', 58 'package:foo/foo.dart|/inputs/foo/lib/foo.dart',
59 'package:foo/bar.dart|/inputs/foo/lib/bar.dart', 59 'package:foo/bar.dart|/inputs/foo/lib/bar.dart',
60 ]); 60 ]);
61 stdinStream.addInputBytes(_serializeProto(request)); 61 stdinStream.addInputBytes(_serializeProto(request));
62 stdinStream.close(); 62 stdinStream.close();
63 63
64 new TestAnalyzerWorkerLoop(connection, (CommandLineOptions options) { 64 await new TestAnalyzerWorkerLoop(connection, (CommandLineOptions options) {
65 expect(options.buildSummaryInputs, 65 expect(options.buildSummaryInputs,
66 unorderedEquals(['/tmp/1.sum', '/tmp/2.sum'])); 66 unorderedEquals(['/tmp/1.sum', '/tmp/2.sum']));
67 expect( 67 expect(
68 options.sourceFiles, 68 options.sourceFiles,
69 unorderedEquals([ 69 unorderedEquals([
70 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', 70 'package:foo/foo.dart|/inputs/foo/lib/foo.dart',
71 'package:foo/bar.dart|/inputs/foo/lib/bar.dart' 71 'package:foo/bar.dart|/inputs/foo/lib/bar.dart'
72 ])); 72 ]));
73 outSink.writeln('outSink a'); 73 outSink.writeln('outSink a');
74 errorSink.writeln('errorSink a'); 74 errorSink.writeln('errorSink a');
75 outSink.writeln('outSink b'); 75 outSink.writeln('outSink b');
76 errorSink.writeln('errorSink b'); 76 errorSink.writeln('errorSink b');
77 }).run(); 77 }).run();
78 expect(connection.responses, hasLength(1)); 78 expect(connection.responses, hasLength(1));
79 79
80 var response = connection.responses[0]; 80 var response = connection.responses[0];
81 expect(response.exitCode, EXIT_CODE_OK, reason: response.output); 81 expect(response.exitCode, EXIT_CODE_OK, reason: response.output);
82 expect( 82 expect(
83 response.output, 83 response.output,
84 allOf(contains('errorSink a'), contains('errorSink a'), 84 allOf(contains('errorSink a'), contains('errorSink a'),
85 contains('outSink a'), contains('outSink b'))); 85 contains('outSink a'), contains('outSink b')));
86 86
87 // Check that a serialized version was written to std out. 87 // Check that a serialized version was written to std out.
88 expect(stdoutStream.writes, hasLength(1)); 88 expect(stdoutStream.writes, hasLength(1));
89 expect(stdoutStream.writes[0], _serializeProto(response)); 89 expect(stdoutStream.writes[0], _serializeProto(response));
90 } 90 }
91 91
92 test_run_invalidOptions() { 92 test_run_invalidOptions() async {
93 var request = new WorkRequest(); 93 var request = new WorkRequest();
94 request.arguments.addAll(['--unknown-option', '/foo.dart', '/bar.dart']); 94 request.arguments.addAll(['--unknown-option', '/foo.dart', '/bar.dart']);
95 stdinStream.addInputBytes(_serializeProto(request)); 95 stdinStream.addInputBytes(_serializeProto(request));
96 stdinStream.close(); 96 stdinStream.close();
97 new TestAnalyzerWorkerLoop(connection).run(); 97 await new TestAnalyzerWorkerLoop(connection).run();
98 expect(connection.responses, hasLength(1)); 98 expect(connection.responses, hasLength(1));
99 99
100 var response = connection.responses[0]; 100 var response = connection.responses[0];
101 expect(response.exitCode, EXIT_CODE_ERROR); 101 expect(response.exitCode, EXIT_CODE_ERROR);
102 expect(response.output, anything); 102 expect(response.output, anything);
103 } 103 }
104 104
105 test_run_invalidRequest_noArgumentsInputs() { 105 test_run_invalidRequest_noArgumentsInputs() async {
106 stdinStream.addInputBytes(_serializeProto(new WorkRequest())); 106 stdinStream.addInputBytes(_serializeProto(new WorkRequest()));
107 stdinStream.close(); 107 stdinStream.close();
108 108
109 new TestAnalyzerWorkerLoop(connection).run(); 109 await new TestAnalyzerWorkerLoop(connection).run();
110 expect(connection.responses, hasLength(1)); 110 expect(connection.responses, hasLength(1));
111 111
112 var response = connection.responses[0]; 112 var response = connection.responses[0];
113 expect(response.exitCode, EXIT_CODE_ERROR); 113 expect(response.exitCode, EXIT_CODE_ERROR);
114 expect(response.output, anything); 114 expect(response.output, anything);
115 } 115 }
116 116
117 test_run_invalidRequest_randomBytes() { 117 test_run_invalidRequest_randomBytes() async {
118 stdinStream.addInputBytes([1, 2, 3]); 118 stdinStream.addInputBytes([1, 2, 3]);
119 stdinStream.close(); 119 stdinStream.close();
120 new TestAnalyzerWorkerLoop(connection).run(); 120 await new TestAnalyzerWorkerLoop(connection).run();
121 expect(connection.responses, hasLength(1)); 121 expect(connection.responses, hasLength(1));
122 122
123 var response = connection.responses[0]; 123 var response = connection.responses[0];
124 expect(response.exitCode, EXIT_CODE_ERROR); 124 expect(response.exitCode, EXIT_CODE_ERROR);
125 expect(response.output, anything); 125 expect(response.output, anything);
126 } 126 }
127 127
128 test_run_stopAtEOF() { 128 test_run_stopAtEOF() async {
129 stdinStream.close(); 129 stdinStream.close();
130 new TestAnalyzerWorkerLoop(connection).run(); 130 await new TestAnalyzerWorkerLoop(connection).run();
131 } 131 }
132 132
133 List<int> _serializeProto(GeneratedMessage message) { 133 List<int> _serializeProto(GeneratedMessage message) {
134 var buffer = message.writeToBuffer(); 134 var buffer = message.writeToBuffer();
135 135
136 var writer = new CodedBufferWriter(); 136 var writer = new CodedBufferWriter();
137 writer.writeInt32NoTag(buffer.length); 137 writer.writeInt32NoTag(buffer.length);
138 writer.writeRawBytes(buffer); 138 writer.writeRawBytes(buffer);
139 139
140 return writer.toBuffer(); 140 return writer.toBuffer();
141 } 141 }
142 } 142 }
OLDNEW
« no previous file with comments | « pkg/analyzer_cli/lib/src/build_mode.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698