| 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 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:bazel_worker/bazel_worker.dart'; | 9 import 'package:bazel_worker/bazel_worker.dart'; |
| 10 // TODO(jakemac): Remove once this is a part of the testing library. | 10 // TODO(jakemac): Remove once this is a part of the testing library. |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 test('can compile in basic mode', () { | 77 test('can compile in basic mode', () { |
| 78 var args = executableArgs.toList()..addAll(compilerArgs); | 78 var args = executableArgs.toList()..addAll(compilerArgs); |
| 79 var result = Process.runSync('dart', args); | 79 var result = Process.runSync('dart', args); |
| 80 | 80 |
| 81 expect(result.exitCode, EXIT_CODE_OK); | 81 expect(result.exitCode, EXIT_CODE_OK); |
| 82 expect(result.stdout, isEmpty); | 82 expect(result.stdout, isEmpty); |
| 83 expect(result.stderr, isEmpty); | 83 expect(result.stderr, isEmpty); |
| 84 expect(outputJsFile.existsSync(), isTrue); | 84 expect(outputJsFile.existsSync(), isTrue); |
| 85 }); | 85 }); |
| 86 | 86 |
| 87 test('unknown options', () { |
| 88 var args = new List<String>.from(executableArgs) |
| 89 ..add('--does-not-exist') |
| 90 ..addAll(compilerArgs); |
| 91 var result = Process.runSync('dart', args); |
| 92 |
| 93 expect(result.exitCode, 64); |
| 94 expect(result.stdout, |
| 95 contains('Could not find an option named "does-not-exist"')); |
| 96 expect(result.stderr, isEmpty); |
| 97 expect(outputJsFile.existsSync(), isFalse); |
| 98 }); |
| 99 |
| 100 test('unknown options ignored', () { |
| 101 var args = new List<String>.from(executableArgs) |
| 102 ..add('--does-not-exist') |
| 103 ..add('--ignore-unrecognized-flags') |
| 104 ..addAll(compilerArgs); |
| 105 var result = Process.runSync('dart', args); |
| 106 |
| 107 expect(result.exitCode, EXIT_CODE_OK); |
| 108 expect(result.stdout, isEmpty); |
| 109 expect(result.stderr, isEmpty); |
| 110 expect(outputJsFile.existsSync(), isTrue); |
| 111 }); |
| 112 |
| 87 test('can compile in basic mode with args in a file', () async { | 113 test('can compile in basic mode with args in a file', () async { |
| 88 argsFile.createSync(); | 114 argsFile.createSync(); |
| 89 argsFile.writeAsStringSync(compilerArgs.join('\n')); | 115 argsFile.writeAsStringSync(compilerArgs.join('\n')); |
| 90 var args = executableArgs.toList()..add('@${argsFile.path}'); | 116 var args = executableArgs.toList()..add('@${argsFile.path}'); |
| 91 var process = await Process.start('dart', args); | 117 var process = await Process.start('dart', args); |
| 92 stderr.addStream(process.stderr); | 118 stderr.addStream(process.stderr); |
| 93 var futureProcessOutput = process.stdout.map(UTF8.decode).toList(); | 119 var futureProcessOutput = process.stdout.map(UTF8.decode).toList(); |
| 94 | 120 |
| 95 expect(await process.exitCode, EXIT_CODE_OK); | 121 expect(await process.exitCode, EXIT_CODE_OK); |
| 96 expect((await futureProcessOutput).join(), isEmpty); | 122 expect((await futureProcessOutput).join(), isEmpty); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; | 188 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; |
| 163 final badFileDart = new File('test/worker/bad.dart').absolute; | 189 final badFileDart = new File('test/worker/bad.dart').absolute; |
| 164 final badFileJs = new File('test/worker/bad.js').absolute; | 190 final badFileJs = new File('test/worker/bad.js').absolute; |
| 165 | 191 |
| 166 tearDown(() { | 192 tearDown(() { |
| 167 if (badFileDart.existsSync()) badFileDart.deleteSync(); | 193 if (badFileDart.existsSync()) badFileDart.deleteSync(); |
| 168 if (badFileJs.existsSync()) badFileJs.deleteSync(); | 194 if (badFileJs.existsSync()) badFileJs.deleteSync(); |
| 169 }); | 195 }); |
| 170 | 196 |
| 171 test('incorrect usage', () { | 197 test('incorrect usage', () { |
| 172 var result = Process.runSync('dart', ['bin/dartdevc.dart', '--dart-sdk-sum
mary', dartSdkSummary.path, 'oops',]); | 198 var result = Process.runSync('dart', [ |
| 199 'bin/dartdevc.dart', |
| 200 '--dart-sdk-summary', |
| 201 dartSdkSummary.path, |
| 202 'oops', |
| 203 ]); |
| 173 expect(result.exitCode, 64); | 204 expect(result.exitCode, 64); |
| 174 expect( | 205 expect( |
| 175 result.stdout, contains('Please include the output file location.')); | 206 result.stdout, contains('Please include the output file location.')); |
| 176 expect(result.stdout, isNot(contains('#0'))); | 207 expect(result.stdout, isNot(contains('#0'))); |
| 177 }); | 208 }); |
| 178 | 209 |
| 179 test('compile errors', () { | 210 test('compile errors', () { |
| 180 badFileDart.writeAsStringSync('main() => "hello world"'); | 211 badFileDart.writeAsStringSync('main() => "hello world"'); |
| 181 var result = Process.runSync('dart', [ | 212 var result = Process.runSync('dart', [ |
| 182 'bin/dartdevc.dart', | 213 'bin/dartdevc.dart', |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { | 301 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { |
| 271 var buffer = (await messageGrouper.next) as List<int>; | 302 var buffer = (await messageGrouper.next) as List<int>; |
| 272 try { | 303 try { |
| 273 return new WorkResponse.fromBuffer(buffer); | 304 return new WorkResponse.fromBuffer(buffer); |
| 274 } catch (_) { | 305 } catch (_) { |
| 275 var bufferAsString = | 306 var bufferAsString = |
| 276 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; | 307 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; |
| 277 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; | 308 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; |
| 278 } | 309 } |
| 279 } | 310 } |
| OLD | NEW |