| 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_cli/src/build_mode.dart'; | 7 import 'package:analyzer_cli/src/build_mode.dart'; |
| 8 import 'package:analyzer_cli/src/driver.dart'; | 8 import 'package:analyzer_cli/src/driver.dart'; |
| 9 import 'package:analyzer_cli/src/options.dart'; | 9 import 'package:analyzer_cli/src/options.dart'; |
| 10 import 'package:bazel_worker/bazel_worker.dart'; | 10 import 'package:bazel_worker/bazel_worker.dart'; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 test_run() { | 43 test_run() { |
| 44 var request = new WorkRequest(); | 44 var request = new WorkRequest(); |
| 45 request.arguments.addAll([ | 45 request.arguments.addAll([ |
| 46 '--build-summary-input=/tmp/1.sum', | 46 '--build-summary-input=/tmp/1.sum', |
| 47 '--build-summary-input=/tmp/2.sum', | 47 '--build-summary-input=/tmp/2.sum', |
| 48 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', | 48 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', |
| 49 'package:foo/bar.dart|/inputs/foo/lib/bar.dart', | 49 'package:foo/bar.dart|/inputs/foo/lib/bar.dart', |
| 50 ]); | 50 ]); |
| 51 stdinStream.addInputBytes(_serializeProto(request)); | 51 stdinStream.addInputBytes(_serializeProto(request)); |
| 52 stdinStream.close(); |
| 52 | 53 |
| 53 new TestAnalyzerWorkerLoop(connection, (CommandLineOptions options) { | 54 new TestAnalyzerWorkerLoop(connection, (CommandLineOptions options) { |
| 54 expect(options.buildSummaryInputs, | 55 expect(options.buildSummaryInputs, |
| 55 unorderedEquals(['/tmp/1.sum', '/tmp/2.sum'])); | 56 unorderedEquals(['/tmp/1.sum', '/tmp/2.sum'])); |
| 56 expect( | 57 expect( |
| 57 options.sourceFiles, | 58 options.sourceFiles, |
| 58 unorderedEquals([ | 59 unorderedEquals([ |
| 59 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', | 60 'package:foo/foo.dart|/inputs/foo/lib/foo.dart', |
| 60 'package:foo/bar.dart|/inputs/foo/lib/bar.dart' | 61 'package:foo/bar.dart|/inputs/foo/lib/bar.dart' |
| 61 ])); | 62 ])); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 75 | 76 |
| 76 // Check that a serialized version was written to std out. | 77 // Check that a serialized version was written to std out. |
| 77 expect(stdoutStream.writes, hasLength(1)); | 78 expect(stdoutStream.writes, hasLength(1)); |
| 78 expect(stdoutStream.writes[0], _serializeProto(response)); | 79 expect(stdoutStream.writes[0], _serializeProto(response)); |
| 79 } | 80 } |
| 80 | 81 |
| 81 test_run_invalidOptions() { | 82 test_run_invalidOptions() { |
| 82 var request = new WorkRequest(); | 83 var request = new WorkRequest(); |
| 83 request.arguments.addAll(['--unknown-option', '/foo.dart', '/bar.dart']); | 84 request.arguments.addAll(['--unknown-option', '/foo.dart', '/bar.dart']); |
| 84 stdinStream.addInputBytes(_serializeProto(request)); | 85 stdinStream.addInputBytes(_serializeProto(request)); |
| 86 stdinStream.close(); |
| 85 new TestAnalyzerWorkerLoop(connection).run(); | 87 new TestAnalyzerWorkerLoop(connection).run(); |
| 86 expect(connection.responses, hasLength(1)); | 88 expect(connection.responses, hasLength(1)); |
| 87 | 89 |
| 88 var response = connection.responses[0]; | 90 var response = connection.responses[0]; |
| 89 expect(response.exitCode, EXIT_CODE_ERROR); | 91 expect(response.exitCode, EXIT_CODE_ERROR); |
| 90 expect(response.output, anything); | 92 expect(response.output, anything); |
| 91 } | 93 } |
| 92 | 94 |
| 93 test_run_invalidRequest_noArgumentsInputs() { | 95 test_run_invalidRequest_noArgumentsInputs() { |
| 94 stdinStream.addInputBytes(_serializeProto(new WorkRequest())); | 96 stdinStream.addInputBytes(_serializeProto(new WorkRequest())); |
| 97 stdinStream.close(); |
| 95 | 98 |
| 96 new TestAnalyzerWorkerLoop(connection).run(); | 99 new TestAnalyzerWorkerLoop(connection).run(); |
| 97 expect(connection.responses, hasLength(1)); | 100 expect(connection.responses, hasLength(1)); |
| 98 | 101 |
| 99 var response = connection.responses[0]; | 102 var response = connection.responses[0]; |
| 100 expect(response.exitCode, EXIT_CODE_ERROR); | 103 expect(response.exitCode, EXIT_CODE_ERROR); |
| 101 expect(response.output, anything); | 104 expect(response.output, anything); |
| 102 } | 105 } |
| 103 | 106 |
| 104 test_run_invalidRequest_randomBytes() { | 107 test_run_invalidRequest_randomBytes() { |
| 105 stdinStream.addInputBytes([1, 2, 3]); | 108 stdinStream.addInputBytes([1, 2, 3]); |
| 109 stdinStream.close(); |
| 106 new TestAnalyzerWorkerLoop(connection).run(); | 110 new TestAnalyzerWorkerLoop(connection).run(); |
| 107 expect(connection.responses, hasLength(1)); | 111 expect(connection.responses, hasLength(1)); |
| 108 | 112 |
| 109 var response = connection.responses[0]; | 113 var response = connection.responses[0]; |
| 110 expect(response.exitCode, EXIT_CODE_ERROR); | 114 expect(response.exitCode, EXIT_CODE_ERROR); |
| 111 expect(response.output, anything); | 115 expect(response.output, anything); |
| 112 } | 116 } |
| 113 | 117 |
| 114 test_run_stopAtEOF() { | 118 test_run_stopAtEOF() { |
| 115 stdinStream.addInputBytes([-1]); | 119 stdinStream.close(); |
| 116 new TestAnalyzerWorkerLoop(connection).run(); | 120 new TestAnalyzerWorkerLoop(connection).run(); |
| 117 } | 121 } |
| 118 } | 122 } |
| 119 | 123 |
| 120 typedef void _TestWorkerLoopAnalyze(CommandLineOptions options); | 124 typedef void _TestWorkerLoopAnalyze(CommandLineOptions options); |
| 121 | 125 |
| 122 /** | 126 /** |
| 123 * [AnalyzerWorkerLoop] for testing. | 127 * [AnalyzerWorkerLoop] for testing. |
| 124 */ | 128 */ |
| 125 class TestAnalyzerWorkerLoop extends AnalyzerWorkerLoop { | 129 class TestAnalyzerWorkerLoop extends AnalyzerWorkerLoop { |
| 126 final _TestWorkerLoopAnalyze _analyze; | 130 final _TestWorkerLoopAnalyze _analyze; |
| 127 | 131 |
| 128 TestAnalyzerWorkerLoop(SyncWorkerConnection connection, [this._analyze]) | 132 TestAnalyzerWorkerLoop(SyncWorkerConnection connection, [this._analyze]) |
| 129 : super(connection); | 133 : super(connection); |
| 130 | 134 |
| 131 @override | 135 @override |
| 132 void analyze(CommandLineOptions options) { | 136 void analyze(CommandLineOptions options) { |
| 133 if (_analyze != null) { | 137 if (_analyze != null) { |
| 134 _analyze(options); | 138 _analyze(options); |
| 135 } | 139 } |
| 136 } | 140 } |
| 137 } | 141 } |
| OLD | NEW |