| OLD | NEW |
| 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_cli/src/build_mode.dart'; | 8 import 'package:analyzer_cli/src/build_mode.dart'; |
| 8 import 'package:analyzer_cli/src/driver.dart'; | 9 import 'package:analyzer_cli/src/driver.dart'; |
| 9 import 'package:analyzer_cli/src/options.dart'; | 10 import 'package:analyzer_cli/src/options.dart'; |
| 10 import 'package:bazel_worker/bazel_worker.dart'; | 11 import 'package:bazel_worker/bazel_worker.dart'; |
| 11 import 'package:bazel_worker/testing.dart'; | 12 import 'package:bazel_worker/testing.dart'; |
| 12 import 'package:protobuf/protobuf.dart'; | 13 import 'package:protobuf/protobuf.dart'; |
| 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 14 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 14 import 'package:unittest/unittest.dart'; | 15 import 'package:unittest/unittest.dart'; |
| 15 | 16 |
| 16 main() { | 17 main() { |
| 17 defineReflectiveTests(WorkerLoopTest); | 18 defineReflectiveTests(WorkerLoopTest); |
| 18 } | 19 } |
| 19 | 20 |
| 21 typedef void _TestWorkerLoopAnalyze(CommandLineOptions options); |
| 22 |
| 23 /** |
| 24 * [AnalyzerWorkerLoop] for testing. |
| 25 */ |
| 26 class TestAnalyzerWorkerLoop extends AnalyzerWorkerLoop { |
| 27 final _TestWorkerLoopAnalyze _analyze; |
| 28 |
| 29 TestAnalyzerWorkerLoop(SyncWorkerConnection connection, [this._analyze]) |
| 30 : super(new MemoryResourceProvider(), connection); |
| 31 |
| 32 @override |
| 33 void analyze(CommandLineOptions options) { |
| 34 if (_analyze != null) { |
| 35 _analyze(options); |
| 36 } |
| 37 } |
| 38 } |
| 39 |
| 20 @reflectiveTest | 40 @reflectiveTest |
| 21 class WorkerLoopTest { | 41 class WorkerLoopTest { |
| 22 final TestStdinSync stdinStream = new TestStdinSync(); | 42 final TestStdinSync stdinStream = new TestStdinSync(); |
| 23 final TestStdoutStream stdoutStream = new TestStdoutStream(); | 43 final TestStdoutStream stdoutStream = new TestStdoutStream(); |
| 24 TestSyncWorkerConnection connection; | 44 TestSyncWorkerConnection connection; |
| 25 | 45 |
| 26 WorkerLoopTest() { | 46 WorkerLoopTest() { |
| 27 connection = | 47 connection = |
| 28 new TestSyncWorkerConnection(this.stdinStream, this.stdoutStream); | 48 new TestSyncWorkerConnection(this.stdinStream, this.stdoutStream); |
| 29 } | 49 } |
| 30 | 50 |
| 31 void setUp() {} | 51 void setUp() {} |
| 32 | 52 |
| 33 List<int> _serializeProto(GeneratedMessage message) { | |
| 34 var buffer = message.writeToBuffer(); | |
| 35 | |
| 36 var writer = new CodedBufferWriter(); | |
| 37 writer.writeInt32NoTag(buffer.length); | |
| 38 writer.writeRawBytes(buffer); | |
| 39 | |
| 40 return writer.toBuffer(); | |
| 41 } | |
| 42 | |
| 43 test_run() { | 53 test_run() { |
| 44 var request = new WorkRequest(); | 54 var request = new WorkRequest(); |
| 45 request.arguments.addAll([ | 55 request.arguments.addAll([ |
| 46 '--build-summary-input=/tmp/1.sum', | 56 '--build-summary-input=/tmp/1.sum', |
| 47 '--build-summary-input=/tmp/2.sum', | 57 '--build-summary-input=/tmp/2.sum', |
| 48 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', | 58 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', |
| 49 'package:foo/bar.dart|/inputs/foo/lib/bar.dart', | 59 'package:foo/bar.dart|/inputs/foo/lib/bar.dart', |
| 50 ]); | 60 ]); |
| 51 stdinStream.addInputBytes(_serializeProto(request)); | 61 stdinStream.addInputBytes(_serializeProto(request)); |
| 52 stdinStream.close(); | 62 stdinStream.close(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 | 122 |
| 113 var response = connection.responses[0]; | 123 var response = connection.responses[0]; |
| 114 expect(response.exitCode, EXIT_CODE_ERROR); | 124 expect(response.exitCode, EXIT_CODE_ERROR); |
| 115 expect(response.output, anything); | 125 expect(response.output, anything); |
| 116 } | 126 } |
| 117 | 127 |
| 118 test_run_stopAtEOF() { | 128 test_run_stopAtEOF() { |
| 119 stdinStream.close(); | 129 stdinStream.close(); |
| 120 new TestAnalyzerWorkerLoop(connection).run(); | 130 new TestAnalyzerWorkerLoop(connection).run(); |
| 121 } | 131 } |
| 122 } | |
| 123 | 132 |
| 124 typedef void _TestWorkerLoopAnalyze(CommandLineOptions options); | 133 List<int> _serializeProto(GeneratedMessage message) { |
| 134 var buffer = message.writeToBuffer(); |
| 125 | 135 |
| 126 /** | 136 var writer = new CodedBufferWriter(); |
| 127 * [AnalyzerWorkerLoop] for testing. | 137 writer.writeInt32NoTag(buffer.length); |
| 128 */ | 138 writer.writeRawBytes(buffer); |
| 129 class TestAnalyzerWorkerLoop extends AnalyzerWorkerLoop { | |
| 130 final _TestWorkerLoopAnalyze _analyze; | |
| 131 | 139 |
| 132 TestAnalyzerWorkerLoop(SyncWorkerConnection connection, [this._analyze]) | 140 return writer.toBuffer(); |
| 133 : super(connection); | |
| 134 | |
| 135 @override | |
| 136 void analyze(CommandLineOptions options) { | |
| 137 if (_analyze != null) { | |
| 138 _analyze(options); | |
| 139 } | |
| 140 } | 141 } |
| 141 } | 142 } |
| OLD | NEW |