| 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/incremental/byte_store.dart'; | 10 import 'package:front_end/src/incremental/byte_store.dart'; |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 { | 361 { |
| 362 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); | 362 DeltaProgram delta = await incrementalKernelGenerator.computeDelta(); |
| 363 Program program = delta.newProgram; | 363 Program program = delta.newProgram; |
| 364 _assertLibraryUris(program, | 364 _assertLibraryUris(program, |
| 365 includes: [aUri, bUri, cUri], excludes: [Uri.parse('dart:core')]); | 365 includes: [aUri, bUri, cUri], excludes: [Uri.parse('dart:core')]); |
| 366 // Compiled: c.dart (changed), and b.dart (has mixin). | 366 // Compiled: c.dart (changed), and b.dart (has mixin). |
| 367 _assertCompiledUris([cUri, bUri]); | 367 _assertCompiledUris([cUri, bUri]); |
| 368 } | 368 } |
| 369 } | 369 } |
| 370 | 370 |
| 371 void _assertCompiledUris(Iterable<Uri> expected) { | |
| 372 var compiledCycles = incrementalKernelGenerator.test.compiledCycles; | |
| 373 Set<Uri> compiledUris = compiledCycles | |
| 374 .map((cycle) => cycle.libraries.map((file) => file.uri)) | |
| 375 .expand((uris) => uris) | |
| 376 .toSet(); | |
| 377 expect(compiledUris, unorderedEquals(expected)); | |
| 378 } | |
| 379 | |
| 380 test_compile_typedef() async { | 371 test_compile_typedef() async { |
| 381 writeFile('/test/.packages', 'test:lib/'); | 372 writeFile('/test/.packages', 'test:lib/'); |
| 382 String aPath = '/test/lib/a.dart'; | 373 String aPath = '/test/lib/a.dart'; |
| 383 String bPath = '/test/lib/b.dart'; | 374 String bPath = '/test/lib/b.dart'; |
| 384 writeFile(aPath, 'typedef int F<T>(T x);'); | 375 writeFile(aPath, 'typedef int F<T>(T x);'); |
| 385 Uri bUri = writeFile( | 376 Uri bUri = writeFile( |
| 386 bPath, | 377 bPath, |
| 387 r''' | 378 r''' |
| 388 import 'a.dart'; | 379 import 'a.dart'; |
| 389 F<String> f; | 380 F<String> f; |
| (...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 { | 806 { |
| 816 await incrementalKernelGenerator.computeDelta(); | 807 await incrementalKernelGenerator.computeDelta(); |
| 817 // No new used files. | 808 // No new used files. |
| 818 expect(usedFiles, isEmpty); | 809 expect(usedFiles, isEmpty); |
| 819 // The file b.dart is not used anymore. | 810 // The file b.dart is not used anymore. |
| 820 expect(unusedFiles, [bUri]); | 811 expect(unusedFiles, [bUri]); |
| 821 unusedFiles.clear(); | 812 unusedFiles.clear(); |
| 822 } | 813 } |
| 823 } | 814 } |
| 824 | 815 |
| 816 test_watch_null() async { |
| 817 writeFile('/test/.packages', 'test:lib/'); |
| 818 String aPath = '/test/lib/a.dart'; |
| 819 String bPath = '/test/lib/b.dart'; |
| 820 Uri aUri = writeFile(aPath, ""); |
| 821 Uri bUri = writeFile(bPath, ""); |
| 822 |
| 823 // Set null, as if the watch function is not provided. |
| 824 watchFn = null; |
| 825 |
| 826 await getInitialState(bUri); |
| 827 |
| 828 // Update b.dart to import a.dart file. |
| 829 writeFile(bPath, "import 'a.dart';"); |
| 830 incrementalKernelGenerator.invalidate(bUri); |
| 831 await incrementalKernelGenerator.computeDelta(); |
| 832 |
| 833 // No exception even though the watcher function is null. |
| 834 } |
| 835 |
| 825 /// Write the given [text] of the file with the given [path] into the | 836 /// Write the given [text] of the file with the given [path] into the |
| 826 /// virtual filesystem. Return the URI of the file. | 837 /// virtual filesystem. Return the URI of the file. |
| 827 Uri writeFile(String path, String text) { | 838 Uri writeFile(String path, String text) { |
| 828 Uri uri = Uri.parse('file://$path'); | 839 Uri uri = Uri.parse('file://$path'); |
| 829 fileSystem.entityForUri(uri).writeAsStringSync(text); | 840 fileSystem.entityForUri(uri).writeAsStringSync(text); |
| 830 return uri; | 841 return uri; |
| 831 } | 842 } |
| 832 | 843 |
| 833 /// Write the given file contents to the virtual filesystem. | 844 /// Write the given file contents to the virtual filesystem. |
| 834 void writeFiles(Map<String, String> contents) { | 845 void writeFiles(Map<String, String> contents) { |
| 835 contents.forEach(writeFile); | 846 contents.forEach(writeFile); |
| 836 } | 847 } |
| 837 | 848 |
| 849 void _assertCompiledUris(Iterable<Uri> expected) { |
| 850 var compiledCycles = incrementalKernelGenerator.test.compiledCycles; |
| 851 Set<Uri> compiledUris = compiledCycles |
| 852 .map((cycle) => cycle.libraries.map((file) => file.uri)) |
| 853 .expand((uris) => uris) |
| 854 .toSet(); |
| 855 expect(compiledUris, unorderedEquals(expected)); |
| 856 } |
| 857 |
| 838 void _assertLibraryUris(Program program, | 858 void _assertLibraryUris(Program program, |
| 839 {List<Uri> includes: const [], List<Uri> excludes: const []}) { | 859 {List<Uri> includes: const [], List<Uri> excludes: const []}) { |
| 840 List<Uri> libraryUris = | 860 List<Uri> libraryUris = |
| 841 program.libraries.map((library) => library.importUri).toList(); | 861 program.libraries.map((library) => library.importUri).toList(); |
| 842 for (var shouldInclude in includes) { | 862 for (var shouldInclude in includes) { |
| 843 expect(libraryUris, contains(shouldInclude)); | 863 expect(libraryUris, contains(shouldInclude)); |
| 844 } | 864 } |
| 845 for (var shouldExclude in excludes) { | 865 for (var shouldExclude in excludes) { |
| 846 expect(libraryUris, isNot(contains(shouldExclude))); | 866 expect(libraryUris, isNot(contains(shouldExclude))); |
| 847 } | 867 } |
| 848 } | 868 } |
| 849 | 869 |
| 850 Library _getLibrary(Program program, Uri uri) { | 870 Library _getLibrary(Program program, Uri uri) { |
| 851 for (var library in program.libraries) { | 871 for (var library in program.libraries) { |
| 852 if (library.importUri == uri) return library; | 872 if (library.importUri == uri) return library; |
| 853 } | 873 } |
| 854 throw fail('No library found with URI "$uri"'); | 874 throw fail('No library found with URI "$uri"'); |
| 855 } | 875 } |
| 856 | 876 |
| 857 String _getLibraryText(Library library) { | 877 String _getLibraryText(Library library) { |
| 858 StringBuffer buffer = new StringBuffer(); | 878 StringBuffer buffer = new StringBuffer(); |
| 859 new Printer(buffer, syntheticNames: new NameSystem()) | 879 new Printer(buffer, syntheticNames: new NameSystem()) |
| 860 .writeLibraryFile(library); | 880 .writeLibraryFile(library); |
| 861 return buffer.toString(); | 881 return buffer.toString(); |
| 862 } | 882 } |
| 863 } | 883 } |
| OLD | NEW |