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

Side by Side Diff: test/worker/worker_test.dart

Issue 1896613002: Move all args to per-request for the worker, and add a test (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: use exit code 70 for internal errors Created 4 years, 8 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 | « lib/src/compiler/command.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 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 inputDartFile = new File('test/worker/hello_world.dart').absolute; 18 final inputDartFile = new File('test/worker/hello_world.dart').absolute;
18 final outputJsFile = new File('test/worker/hello_world.js').absolute; 19 final outputJsFile = new File('test/worker/hello_world.js').absolute;
19 final executableArgs = [ 20 final executableArgs = ['bin/dartdevc.dart', 'compile',];
20 'bin/dartdevc.dart',
21 'compile',
22 ];
23 final compilerArgs = [ 21 final compilerArgs = [
24 '--no-source-map', 22 '--no-source-map',
25 '--no-summarize', 23 '--no-summarize',
26 '-o', 24 '-o',
27 outputJsFile.path, 25 outputJsFile.path,
28 inputDartFile.path, 26 inputDartFile.path,
29 ]; 27 ];
30 28
31 setUp(() { 29 setUp(() {
32 inputDartFile.createSync(); 30 inputDartFile.createSync();
33 inputDartFile.writeAsStringSync('main() => print("hello world");'); 31 inputDartFile.writeAsStringSync('main() => print("hello world");');
34 }); 32 });
35 33
36 tearDown(() { 34 tearDown(() {
37 if (inputDartFile.existsSync()) inputDartFile.deleteSync(); 35 if (inputDartFile.existsSync()) inputDartFile.deleteSync();
38 if (outputJsFile.existsSync()) outputJsFile.deleteSync(); 36 if (outputJsFile.existsSync()) outputJsFile.deleteSync();
37 if (argsFile.existsSync()) argsFile.deleteSync();
39 }); 38 });
40 39
41 test('can compile in worker mode', () async { 40 test('can compile in worker mode', () async {
42 var args = new List.from(executableArgs)..add('--persistent_worker'); 41 var args = new List.from(executableArgs)..add('--persistent_worker');
43 var process = await Process.start('dart', args); 42 var process = await Process.start('dart', args);
44 var messageGrouper = new AsyncMessageGrouper(process.stdout); 43 var messageGrouper = new AsyncMessageGrouper(process.stdout);
45 44
46 var request = new WorkRequest(); 45 var request = new WorkRequest();
47 request.arguments.addAll(compilerArgs); 46 request.arguments.addAll(compilerArgs);
48 process.stdin.add(protoToDelimitedBuffer(request)); 47 process.stdin.add(protoToDelimitedBuffer(request));
(...skipping 23 matching lines...) Expand all
72 71
73 test('can compile in basic mode', () { 72 test('can compile in basic mode', () {
74 var args = new List.from(executableArgs)..addAll(compilerArgs); 73 var args = new List.from(executableArgs)..addAll(compilerArgs);
75 var result = Process.runSync('dart', args); 74 var result = Process.runSync('dart', args);
76 75
77 expect(result.exitCode, EXIT_CODE_OK); 76 expect(result.exitCode, EXIT_CODE_OK);
78 expect(result.stdout, isEmpty); 77 expect(result.stdout, isEmpty);
79 expect(result.stderr, isEmpty); 78 expect(result.stderr, isEmpty);
80 expect(outputJsFile.existsSync(), isTrue); 79 expect(outputJsFile.existsSync(), isTrue);
81 }); 80 });
81
82 test('can compile in basic mode with args in a file', () async {
83 argsFile.createSync();
84 argsFile.writeAsStringSync(compilerArgs.join('\n'));
85 var args = new List.from(executableArgs)..add('@${argsFile.path}');
86 var process = await Process.start('dart', args);
87 stderr.addStream(process.stderr);
88 var futureProcessOutput = process.stdout.map(UTF8.decode).toList();
89
90 expect(await process.exitCode, EXIT_CODE_OK);
91 expect((await futureProcessOutput).join(), isEmpty);
92 expect(outputJsFile.existsSync(), isTrue);
93 });
82 }); 94 });
83 95
84 group('Hello World with Summaries', () { 96 group('Hello World with Summaries', () {
85 final greetingDart = new File('test/worker/greeting.dart').absolute; 97 final greetingDart = new File('test/worker/greeting.dart').absolute;
86 final helloDart = new File('test/worker/hello.dart').absolute; 98 final helloDart = new File('test/worker/hello.dart').absolute;
87 99
88 final greetingJS = new File('test/worker/greeting.js').absolute; 100 final greetingJS = new File('test/worker/greeting.js').absolute;
89 final greetingSummary = new File('test/worker/greeting.sum').absolute; 101 final greetingSummary = new File('test/worker/greeting.sum').absolute;
90 final helloJS = new File('test/worker/hello_world.js').absolute; 102 final helloJS = new File('test/worker/hello_world.js').absolute;
91 103
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 expect(helloJS.existsSync(), isTrue); 148 expect(helloJS.existsSync(), isTrue);
137 }); 149 });
138 }); 150 });
139 } 151 }
140 152
141 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { 153 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async {
142 var buffer = await messageGrouper.next; 154 var buffer = await messageGrouper.next;
143 try { 155 try {
144 return new WorkResponse.fromBuffer(buffer); 156 return new WorkResponse.fromBuffer(buffer);
145 } catch (_) { 157 } catch (_) {
146 throw 'Failed to parse response: \n' 158 var bufferAsString =
147 'bytes: $buffer\n' 159 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n';
148 'String: ${new String.fromCharCodes(buffer)}\n'; 160 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString';
149 } 161 }
150 } 162 }
OLDNEW
« no previous file with comments | « lib/src/compiler/command.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698