OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 // Test of the graph segmentation algorithm used by deferred loading | 5 // Test of the graph segmentation algorithm used by deferred loading |
6 // to determine which elements can be deferred and which libraries | 6 // to determine which elements can be deferred and which libraries |
7 // much be included in the initial download (loaded eagerly). | 7 // much be included in the initial download (loaded eagerly). |
8 | 8 |
9 import 'package:expect/expect.dart'; | 9 import 'package:expect/expect.dart'; |
10 import "package:async_helper/async_helper.dart"; | 10 import "package:async_helper/async_helper.dart"; |
11 import 'memory_source_file_helper.dart'; | 11 import 'memory_source_file_helper.dart'; |
12 import "memory_compiler.dart"; | 12 import "memory_compiler.dart"; |
13 | 13 |
14 import 'package:compiler/implementation/dart2jslib.dart' | 14 import 'package:compiler/implementation/dart2jslib.dart' |
15 as dart2js; | 15 as dart2js; |
16 | 16 |
17 runTest(String mainScript, test) { | 17 runTest(String mainScript, test) { |
18 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, | 18 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, |
19 outputProvider: new OutputCollector()); | 19 outputProvider: new OutputCollector()); |
20 asyncTest(() => compiler.run(Uri.parse(mainScript)) | 20 asyncTest(() => compiler.run(Uri.parse(mainScript)) |
21 .then((_) => test(compiler))); | 21 .then((_) => test(compiler))); |
22 } | 22 } |
23 | 23 |
| 24 lookupLibrary(compiler, name) { |
| 25 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
| 26 } |
| 27 |
24 void main() { | 28 void main() { |
25 runTest('memory:main.dart', (compiler) { | 29 runTest('memory:main.dart', (compiler) { |
26 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); | 30 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); |
27 Expect.isNotNull(main, "Could not find 'main'"); | 31 Expect.isNotNull(main, "Could not find 'main'"); |
28 compiler.deferredLoadTask.onResolutionComplete(main); | 32 compiler.deferredLoadTask.onResolutionComplete(main); |
29 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 33 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
30 | 34 |
31 var lib1 = compiler.libraries["memory:lib1.dart"]; | 35 var lib1 = lookupLibrary(compiler, "memory:lib1.dart"); |
32 var lib2 = compiler.libraries["memory:lib2.dart"]; | 36 var lib2 = lookupLibrary(compiler, "memory:lib2.dart"); |
33 var mathLib = compiler.libraries["dart:math"]; | 37 var mathLib = lookupLibrary(compiler, "dart:math"); |
34 var sin = mathLib.find('sin'); | 38 var sin = mathLib.find('sin'); |
35 var foo1 = lib1.find("foo1"); | 39 var foo1 = lib1.find("foo1"); |
36 var foo2 = lib2.find("foo2"); | 40 var foo2 = lib2.find("foo2"); |
37 var field2 = lib2.find("field2"); | 41 var field2 = lib2.find("field2"); |
38 | 42 |
39 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo1)); | 43 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo1)); |
40 Expect.equals(outputUnitForElement(main), outputUnitForElement(sin)); | 44 Expect.equals(outputUnitForElement(main), outputUnitForElement(sin)); |
41 Expect.equals(outputUnitForElement(foo2), outputUnitForElement(field2)); | 45 Expect.equals(outputUnitForElement(foo2), outputUnitForElement(field2)); |
42 }); | 46 }); |
43 runTest('memory:main2.dart', (compiler) { | 47 runTest('memory:main2.dart', (compiler) { |
44 // Just check that the compile runs. | 48 // Just check that the compile runs. |
45 // This is a regression test. | 49 // This is a regression test. |
46 Expect.isTrue(true); | 50 Expect.isTrue(true); |
47 }); | 51 }); |
48 runTest('memory:main3.dart', (compiler) { | 52 runTest('memory:main3.dart', (compiler) { |
49 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); | 53 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); |
50 Expect.isNotNull(main, "Could not find 'main'"); | 54 Expect.isNotNull(main, "Could not find 'main'"); |
51 compiler.deferredLoadTask.onResolutionComplete(main); | 55 compiler.deferredLoadTask.onResolutionComplete(main); |
52 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 56 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
53 | 57 |
54 var mainLib = compiler.libraries["memory:main3.dart"]; | 58 var mainLib = lookupLibrary(compiler, "memory:main3.dart"); |
55 var lib3 = compiler.libraries["memory:lib3.dart"]; | 59 var lib3 = lookupLibrary(compiler, "memory:lib3.dart"); |
56 var C = mainLib.find("C"); | 60 var C = mainLib.find("C"); |
57 var foo = lib3.find("foo"); | 61 var foo = lib3.find("foo"); |
58 | 62 |
59 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); | 63 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); |
60 Expect.equals(outputUnitForElement(main), outputUnitForElement(C)); | 64 Expect.equals(outputUnitForElement(main), outputUnitForElement(C)); |
61 }); | 65 }); |
62 runTest('memory:main4.dart', (compiler) { | 66 runTest('memory:main4.dart', (compiler) { |
63 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); | 67 var main = compiler.mainApp.find(dart2js.Compiler.MAIN); |
64 Expect.isNotNull(main, "Could not find 'main'"); | 68 Expect.isNotNull(main, "Could not find 'main'"); |
65 compiler.deferredLoadTask.onResolutionComplete(main); | 69 compiler.deferredLoadTask.onResolutionComplete(main); |
66 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 70 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
67 | 71 |
68 var mainLib = compiler.libraries["memory:main4.dart"]; | 72 var mainLib = lookupLibrary(compiler, "memory:main4.dart"); |
69 var lib4 = compiler.libraries["memory:lib4.dart"]; | 73 var lib4 = lookupLibrary(compiler, "memory:lib4.dart"); |
70 var lib5 = compiler.libraries["memory:lib5.dart"]; | 74 var lib5 = lookupLibrary(compiler, "memory:lib5.dart"); |
71 var lib6 = compiler.libraries["memory:lib6.dart"]; | 75 var lib6 = lookupLibrary(compiler, "memory:lib6.dart"); |
72 var foo5 = lib5.find("foo"); | 76 var foo5 = lib5.find("foo"); |
73 var foo6 = lib6.find("foo"); | 77 var foo6 = lib6.find("foo"); |
74 | 78 |
75 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo5)); | 79 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo5)); |
76 Expect.equals(outputUnitForElement(foo5), outputUnitForElement(foo6)); | 80 Expect.equals(outputUnitForElement(foo5), outputUnitForElement(foo6)); |
77 }); | 81 }); |
78 } | 82 } |
79 | 83 |
80 // "lib1.dart" uses mirrors without a MirrorsUsed annotation, so everything | 84 // "lib1.dart" uses mirrors without a MirrorsUsed annotation, so everything |
81 // should be put in the "lib1" output unit. | 85 // should be put in the "lib1" output unit. |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 library lib5; | 189 library lib5; |
186 | 190 |
187 foo() {} | 191 foo() {} |
188 """, | 192 """, |
189 "lib6.dart": """ | 193 "lib6.dart": """ |
190 library lib6; | 194 library lib6; |
191 | 195 |
192 foo() {} | 196 foo() {} |
193 """, | 197 """, |
194 }; | 198 }; |
OLD | NEW |