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 'dart:async'; | 9 import 'dart:async'; |
10 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
(...skipping 11 matching lines...) Expand all Loading... |
22 lookupLibrary(compiler, name) { | 22 lookupLibrary(compiler, name) { |
23 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); | 23 return compiler.libraryLoader.lookupLibrary(Uri.parse(name)); |
24 } | 24 } |
25 | 25 |
26 void main() { | 26 void main() { |
27 asyncTest(runTests); | 27 asyncTest(runTests); |
28 } | 28 } |
29 | 29 |
30 runTests() async { | 30 runTests() async { |
31 await runTest('memory:main.dart', (compiler) { | 31 await runTest('memory:main.dart', (compiler) { |
32 var main = compiler.mainFunction; | 32 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; |
33 Expect.isNotNull(main, "Could not find 'main'"); | 33 Expect.isNotNull(main, "Could not find 'main'"); |
34 compiler.deferredLoadTask.onResolutionComplete( | 34 compiler.deferredLoadTask.onResolutionComplete( |
35 main, compiler.resolutionWorldBuilder.closedWorldForTesting); | 35 main, compiler.resolutionWorldBuilder.closedWorldForTesting); |
36 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 36 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
37 | 37 |
38 var lib1 = lookupLibrary(compiler, "memory:lib1.dart"); | 38 var lib1 = lookupLibrary(compiler, "memory:lib1.dart"); |
39 var lib2 = lookupLibrary(compiler, "memory:lib2.dart"); | 39 var lib2 = lookupLibrary(compiler, "memory:lib2.dart"); |
40 var mathLib = lookupLibrary(compiler, "dart:math"); | 40 var mathLib = lookupLibrary(compiler, "dart:math"); |
41 var sin = mathLib.find('sin'); | 41 var sin = mathLib.find('sin'); |
42 var foo1 = lib1.find("foo1"); | 42 var foo1 = lib1.find("foo1"); |
43 var foo2 = lib2.find("foo2"); | 43 var foo2 = lib2.find("foo2"); |
44 var field2 = lib2.find("field2"); | 44 var field2 = lib2.find("field2"); |
45 | 45 |
46 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo1)); | 46 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo1)); |
47 Expect.equals(outputUnitForElement(main), outputUnitForElement(sin)); | 47 Expect.equals(outputUnitForElement(main), outputUnitForElement(sin)); |
48 Expect.equals(outputUnitForElement(foo2), outputUnitForElement(field2)); | 48 Expect.equals(outputUnitForElement(foo2), outputUnitForElement(field2)); |
49 }); | 49 }); |
50 await runTest('memory:main2.dart', (compiler) { | 50 await runTest('memory:main2.dart', (compiler) { |
51 // Just check that the compile runs. | 51 // Just check that the compile runs. |
52 // This is a regression test. | 52 // This is a regression test. |
53 Expect.isTrue(true); | 53 Expect.isTrue(true); |
54 }); | 54 }); |
55 await runTest('memory:main3.dart', (compiler) { | 55 await runTest('memory:main3.dart', (compiler) { |
56 var main = compiler.mainFunction; | 56 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; |
57 Expect.isNotNull(main, "Could not find 'main'"); | 57 Expect.isNotNull(main, "Could not find 'main'"); |
58 compiler.deferredLoadTask.onResolutionComplete( | 58 compiler.deferredLoadTask.onResolutionComplete( |
59 main, compiler.resolutionWorldBuilder.closedWorldForTesting); | 59 main, compiler.resolutionWorldBuilder.closedWorldForTesting); |
60 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 60 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
61 | 61 |
62 Expect.isFalse(compiler.backend.mirrorsData.hasInsufficientMirrorsUsed); | 62 Expect.isFalse(compiler.backend.mirrorsData.hasInsufficientMirrorsUsed); |
63 var mainLib = lookupLibrary(compiler, "memory:main3.dart"); | 63 var mainLib = lookupLibrary(compiler, "memory:main3.dart"); |
64 var lib3 = lookupLibrary(compiler, "memory:lib3.dart"); | 64 var lib3 = lookupLibrary(compiler, "memory:lib3.dart"); |
65 var C = mainLib.find("C"); | 65 var C = mainLib.find("C"); |
66 var foo = lib3.find("foo"); | 66 var foo = lib3.find("foo"); |
67 | 67 |
68 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); | 68 Expect.notEquals(outputUnitForElement(main), outputUnitForElement(foo)); |
69 Expect.equals(outputUnitForElement(main), outputUnitForElement(C)); | 69 Expect.equals(outputUnitForElement(main), outputUnitForElement(C)); |
70 }); | 70 }); |
71 await runTest('memory:main4.dart', (compiler) { | 71 await runTest('memory:main4.dart', (compiler) { |
72 var main = compiler.mainFunction; | 72 var main = compiler.frontendStrategy.elementEnvironment.mainFunction; |
73 Expect.isNotNull(main, "Could not find 'main'"); | 73 Expect.isNotNull(main, "Could not find 'main'"); |
74 compiler.deferredLoadTask.onResolutionComplete( | 74 compiler.deferredLoadTask.onResolutionComplete( |
75 main, compiler.resolutionWorldBuilder.closedWorldForTesting); | 75 main, compiler.resolutionWorldBuilder.closedWorldForTesting); |
76 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; | 76 var outputUnitForElement = compiler.deferredLoadTask.outputUnitForElement; |
77 | 77 |
78 var mainLib = lookupLibrary(compiler, "memory:main4.dart"); | 78 var mainLib = lookupLibrary(compiler, "memory:main4.dart"); |
79 var lib4 = lookupLibrary(compiler, "memory:lib4.dart"); | 79 var lib4 = lookupLibrary(compiler, "memory:lib4.dart"); |
80 var lib5 = lookupLibrary(compiler, "memory:lib5.dart"); | 80 var lib5 = lookupLibrary(compiler, "memory:lib5.dart"); |
81 var lib6 = lookupLibrary(compiler, "memory:lib6.dart"); | 81 var lib6 = lookupLibrary(compiler, "memory:lib6.dart"); |
82 var foo5 = lib5.find("foo"); | 82 var foo5 = lib5.find("foo"); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 library lib5; | 195 library lib5; |
196 | 196 |
197 foo() {} | 197 foo() {} |
198 """, | 198 """, |
199 "lib6.dart": """ | 199 "lib6.dart": """ |
200 library lib6; | 200 library lib6; |
201 | 201 |
202 foo() {} | 202 foo() {} |
203 """, | 203 """, |
204 }; | 204 }; |
OLD | NEW |