| 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 import 'package:dev_compiler/src/compiler/compiler.dart' | |
| 16 show missingPartErrorCode, unusedPartWarningCode; | |
| 17 | |
| 18 main() { | 15 main() { |
| 19 group('Hello World', () { | 16 group('Hello World', () { |
| 20 final argsFile = new File('test/worker/hello_world.args').absolute; | 17 final argsFile = new File('test/worker/hello_world.args').absolute; |
| 21 final inputDartFile = new File('test/worker/hello_world.dart').absolute; | 18 final inputDartFile = new File('test/worker/hello_world.dart').absolute; |
| 22 final outputJsFile = new File('test/worker/hello_world.js').absolute; | 19 final outputJsFile = new File('test/worker/hello_world.js').absolute; |
| 23 final executableArgs = ['bin/dartdevc.dart', 'compile',]; | 20 final executableArgs = ['bin/dartdevc.dart', 'compile',]; |
| 24 final compilerArgs = [ | 21 final compilerArgs = [ |
| 25 '--no-source-map', | 22 '--no-source-map', |
| 26 '--no-summarize', | 23 '--no-summarize', |
| 27 '-o', | 24 '-o', |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 outJS.path, | 212 outJS.path, |
| 216 partFile.path, | 213 partFile.path, |
| 217 libraryFile.path, | 214 libraryFile.path, |
| 218 ]); | 215 ]); |
| 219 expect(result.stdout, isEmpty); | 216 expect(result.stdout, isEmpty); |
| 220 expect(result.stderr, isEmpty); | 217 expect(result.stderr, isEmpty); |
| 221 expect(result.exitCode, 0); | 218 expect(result.exitCode, 0); |
| 222 expect(outJS.existsSync(), isTrue); | 219 expect(outJS.existsSync(), isTrue); |
| 223 }); | 220 }); |
| 224 | 221 |
| 225 test('error if part is not supplied', () { | 222 test('works if part is not supplied', () { |
| 226 var result = Process.runSync('dart', [ | 223 var result = Process.runSync('dart', [ |
| 227 'bin/dartdevc.dart', | 224 'bin/dartdevc.dart', |
| 228 'compile', | 225 'compile', |
| 229 '--no-summarize', | 226 '--no-summarize', |
| 230 '--no-source-map', | 227 '--no-source-map', |
| 231 '-o', | 228 '-o', |
| 232 outJS.path, | 229 outJS.path, |
| 233 libraryFile.path, | 230 libraryFile.path, |
| 234 ]); | 231 ]); |
| 235 expect( | 232 expect(result.stdout, isEmpty); |
| 236 result.stdout, | |
| 237 startsWith('[error] ${missingPartErrorCode.message} ' | |
| 238 '(test/worker/greeting.dart, line 1, col 1)')); | |
| 239 expect(result.stderr, isEmpty); | 233 expect(result.stderr, isEmpty); |
| 240 expect(result.exitCode, 1); | 234 expect(result.exitCode, 0); |
| 241 expect(outJS.existsSync(), isFalse); | 235 expect(outJS.existsSync(), isTrue); |
| 242 }); | 236 }); |
| 243 | 237 |
| 244 test('warning if part without library is supplied', () { | 238 test('part without library is silently ignored', () { |
| 245 var result = Process.runSync('dart', [ | 239 var result = Process.runSync('dart', [ |
| 246 'bin/dartdevc.dart', | 240 'bin/dartdevc.dart', |
| 247 'compile', | 241 'compile', |
| 248 '--no-summarize', | 242 '--no-summarize', |
| 249 '--no-source-map', | 243 '--no-source-map', |
| 250 '-o', | 244 '-o', |
| 251 outJS.path, | 245 outJS.path, |
| 252 partFile.path, | 246 partFile.path, |
| 253 ]); | 247 ]); |
| 254 expect( | 248 expect(result.stdout, isEmpty); |
| 255 result.stdout, | |
| 256 startsWith('[warning] ${unusedPartWarningCode.message} ' | |
| 257 '(test/worker/greeting.dart, line 1, col 1)')); | |
| 258 expect(result.stderr, isEmpty); | 249 expect(result.stderr, isEmpty); |
| 259 expect(result.exitCode, 0); | 250 expect(result.exitCode, 0); |
| 260 expect(outJS.existsSync(), isTrue); | 251 expect(outJS.existsSync(), isTrue); |
| 261 }); | 252 }); |
| 262 }); | 253 }); |
| 263 } | 254 } |
| 264 | 255 |
| 265 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { | 256 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { |
| 266 var buffer = (await messageGrouper.next) as List<int>; | 257 var buffer = (await messageGrouper.next) as List<int>; |
| 267 try { | 258 try { |
| 268 return new WorkResponse.fromBuffer(buffer); | 259 return new WorkResponse.fromBuffer(buffer); |
| 269 } catch (_) { | 260 } catch (_) { |
| 270 var bufferAsString = | 261 var bufferAsString = |
| 271 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; | 262 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; |
| 272 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; | 263 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; |
| 273 } | 264 } |
| 274 } | 265 } |
| OLD | NEW |