| 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/hello_world.js').absolute; |
| 20 final executableArgs = ['bin/dartdevc.dart', 'compile',]; | 20 final executableArgs = ['bin/dartdevc.dart']; |
| 21 final compilerArgs = [ | 21 final compilerArgs = [ |
| 22 '--no-source-map', | 22 '--no-source-map', |
| 23 '--no-summarize', | 23 '--no-summarize', |
| 24 '-o', | 24 '-o', |
| 25 outputJsFile.path, | 25 outputJsFile.path, |
| 26 inputDartFile.path, | 26 inputDartFile.path, |
| 27 ]; | 27 ]; |
| 28 | 28 |
| 29 setUp(() { | 29 setUp(() { |
| 30 inputDartFile.createSync(); | 30 inputDartFile.createSync(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 if (greetingDart.existsSync()) greetingDart.deleteSync(); | 111 if (greetingDart.existsSync()) greetingDart.deleteSync(); |
| 112 if (helloDart.existsSync()) helloDart.deleteSync(); | 112 if (helloDart.existsSync()) helloDart.deleteSync(); |
| 113 if (greetingJS.existsSync()) greetingJS.deleteSync(); | 113 if (greetingJS.existsSync()) greetingJS.deleteSync(); |
| 114 if (greetingSummary.existsSync()) greetingSummary.deleteSync(); | 114 if (greetingSummary.existsSync()) greetingSummary.deleteSync(); |
| 115 if (helloJS.existsSync()) helloJS.deleteSync(); | 115 if (helloJS.existsSync()) helloJS.deleteSync(); |
| 116 }); | 116 }); |
| 117 | 117 |
| 118 test('can compile in basic mode', () { | 118 test('can compile in basic mode', () { |
| 119 var result = Process.runSync('dart', [ | 119 var result = Process.runSync('dart', [ |
| 120 'bin/dartdevc.dart', | 120 'bin/dartdevc.dart', |
| 121 'compile', | |
| 122 '--summary-extension=api.ds', | 121 '--summary-extension=api.ds', |
| 123 '--no-source-map', | 122 '--no-source-map', |
| 124 '-o', | 123 '-o', |
| 125 greetingJS.path, | 124 greetingJS.path, |
| 126 greetingDart.path, | 125 greetingDart.path, |
| 127 ]); | 126 ]); |
| 128 expect(result.exitCode, EXIT_CODE_OK); | 127 expect(result.exitCode, EXIT_CODE_OK); |
| 129 expect(result.stdout, isEmpty); | 128 expect(result.stdout, isEmpty); |
| 130 expect(result.stderr, isEmpty); | 129 expect(result.stderr, isEmpty); |
| 131 expect(greetingJS.existsSync(), isTrue); | 130 expect(greetingJS.existsSync(), isTrue); |
| 132 expect(greetingSummary.existsSync(), isTrue); | 131 expect(greetingSummary.existsSync(), isTrue); |
| 133 | 132 |
| 134 result = Process.runSync('dart', [ | 133 result = Process.runSync('dart', [ |
| 135 'bin/dartdevc.dart', | 134 'bin/dartdevc.dart', |
| 136 'compile', | |
| 137 '--no-source-map', | 135 '--no-source-map', |
| 138 '--no-summarize', | 136 '--no-summarize', |
| 139 '--summary-extension=api.ds', | 137 '--summary-extension=api.ds', |
| 140 '-s', | 138 '-s', |
| 141 greetingSummary.path, | 139 greetingSummary.path, |
| 142 '-o', | 140 '-o', |
| 143 helloJS.path, | 141 helloJS.path, |
| 144 helloDart.path, | 142 helloDart.path, |
| 145 ]); | 143 ]); |
| 146 expect(result.exitCode, EXIT_CODE_OK); | 144 expect(result.exitCode, EXIT_CODE_OK); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 164 expect(result.exitCode, 64); | 162 expect(result.exitCode, 64); |
| 165 expect( | 163 expect( |
| 166 result.stdout, contains('Please include the output file location.')); | 164 result.stdout, contains('Please include the output file location.')); |
| 167 expect(result.stdout, isNot(contains('#0'))); | 165 expect(result.stdout, isNot(contains('#0'))); |
| 168 }); | 166 }); |
| 169 | 167 |
| 170 test('compile errors', () { | 168 test('compile errors', () { |
| 171 badFileDart.writeAsStringSync('main() => "hello world"'); | 169 badFileDart.writeAsStringSync('main() => "hello world"'); |
| 172 var result = Process.runSync('dart', [ | 170 var result = Process.runSync('dart', [ |
| 173 'bin/dartdevc.dart', | 171 'bin/dartdevc.dart', |
| 174 'compile', | |
| 175 '--no-source-map', | 172 '--no-source-map', |
| 176 '-o', | 173 '-o', |
| 177 badFileJs.path, | 174 badFileJs.path, |
| 178 badFileDart.path, | 175 badFileDart.path, |
| 179 ]); | 176 ]); |
| 180 expect(result.exitCode, 1); | 177 expect(result.exitCode, 1); |
| 181 expect(result.stdout, contains("[error] Expected to find ';'")); | 178 expect(result.stdout, contains("[error] Expected to find ';'")); |
| 182 }); | 179 }); |
| 183 }); | 180 }); |
| 184 | 181 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 198 | 195 |
| 199 tearDown(() { | 196 tearDown(() { |
| 200 if (partFile.existsSync()) partFile.deleteSync(); | 197 if (partFile.existsSync()) partFile.deleteSync(); |
| 201 if (libraryFile.existsSync()) libraryFile.deleteSync(); | 198 if (libraryFile.existsSync()) libraryFile.deleteSync(); |
| 202 if (outJS.existsSync()) outJS.deleteSync(); | 199 if (outJS.existsSync()) outJS.deleteSync(); |
| 203 }); | 200 }); |
| 204 | 201 |
| 205 test('works if part and library supplied', () { | 202 test('works if part and library supplied', () { |
| 206 var result = Process.runSync('dart', [ | 203 var result = Process.runSync('dart', [ |
| 207 'bin/dartdevc.dart', | 204 'bin/dartdevc.dart', |
| 208 'compile', | |
| 209 '--no-summarize', | 205 '--no-summarize', |
| 210 '--no-source-map', | 206 '--no-source-map', |
| 211 '-o', | 207 '-o', |
| 212 outJS.path, | 208 outJS.path, |
| 213 partFile.path, | 209 partFile.path, |
| 214 libraryFile.path, | 210 libraryFile.path, |
| 215 ]); | 211 ]); |
| 216 expect(result.stdout, isEmpty); | 212 expect(result.stdout, isEmpty); |
| 217 expect(result.stderr, isEmpty); | 213 expect(result.stderr, isEmpty); |
| 218 expect(result.exitCode, 0); | 214 expect(result.exitCode, 0); |
| 219 expect(outJS.existsSync(), isTrue); | 215 expect(outJS.existsSync(), isTrue); |
| 220 }); | 216 }); |
| 221 | 217 |
| 222 test('works if part is not supplied', () { | 218 test('works if part is not supplied', () { |
| 223 var result = Process.runSync('dart', [ | 219 var result = Process.runSync('dart', [ |
| 224 'bin/dartdevc.dart', | 220 'bin/dartdevc.dart', |
| 225 'compile', | |
| 226 '--no-summarize', | 221 '--no-summarize', |
| 227 '--no-source-map', | 222 '--no-source-map', |
| 228 '-o', | 223 '-o', |
| 229 outJS.path, | 224 outJS.path, |
| 230 libraryFile.path, | 225 libraryFile.path, |
| 231 ]); | 226 ]); |
| 232 expect(result.stdout, isEmpty); | 227 expect(result.stdout, isEmpty); |
| 233 expect(result.stderr, isEmpty); | 228 expect(result.stderr, isEmpty); |
| 234 expect(result.exitCode, 0); | 229 expect(result.exitCode, 0); |
| 235 expect(outJS.existsSync(), isTrue); | 230 expect(outJS.existsSync(), isTrue); |
| 236 }); | 231 }); |
| 237 | 232 |
| 238 test('part without library is silently ignored', () { | 233 test('part without library is silently ignored', () { |
| 239 var result = Process.runSync('dart', [ | 234 var result = Process.runSync('dart', [ |
| 240 'bin/dartdevc.dart', | 235 'bin/dartdevc.dart', |
| 241 'compile', | |
| 242 '--no-summarize', | 236 '--no-summarize', |
| 243 '--no-source-map', | 237 '--no-source-map', |
| 244 '-o', | 238 '-o', |
| 245 outJS.path, | 239 outJS.path, |
| 246 partFile.path, | 240 partFile.path, |
| 247 ]); | 241 ]); |
| 248 expect(result.stdout, isEmpty); | 242 expect(result.stdout, isEmpty); |
| 249 expect(result.stderr, isEmpty); | 243 expect(result.stderr, isEmpty); |
| 250 expect(result.exitCode, 0); | 244 expect(result.exitCode, 0); |
| 251 expect(outJS.existsSync(), isTrue); | 245 expect(outJS.existsSync(), isTrue); |
| 252 }); | 246 }); |
| 253 }); | 247 }); |
| 254 } | 248 } |
| 255 | 249 |
| 256 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { | 250 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { |
| 257 var buffer = (await messageGrouper.next) as List<int>; | 251 var buffer = (await messageGrouper.next) as List<int>; |
| 258 try { | 252 try { |
| 259 return new WorkResponse.fromBuffer(buffer); | 253 return new WorkResponse.fromBuffer(buffer); |
| 260 } catch (_) { | 254 } catch (_) { |
| 261 var bufferAsString = | 255 var bufferAsString = |
| 262 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; | 256 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; |
| 263 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; | 257 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; |
| 264 } | 258 } |
| 265 } | 259 } |
| OLD | NEW |