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. |
11 import 'package:bazel_worker/src/async_message_grouper.dart'; | 11 import 'package:bazel_worker/src/async_message_grouper.dart'; |
12 import 'package:bazel_worker/testing.dart'; | 12 import 'package:bazel_worker/testing.dart'; |
13 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 group('Hello World', () { | 16 group('Hello World', () { |
17 final argsFile = new File('test/worker/hello_world.args').absolute; | 17 final argsFile = new File('test/worker/hello_world.args').absolute; |
18 final inputDartFile = new File('test/worker/hello_world.dart').absolute; | 18 final inputDartFile = new File('test/worker/hello_world.dart').absolute; |
19 final outputJsFile = new File('test/worker/hello_world.js').absolute; | 19 final outputJsFile = new File('test/worker/out/hello_world.js').absolute; |
20 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; | 20 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; |
21 final executableArgs = ['bin/dartdevc.dart']; | 21 final executableArgs = ['bin/dartdevc.dart']; |
22 final compilerArgs = [ | 22 final compilerArgs = [ |
23 '--no-source-map', | 23 '--no-source-map', |
24 '--no-summarize', | 24 '--no-summarize', |
25 '--dart-sdk-summary', | 25 '--dart-sdk-summary', |
26 dartSdkSummary.path, | 26 dartSdkSummary.path, |
27 '-o', | 27 '-o', |
28 outputJsFile.path, | 28 outputJsFile.path, |
29 inputDartFile.path, | 29 inputDartFile.path, |
30 ]; | 30 ]; |
31 | 31 |
32 setUp(() { | 32 setUp(() { |
33 inputDartFile.createSync(); | 33 inputDartFile.createSync(); |
34 inputDartFile.writeAsStringSync('main() => print("hello world");'); | 34 inputDartFile.writeAsStringSync('main() => print("hello world");'); |
35 }); | 35 }); |
36 | 36 |
37 tearDown(() { | 37 tearDown(() { |
38 if (inputDartFile.existsSync()) inputDartFile.deleteSync(); | 38 if (inputDartFile.existsSync()) inputDartFile.deleteSync(); |
39 if (outputJsFile.existsSync()) outputJsFile.deleteSync(); | 39 if (outputJsFile.parent.existsSync()) { |
40 outputJsFile.parent.deleteSync(recursive: true); | |
kevmoo
2016/11/08 02:51:30
Huh? This seems – bad.
Are we sure this directory
Jennifer Messerly
2016/11/08 18:11:51
it's a test folder, so yes (we're in "worker_test.
kevmoo
2016/11/08 18:16:47
*sigh* Sorry. Paranoid. :-)
| |
41 } | |
40 if (argsFile.existsSync()) argsFile.deleteSync(); | 42 if (argsFile.existsSync()) argsFile.deleteSync(); |
41 }); | 43 }); |
42 | 44 |
43 test('can compile in worker mode', () async { | 45 test('can compile in worker mode', () async { |
44 var args = executableArgs.toList()..add('--persistent_worker'); | 46 var args = executableArgs.toList()..add('--persistent_worker'); |
45 var process = await Process.start('dart', args); | 47 var process = await Process.start('dart', args); |
46 var messageGrouper = new AsyncMessageGrouper(process.stdout); | 48 var messageGrouper = new AsyncMessageGrouper(process.stdout); |
47 | 49 |
48 var request = new WorkRequest(); | 50 var request = new WorkRequest(); |
49 request.arguments.addAll(compilerArgs); | 51 request.arguments.addAll(compilerArgs); |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { | 270 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { |
269 var buffer = (await messageGrouper.next) as List<int>; | 271 var buffer = (await messageGrouper.next) as List<int>; |
270 try { | 272 try { |
271 return new WorkResponse.fromBuffer(buffer); | 273 return new WorkResponse.fromBuffer(buffer); |
272 } catch (_) { | 274 } catch (_) { |
273 var bufferAsString = | 275 var bufferAsString = |
274 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; | 276 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; |
275 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; | 277 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; |
276 } | 278 } |
277 } | 279 } |
OLD | NEW |