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