| 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. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 tearDown(() { | 37 tearDown(() { |
| 38 if (inputDartFile.existsSync()) inputDartFile.deleteSync(); | 38 if (inputDartFile.existsSync()) inputDartFile.deleteSync(); |
| 39 if (outputJsFile.parent.existsSync()) { | 39 if (outputJsFile.parent.existsSync()) { |
| 40 outputJsFile.parent.deleteSync(recursive: true); | 40 outputJsFile.parent.deleteSync(recursive: true); |
| 41 } | 41 } |
| 42 if (argsFile.existsSync()) argsFile.deleteSync(); | 42 if (argsFile.existsSync()) argsFile.deleteSync(); |
| 43 }); | 43 }); |
| 44 | 44 |
| 45 test('can compile in worker mode', () async { | 45 test('can compile in worker mode', () async { |
| 46 var args = executableArgs.toList()..add('--persistent_worker'); | 46 var args = executableArgs.toList()..add('--persistent_worker'); |
| 47 var process = await Process.start('dart', args); | 47 var process = await Process.start(Platform.executable, args); |
| 48 var messageGrouper = new AsyncMessageGrouper(process.stdout); | 48 var messageGrouper = new AsyncMessageGrouper(process.stdout); |
| 49 | 49 |
| 50 var request = new WorkRequest(); | 50 var request = new WorkRequest(); |
| 51 request.arguments.addAll(compilerArgs); | 51 request.arguments.addAll(compilerArgs); |
| 52 process.stdin.add(protoToDelimitedBuffer(request)); | 52 process.stdin.add(protoToDelimitedBuffer(request)); |
| 53 | 53 |
| 54 var response = await _readResponse(messageGrouper); | 54 var response = await _readResponse(messageGrouper); |
| 55 expect(response.exitCode, EXIT_CODE_OK, reason: response.output); | 55 expect(response.exitCode, EXIT_CODE_OK, reason: response.output); |
| 56 expect(response.output, isEmpty); | 56 expect(response.output, isEmpty); |
| 57 | 57 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 69 | 69 |
| 70 process.kill(); | 70 process.kill(); |
| 71 | 71 |
| 72 // TODO(jakemac): This shouldn't be necessary, but it is for the process | 72 // TODO(jakemac): This shouldn't be necessary, but it is for the process |
| 73 // to exit properly. | 73 // to exit properly. |
| 74 expect(await messageGrouper.next, isNull); | 74 expect(await messageGrouper.next, isNull); |
| 75 }); | 75 }); |
| 76 | 76 |
| 77 test('can compile in basic mode', () { | 77 test('can compile in basic mode', () { |
| 78 var args = executableArgs.toList()..addAll(compilerArgs); | 78 var args = executableArgs.toList()..addAll(compilerArgs); |
| 79 var result = Process.runSync('dart', args); | 79 var result = Process.runSync(Platform.executable, args); |
| 80 | 80 |
| 81 expect(result.exitCode, EXIT_CODE_OK); | 81 expect(result.exitCode, EXIT_CODE_OK); |
| 82 expect(result.stdout, isEmpty); | 82 expect(result.stdout, isEmpty); |
| 83 expect(result.stderr, isEmpty); | 83 expect(result.stderr, isEmpty); |
| 84 expect(outputJsFile.existsSync(), isTrue); | 84 expect(outputJsFile.existsSync(), isTrue); |
| 85 }); | 85 }); |
| 86 | 86 |
| 87 test('unknown options', () { | 87 test('unknown options', () { |
| 88 var args = new List<String>.from(executableArgs) | 88 var args = new List<String>.from(executableArgs) |
| 89 ..add('--does-not-exist') | 89 ..add('--does-not-exist') |
| 90 ..addAll(compilerArgs); | 90 ..addAll(compilerArgs); |
| 91 var result = Process.runSync('dart', args); | 91 var result = Process.runSync(Platform.executable, args); |
| 92 | 92 |
| 93 expect(result.exitCode, 64); | 93 expect(result.exitCode, 64); |
| 94 expect(result.stdout, | 94 expect(result.stdout, |
| 95 contains('Could not find an option named "does-not-exist"')); | 95 contains('Could not find an option named "does-not-exist"')); |
| 96 expect(result.stderr, isEmpty); | 96 expect(result.stderr, isEmpty); |
| 97 expect(outputJsFile.existsSync(), isFalse); | 97 expect(outputJsFile.existsSync(), isFalse); |
| 98 }); | 98 }); |
| 99 | 99 |
| 100 test('unknown options ignored', () { | 100 test('unknown options ignored', () { |
| 101 var args = new List<String>.from(executableArgs) | 101 var args = new List<String>.from(executableArgs) |
| 102 ..add('--does-not-exist') | 102 ..add('--does-not-exist') |
| 103 ..add('--ignore-unrecognized-flags') | 103 ..add('--ignore-unrecognized-flags') |
| 104 ..addAll(compilerArgs); | 104 ..addAll(compilerArgs); |
| 105 var result = Process.runSync('dart', args); | 105 var result = Process.runSync(Platform.executable, args); |
| 106 | 106 |
| 107 expect(result.exitCode, EXIT_CODE_OK); | 107 expect(result.exitCode, EXIT_CODE_OK); |
| 108 expect(result.stdout, isEmpty); | 108 expect(result.stdout, isEmpty); |
| 109 expect(result.stderr, isEmpty); | 109 expect(result.stderr, isEmpty); |
| 110 expect(outputJsFile.existsSync(), isTrue); | 110 expect(outputJsFile.existsSync(), isTrue); |
| 111 }); | 111 }); |
| 112 | 112 |
| 113 test('can compile in basic mode with args in a file', () async { | 113 test('can compile in basic mode with args in a file', () async { |
| 114 argsFile.createSync(); | 114 argsFile.createSync(); |
| 115 argsFile.writeAsStringSync(compilerArgs.join('\n')); | 115 argsFile.writeAsStringSync(compilerArgs.join('\n')); |
| 116 var args = executableArgs.toList()..add('@${argsFile.path}'); | 116 var args = executableArgs.toList()..add('@${argsFile.path}'); |
| 117 var process = await Process.start('dart', args); | 117 var process = await Process.start(Platform.executable, args); |
| 118 stderr.addStream(process.stderr); | 118 stderr.addStream(process.stderr); |
| 119 var futureProcessOutput = process.stdout.map(UTF8.decode).toList(); | 119 var futureProcessOutput = process.stdout.map(UTF8.decode).toList(); |
| 120 | 120 |
| 121 expect(await process.exitCode, EXIT_CODE_OK); | 121 expect(await process.exitCode, EXIT_CODE_OK); |
| 122 expect((await futureProcessOutput).join(), isEmpty); | 122 expect((await futureProcessOutput).join(), isEmpty); |
| 123 expect(outputJsFile.existsSync(), isTrue); | 123 expect(outputJsFile.existsSync(), isTrue); |
| 124 }); | 124 }); |
| 125 }); | 125 }); |
| 126 | 126 |
| 127 group('Hello World with Summaries', () { | 127 group('Hello World with Summaries', () { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 141 tearDown(() { | 141 tearDown(() { |
| 142 if (greetingDart.existsSync()) greetingDart.deleteSync(); | 142 if (greetingDart.existsSync()) greetingDart.deleteSync(); |
| 143 if (helloDart.existsSync()) helloDart.deleteSync(); | 143 if (helloDart.existsSync()) helloDart.deleteSync(); |
| 144 if (greetingJS.existsSync()) greetingJS.deleteSync(); | 144 if (greetingJS.existsSync()) greetingJS.deleteSync(); |
| 145 if (greetingSummary.existsSync()) greetingSummary.deleteSync(); | 145 if (greetingSummary.existsSync()) greetingSummary.deleteSync(); |
| 146 if (helloJS.existsSync()) helloJS.deleteSync(); | 146 if (helloJS.existsSync()) helloJS.deleteSync(); |
| 147 }); | 147 }); |
| 148 | 148 |
| 149 test('can compile in basic mode', () { | 149 test('can compile in basic mode', () { |
| 150 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; | 150 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; |
| 151 var result = Process.runSync('dart', [ | 151 var result = Process.runSync(Platform.executable, [ |
| 152 'bin/dartdevc.dart', | 152 'bin/dartdevc.dart', |
| 153 '--summary-extension=api.ds', | 153 '--summary-extension=api.ds', |
| 154 '--no-source-map', | 154 '--no-source-map', |
| 155 '--dart-sdk-summary', | 155 '--dart-sdk-summary', |
| 156 dartSdkSummary.path, | 156 dartSdkSummary.path, |
| 157 '-o', | 157 '-o', |
| 158 greetingJS.path, | 158 greetingJS.path, |
| 159 greetingDart.path, | 159 greetingDart.path, |
| 160 ]); | 160 ]); |
| 161 expect(result.exitCode, EXIT_CODE_OK); | 161 expect(result.exitCode, EXIT_CODE_OK); |
| 162 expect(result.stdout, isEmpty); | 162 expect(result.stdout, isEmpty); |
| 163 expect(result.stderr, isEmpty); | 163 expect(result.stderr, isEmpty); |
| 164 expect(greetingJS.existsSync(), isTrue); | 164 expect(greetingJS.existsSync(), isTrue); |
| 165 expect(greetingSummary.existsSync(), isTrue); | 165 expect(greetingSummary.existsSync(), isTrue); |
| 166 | 166 |
| 167 result = Process.runSync('dart', [ | 167 result = Process.runSync(Platform.executable, [ |
| 168 'bin/dartdevc.dart', | 168 'bin/dartdevc.dart', |
| 169 '--no-source-map', | 169 '--no-source-map', |
| 170 '--no-summarize', | 170 '--no-summarize', |
| 171 '--dart-sdk-summary', | 171 '--dart-sdk-summary', |
| 172 dartSdkSummary.path, | 172 dartSdkSummary.path, |
| 173 '--summary-extension=api.ds', | 173 '--summary-extension=api.ds', |
| 174 '-s', | 174 '-s', |
| 175 greetingSummary.path, | 175 greetingSummary.path, |
| 176 '-o', | 176 '-o', |
| 177 helloJS.path, | 177 helloJS.path, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 188 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; | 188 final dartSdkSummary = new File('lib/sdk/ddc_sdk.sum').absolute; |
| 189 final badFileDart = new File('test/worker/bad.dart').absolute; | 189 final badFileDart = new File('test/worker/bad.dart').absolute; |
| 190 final badFileJs = new File('test/worker/bad.js').absolute; | 190 final badFileJs = new File('test/worker/bad.js').absolute; |
| 191 | 191 |
| 192 tearDown(() { | 192 tearDown(() { |
| 193 if (badFileDart.existsSync()) badFileDart.deleteSync(); | 193 if (badFileDart.existsSync()) badFileDart.deleteSync(); |
| 194 if (badFileJs.existsSync()) badFileJs.deleteSync(); | 194 if (badFileJs.existsSync()) badFileJs.deleteSync(); |
| 195 }); | 195 }); |
| 196 | 196 |
| 197 test('incorrect usage', () { | 197 test('incorrect usage', () { |
| 198 var result = Process.runSync('dart', [ | 198 var result = Process.runSync(Platform.executable, [ |
| 199 'bin/dartdevc.dart', | 199 'bin/dartdevc.dart', |
| 200 '--dart-sdk-summary', | 200 '--dart-sdk-summary', |
| 201 dartSdkSummary.path, | 201 dartSdkSummary.path, |
| 202 'oops', | 202 'oops', |
| 203 ]); | 203 ]); |
| 204 expect(result.exitCode, 64); | 204 expect(result.exitCode, 64); |
| 205 expect( | 205 expect( |
| 206 result.stdout, contains('Please include the output file location.')); | 206 result.stdout, contains('Please include the output file location.')); |
| 207 expect(result.stdout, isNot(contains('#0'))); | 207 expect(result.stdout, isNot(contains('#0'))); |
| 208 }); | 208 }); |
| 209 | 209 |
| 210 test('compile errors', () { | 210 test('compile errors', () { |
| 211 badFileDart.writeAsStringSync('main() => "hello world"'); | 211 badFileDart.writeAsStringSync('main() => "hello world"'); |
| 212 var result = Process.runSync('dart', [ | 212 var result = Process.runSync(Platform.executable, [ |
| 213 'bin/dartdevc.dart', | 213 'bin/dartdevc.dart', |
| 214 '--no-source-map', | 214 '--no-source-map', |
| 215 '--dart-sdk-summary', | 215 '--dart-sdk-summary', |
| 216 dartSdkSummary.path, | 216 dartSdkSummary.path, |
| 217 '-o', | 217 '-o', |
| 218 badFileJs.path, | 218 badFileJs.path, |
| 219 badFileDart.path, | 219 badFileDart.path, |
| 220 ]); | 220 ]); |
| 221 expect(result.exitCode, 1); | 221 expect(result.exitCode, 1); |
| 222 expect(result.stdout, contains("[error] Expected to find ';'")); | 222 expect(result.stdout, contains("[error] Expected to find ';'")); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 238 'main() => print(greeting);\n'); | 238 'main() => print(greeting);\n'); |
| 239 }); | 239 }); |
| 240 | 240 |
| 241 tearDown(() { | 241 tearDown(() { |
| 242 if (partFile.existsSync()) partFile.deleteSync(); | 242 if (partFile.existsSync()) partFile.deleteSync(); |
| 243 if (libraryFile.existsSync()) libraryFile.deleteSync(); | 243 if (libraryFile.existsSync()) libraryFile.deleteSync(); |
| 244 if (outJS.existsSync()) outJS.deleteSync(); | 244 if (outJS.existsSync()) outJS.deleteSync(); |
| 245 }); | 245 }); |
| 246 | 246 |
| 247 test('works if part and library supplied', () { | 247 test('works if part and library supplied', () { |
| 248 var result = Process.runSync('dart', [ | 248 var result = Process.runSync(Platform.executable, [ |
| 249 'bin/dartdevc.dart', | 249 'bin/dartdevc.dart', |
| 250 '--no-summarize', | 250 '--no-summarize', |
| 251 '--no-source-map', | 251 '--no-source-map', |
| 252 '--dart-sdk-summary', | 252 '--dart-sdk-summary', |
| 253 dartSdkSummary.path, | 253 dartSdkSummary.path, |
| 254 '-o', | 254 '-o', |
| 255 outJS.path, | 255 outJS.path, |
| 256 partFile.path, | 256 partFile.path, |
| 257 libraryFile.path, | 257 libraryFile.path, |
| 258 ]); | 258 ]); |
| 259 expect(result.stdout, isEmpty); | 259 expect(result.stdout, isEmpty); |
| 260 expect(result.stderr, isEmpty); | 260 expect(result.stderr, isEmpty); |
| 261 expect(result.exitCode, 0); | 261 expect(result.exitCode, 0); |
| 262 expect(outJS.existsSync(), isTrue); | 262 expect(outJS.existsSync(), isTrue); |
| 263 }); | 263 }); |
| 264 | 264 |
| 265 test('works if part is not supplied', () { | 265 test('works if part is not supplied', () { |
| 266 var result = Process.runSync('dart', [ | 266 var result = Process.runSync(Platform.executable, [ |
| 267 'bin/dartdevc.dart', | 267 'bin/dartdevc.dart', |
| 268 '--no-summarize', | 268 '--no-summarize', |
| 269 '--no-source-map', | 269 '--no-source-map', |
| 270 '--dart-sdk-summary', | 270 '--dart-sdk-summary', |
| 271 dartSdkSummary.path, | 271 dartSdkSummary.path, |
| 272 '-o', | 272 '-o', |
| 273 outJS.path, | 273 outJS.path, |
| 274 libraryFile.path, | 274 libraryFile.path, |
| 275 ]); | 275 ]); |
| 276 expect(result.stdout, isEmpty); | 276 expect(result.stdout, isEmpty); |
| 277 expect(result.stderr, isEmpty); | 277 expect(result.stderr, isEmpty); |
| 278 expect(result.exitCode, 0); | 278 expect(result.exitCode, 0); |
| 279 expect(outJS.existsSync(), isTrue); | 279 expect(outJS.existsSync(), isTrue); |
| 280 }); | 280 }); |
| 281 | 281 |
| 282 test('part without library is silently ignored', () { | 282 test('part without library is silently ignored', () { |
| 283 var result = Process.runSync('dart', [ | 283 var result = Process.runSync(Platform.executable, [ |
| 284 'bin/dartdevc.dart', | 284 'bin/dartdevc.dart', |
| 285 '--no-summarize', | 285 '--no-summarize', |
| 286 '--no-source-map', | 286 '--no-source-map', |
| 287 '--dart-sdk-summary', | 287 '--dart-sdk-summary', |
| 288 dartSdkSummary.path, | 288 dartSdkSummary.path, |
| 289 '-o', | 289 '-o', |
| 290 outJS.path, | 290 outJS.path, |
| 291 partFile.path, | 291 partFile.path, |
| 292 ]); | 292 ]); |
| 293 expect(result.stdout, isEmpty); | 293 expect(result.stdout, isEmpty); |
| 294 expect(result.stderr, isEmpty); | 294 expect(result.stderr, isEmpty); |
| 295 expect(result.exitCode, 0); | 295 expect(result.exitCode, 0); |
| 296 expect(outJS.existsSync(), isTrue); | 296 expect(outJS.existsSync(), isTrue); |
| 297 }); | 297 }); |
| 298 }); | 298 }); |
| 299 } | 299 } |
| 300 | 300 |
| 301 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { | 301 Future<WorkResponse> _readResponse(MessageGrouper messageGrouper) async { |
| 302 var buffer = (await messageGrouper.next) as List<int>; | 302 var buffer = (await messageGrouper.next) as List<int>; |
| 303 try { | 303 try { |
| 304 return new WorkResponse.fromBuffer(buffer); | 304 return new WorkResponse.fromBuffer(buffer); |
| 305 } catch (_) { | 305 } catch (_) { |
| 306 var bufferAsString = | 306 var bufferAsString = |
| 307 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; | 307 buffer == null ? '' : 'String: ${UTF8.decode(buffer)}\n'; |
| 308 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; | 308 throw 'Failed to parse response:\nbytes: $buffer\n$bufferAsString'; |
| 309 } | 309 } |
| 310 } | 310 } |
| OLD | NEW |