| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 | 6 |
| 7 import 'package:front_end/compiler_options.dart'; | 7 import 'package:front_end/compiler_options.dart'; |
| 8 import 'package:front_end/incremental_kernel_generator.dart'; | 8 import 'package:front_end/incremental_kernel_generator.dart'; |
| 9 import 'package:front_end/memory_file_system.dart'; | 9 import 'package:front_end/memory_file_system.dart'; |
| 10 import 'package:front_end/src/byte_store/byte_store.dart'; | 10 import 'package:front_end/src/byte_store/byte_store.dart'; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 compilerOptions.packagesFileUri = Uri.parse('file:///test/.packages'); | 53 compilerOptions.packagesFileUri = Uri.parse('file:///test/.packages'); |
| 54 } | 54 } |
| 55 incrementalKernelGenerator = await IncrementalKernelGenerator | 55 incrementalKernelGenerator = await IncrementalKernelGenerator |
| 56 .newInstance(compilerOptions, entryPoint, watch: watchFn); | 56 .newInstance(compilerOptions, entryPoint, watch: watchFn); |
| 57 return (await incrementalKernelGenerator.computeDelta()).newProgram; | 57 return (await incrementalKernelGenerator.computeDelta()).newProgram; |
| 58 } | 58 } |
| 59 | 59 |
| 60 test_acceptLastDelta() async { | 60 test_acceptLastDelta() async { |
| 61 writeFile('/test/.packages', 'test:lib/'); | 61 writeFile('/test/.packages', 'test:lib/'); |
| 62 String path = '/test/lib/test.dart'; | 62 String path = '/test/lib/test.dart'; |
| 63 Uri uri = writeFile(path, 'var v = 1;'); | 63 Uri uri = writeFile(path, ''); |
| 64 | 64 |
| 65 await getInitialState(uri); | 65 await getInitialState(uri); |
| 66 incrementalKernelGenerator.acceptLastDelta(); | 66 incrementalKernelGenerator.acceptLastDelta(); |
| 67 | 67 |
| 68 // Attempt to accept the second time. | 68 // Attempt to accept the second time. |
| 69 expect(() { | 69 _assertStateError(() { |
| 70 incrementalKernelGenerator.acceptLastDelta(); | 70 incrementalKernelGenerator.acceptLastDelta(); |
| 71 }, throwsStateError); | 71 }, IncrementalKernelGeneratorImpl.MSG_NO_LAST_DELTA); |
| 72 } | 72 } |
| 73 | 73 |
| 74 test_compile_chain() async { | 74 test_compile_chain() async { |
| 75 writeFile('/test/.packages', 'test:lib/'); | 75 writeFile('/test/.packages', 'test:lib/'); |
| 76 String aPath = '/test/lib/a.dart'; | 76 String aPath = '/test/lib/a.dart'; |
| 77 String bPath = '/test/lib/b.dart'; | 77 String bPath = '/test/lib/b.dart'; |
| 78 String cPath = '/test/lib/c.dart'; | 78 String cPath = '/test/lib/c.dart'; |
| 79 Uri aUri = writeFile(aPath, 'var a = 1;'); | 79 Uri aUri = writeFile(aPath, 'var a = 1;'); |
| 80 Uri bUri = writeFile(bPath, r''' | 80 Uri bUri = writeFile(bPath, r''' |
| 81 import 'a.dart'; | 81 import 'a.dart'; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 expect(_getLibraryText(library), r'''library; | 216 expect(_getLibraryText(library), r'''library; |
| 217 import self as self; | 217 import self as self; |
| 218 import "dart:core" as core; | 218 import "dart:core" as core; |
| 219 import "dart:async" as asy; | 219 import "dart:async" as asy; |
| 220 | 220 |
| 221 static field core::int a = 1; | 221 static field core::int a = 1; |
| 222 static field asy::Future<core::String> b; | 222 static field asy::Future<core::String> b; |
| 223 '''); | 223 '''); |
| 224 } | 224 } |
| 225 | 225 |
| 226 test_computeDelta_hasAnotherRunning() async { |
| 227 writeFile('/test/.packages', 'test:lib/'); |
| 228 String path = '/test/lib/test.dart'; |
| 229 Uri uri = writeFile(path, ''); |
| 230 |
| 231 await getInitialState(uri); |
| 232 incrementalKernelGenerator.acceptLastDelta(); |
| 233 |
| 234 // Run, but don't wait. |
| 235 var future = incrementalKernelGenerator.computeDelta(); |
| 236 |
| 237 // acceptLastDelta() is failing while the future is pending. |
| 238 _assertStateError(() { |
| 239 incrementalKernelGenerator.acceptLastDelta(); |
| 240 }, IncrementalKernelGeneratorImpl.MSG_PENDING_COMPUTE); |
| 241 |
| 242 // rejectLastDelta() is failing while the future is pending. |
| 243 _assertStateError(() { |
| 244 incrementalKernelGenerator.rejectLastDelta(); |
| 245 }, IncrementalKernelGeneratorImpl.MSG_PENDING_COMPUTE); |
| 246 |
| 247 // Run another, this causes StateError. |
| 248 _assertStateError(() { |
| 249 incrementalKernelGenerator.computeDelta(); |
| 250 }, IncrementalKernelGeneratorImpl.MSG_PENDING_COMPUTE); |
| 251 |
| 252 // Wait for the pending future. |
| 253 await future; |
| 254 } |
| 255 |
| 226 test_inferPackagesFile() async { | 256 test_inferPackagesFile() async { |
| 227 writeFile('/test/.packages', 'test:lib/'); | 257 writeFile('/test/.packages', 'test:lib/'); |
| 228 String aPath = '/test/lib/a.dart'; | 258 String aPath = '/test/lib/a.dart'; |
| 229 String bPath = '/test/lib/b.dart'; | 259 String bPath = '/test/lib/b.dart'; |
| 230 writeFile(aPath, 'var a = 1;'); | 260 writeFile(aPath, 'var a = 1;'); |
| 231 Uri bUri = writeFile(bPath, r''' | 261 Uri bUri = writeFile(bPath, r''' |
| 232 import "package:test/a.dart"; | 262 import "package:test/a.dart"; |
| 233 var b = a; | 263 var b = a; |
| 234 '''); | 264 '''); |
| 235 | 265 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 263 // Reject the last delta, so the test library is included again. | 293 // Reject the last delta, so the test library is included again. |
| 264 incrementalKernelGenerator.rejectLastDelta(); | 294 incrementalKernelGenerator.rejectLastDelta(); |
| 265 { | 295 { |
| 266 var delta = await incrementalKernelGenerator.computeDelta(); | 296 var delta = await incrementalKernelGenerator.computeDelta(); |
| 267 Program program = delta.newProgram; | 297 Program program = delta.newProgram; |
| 268 _assertLibraryUris(program, includes: [uri]); | 298 _assertLibraryUris(program, includes: [uri]); |
| 269 } | 299 } |
| 270 | 300 |
| 271 // Attempt to reject the last delta twice. | 301 // Attempt to reject the last delta twice. |
| 272 incrementalKernelGenerator.rejectLastDelta(); | 302 incrementalKernelGenerator.rejectLastDelta(); |
| 273 expect(() { | 303 _assertStateError(() { |
| 274 incrementalKernelGenerator.rejectLastDelta(); | 304 incrementalKernelGenerator.rejectLastDelta(); |
| 275 }, throwsStateError); | 305 }, IncrementalKernelGeneratorImpl.MSG_NO_LAST_DELTA); |
| 276 } | 306 } |
| 277 | 307 |
| 278 test_updateEntryPoint() async { | 308 test_updateEntryPoint() async { |
| 279 writeFile('/test/.packages', 'test:lib/'); | 309 writeFile('/test/.packages', 'test:lib/'); |
| 280 String path = '/test/lib/test.dart'; | 310 String path = '/test/lib/test.dart'; |
| 281 Uri uri = writeFile(path, r''' | 311 Uri uri = writeFile(path, r''' |
| 282 main() { | 312 main() { |
| 283 var v = 1; | 313 var v = 1; |
| 284 } | 314 } |
| 285 '''); | 315 '''); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 List<Uri> libraryUris = | 478 List<Uri> libraryUris = |
| 449 program.libraries.map((library) => library.importUri).toList(); | 479 program.libraries.map((library) => library.importUri).toList(); |
| 450 for (var shouldInclude in includes) { | 480 for (var shouldInclude in includes) { |
| 451 expect(libraryUris, contains(shouldInclude)); | 481 expect(libraryUris, contains(shouldInclude)); |
| 452 } | 482 } |
| 453 for (var shouldExclude in excludes) { | 483 for (var shouldExclude in excludes) { |
| 454 expect(libraryUris, isNot(contains(shouldExclude))); | 484 expect(libraryUris, isNot(contains(shouldExclude))); |
| 455 } | 485 } |
| 456 } | 486 } |
| 457 | 487 |
| 488 /// Assert that invocation of [f] throws a [StateError] with the given [msg]. |
| 489 void _assertStateError(f(), String msg) { |
| 490 try { |
| 491 f(); |
| 492 fail('StateError expected.'); |
| 493 } on StateError catch (e) { |
| 494 expect(e.message, msg); |
| 495 } |
| 496 } |
| 497 |
| 458 Future<List<int>> _computeSdkOutlineBytes() async { | 498 Future<List<int>> _computeSdkOutlineBytes() async { |
| 459 var options = new CompilerOptions() | 499 var options = new CompilerOptions() |
| 460 ..fileSystem = fileSystem | 500 ..fileSystem = fileSystem |
| 461 ..sdkRoot = Uri.parse('file:///sdk/') | 501 ..sdkRoot = Uri.parse('file:///sdk/') |
| 462 ..compileSdk = true | 502 ..compileSdk = true |
| 463 ..chaseDependencies = true | 503 ..chaseDependencies = true |
| 464 ..strongMode = true; | 504 ..strongMode = true; |
| 465 var inputs = [Uri.parse('dart:core')]; | 505 var inputs = [Uri.parse('dart:core')]; |
| 466 return summaryFor(inputs, options); | 506 return summaryFor(inputs, options); |
| 467 } | 507 } |
| 468 | 508 |
| 469 Library _getLibrary(Program program, Uri uri) { | 509 Library _getLibrary(Program program, Uri uri) { |
| 470 for (var library in program.libraries) { | 510 for (var library in program.libraries) { |
| 471 if (library.importUri == uri) return library; | 511 if (library.importUri == uri) return library; |
| 472 } | 512 } |
| 473 throw fail('No library found with URI "$uri"'); | 513 throw fail('No library found with URI "$uri"'); |
| 474 } | 514 } |
| 475 | 515 |
| 476 String _getLibraryText(Library library) { | 516 String _getLibraryText(Library library) { |
| 477 StringBuffer buffer = new StringBuffer(); | 517 StringBuffer buffer = new StringBuffer(); |
| 478 new Printer(buffer, syntheticNames: new NameSystem()) | 518 new Printer(buffer, syntheticNames: new NameSystem()) |
| 479 .writeLibraryFile(library); | 519 .writeLibraryFile(library); |
| 480 return buffer.toString(); | 520 return buffer.toString(); |
| 481 } | 521 } |
| 482 } | 522 } |
| OLD | NEW |