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

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

Issue 1930133002: Make parts hermetic, fixes #531 (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 4 years, 7 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
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 import 'package:dev_compiler/src/compiler/compiler.dart'
16 show missingPartErrorCode, unusedPartErrorCode;
17
15 main() { 18 main() {
16 group('Hello World', () { 19 group('Hello World', () {
17 final argsFile = new File('test/worker/hello_world.args').absolute; 20 final argsFile = new File('test/worker/hello_world.args').absolute;
18 final inputDartFile = new File('test/worker/hello_world.dart').absolute; 21 final inputDartFile = new File('test/worker/hello_world.dart').absolute;
19 final outputJsFile = new File('test/worker/hello_world.js').absolute; 22 final outputJsFile = new File('test/worker/hello_world.js').absolute;
20 final executableArgs = ['bin/dartdevc.dart', 'compile',]; 23 final executableArgs = ['bin/dartdevc.dart', 'compile',];
21 final compilerArgs = [ 24 final compilerArgs = [
22 '--no-source-map', 25 '--no-source-map',
23 '--no-summarize', 26 '--no-summarize',
24 '-o', 27 '-o',
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 'compile', 174 'compile',
172 '--no-source-map', 175 '--no-source-map',
173 '-o', 176 '-o',
174 badFileJs.path, 177 badFileJs.path,
175 badFileDart.path, 178 badFileDart.path,
176 ]); 179 ]);
177 expect(result.exitCode, 1); 180 expect(result.exitCode, 1);
178 expect(result.stdout, contains("[error] Expected to find ';'")); 181 expect(result.stdout, contains("[error] Expected to find ';'"));
179 }); 182 });
180 }); 183 });
184
185 group('Parts', () {
186 final partFile = new File('test/worker/greeting.dart').absolute;
187 final libraryFile = new File('test/worker/hello.dart').absolute;
188
189 final outJS = new File('test/worker/output.js').absolute;
190
191 setUp(() {
192 partFile.writeAsStringSync('part of hello;\n'
193 'String greeting = "hello";');
194 libraryFile.writeAsStringSync('library hello;\n'
195 'part "greeting.dart";\n'
196 'main() => print(greeting);\n');
197 });
198
199 tearDown(() {
200 if (partFile.existsSync()) partFile.deleteSync();
201 if (libraryFile.existsSync()) libraryFile.deleteSync();
202 if (outJS.existsSync()) outJS.deleteSync();
203 });
204
205 test('works if part and library supplied', () {
206 var result = Process.runSync('dart', [
207 'bin/dartdevc.dart',
208 'compile',
209 '--no-summarize',
210 '--no-source-map',
211 '-o',
212 outJS.path,
213 partFile.path,
214 libraryFile.path,
215 ]);
216 expect(result.stdout, isEmpty);
217 expect(result.stderr, isEmpty);
218 expect(result.exitCode, 0);
219 expect(outJS.existsSync(), isTrue);
220 });
221
222 test('error if part is not supplied', () {
223 var result = Process.runSync('dart', [
224 'bin/dartdevc.dart',
225 'compile',
226 '--no-summarize',
227 '--no-source-map',
228 '-o',
229 outJS.path,
230 libraryFile.path,
231 ]);
232 expect(
233 result.stdout,
234 startsWith('[error] ${missingPartErrorCode.message} '
235 '(test/worker/greeting.dart, line 1, col 1)'));
236 expect(result.stderr, isEmpty);
237 expect(result.exitCode, 1);
238 expect(outJS.existsSync(), isFalse);
239 });
240
241 test('error if part without library is supplied', () {
242 var result = Process.runSync('dart', [
243 'bin/dartdevc.dart',
244 'compile',
245 '--no-summarize',
246 '--no-source-map',
247 '-o',
248 outJS.path,
249 partFile.path,
250 ]);
251 expect(
252 result.stdout,
253 startsWith('[error] ${unusedPartErrorCode.message} '
254 '(test/worker/greeting.dart, line 1, col 1)'));
255 expect(result.stderr, isEmpty);
256 expect(result.exitCode, 1);
257 expect(outJS.existsSync(), isFalse);
258 });
259 });
181 } 260 }
182 261
183 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { 262 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async {
184 var buffer = await messageGrouper.next; 263 var buffer = await messageGrouper.next;
185 try { 264 try {
186 return new WorkResponse.fromBuffer(buffer); 265 return new WorkResponse.fromBuffer(buffer);
187 } catch (_) { 266 } catch (_) {
188 var bufferAsString = 267 var bufferAsString =
189 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; 268 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n';
190 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; 269 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString';
191 } 270 }
192 } 271 }
OLDNEW
« lib/src/compiler/compiler.dart ('K') | « lib/src/compiler/compiler.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698