OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; |
| 7 import "package:async_helper/async_helper.dart"; |
6 import 'memory_compiler.dart' show compilerFor; | 8 import 'memory_compiler.dart' show compilerFor; |
7 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show | 9 import '../../../sdk/lib/_internal/compiler/implementation/apiimpl.dart' show |
8 Compiler; | 10 Compiler; |
9 import | 11 import |
10 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart' | 12 '../../../sdk/lib/_internal/compiler/implementation/elements/elements.dart' |
11 show | 13 show |
12 Element, LibraryElement, ClassElement; | 14 Element, LibraryElement, ClassElement; |
13 import | 15 import |
14 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart' | 16 '../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart' |
15 show | 17 show |
(...skipping 12 matching lines...) Expand all Loading... |
28 SourceString; | 30 SourceString; |
29 | 31 |
30 | 32 |
31 main() { | 33 main() { |
32 testWithMirrorRenaming(minify: true); | 34 testWithMirrorRenaming(minify: true); |
33 testWithMirrorRenaming(minify: false); | 35 testWithMirrorRenaming(minify: false); |
34 testWithoutMirrorRenaming(minify: true); | 36 testWithoutMirrorRenaming(minify: true); |
35 testWithoutMirrorRenaming(minify: false); | 37 testWithoutMirrorRenaming(minify: false); |
36 } | 38 } |
37 | 39 |
38 Compiler runCompiler({useMirrorHelperLibrary: false, minify: false}) { | 40 Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) { |
39 List<String> options = ['--output-type=dart']; | 41 List<String> options = ['--output-type=dart']; |
40 if (minify) { | 42 if (minify) { |
41 options.add('--minify'); | 43 options.add('--minify'); |
42 } | 44 } |
43 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); | 45 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); |
44 DartBackend backend = compiler.backend; | 46 DartBackend backend = compiler.backend; |
45 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; | 47 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
46 compiler.runCompiler(Uri.parse('memory:main.dart')); | 48 return |
47 return compiler; | 49 compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler); |
48 } | 50 } |
49 | 51 |
50 void testWithMirrorRenaming({bool minify}) { | 52 void testWithMirrorRenaming({bool minify}) { |
51 Compiler compiler = runCompiler(useMirrorHelperLibrary: true, minify: minify); | 53 asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: minify). |
| 54 then((Compiler compiler) { |
52 | 55 |
53 DartBackend backend = compiler.backend; | 56 DartBackend backend = compiler.backend; |
54 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; | 57 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; |
55 Map<Node, String> renames = backend.renames; | 58 Map<Node, String> renames = backend.renames; |
56 Map<LibraryElement, String> imports = backend.imports; | 59 Map<LibraryElement, String> imports = backend.imports; |
57 | 60 |
58 Node getNameFunctionNode = | 61 Node getNameFunctionNode = |
59 backend.memberNodes.values.first.first.body.statements.nodes.head; | 62 backend.memberNodes.values.first.first.body.statements.nodes.head; |
60 | 63 |
61 Expect.equals(renames[mirrorRenamer.mirrorHelperGetNameFunctionNode.name], | 64 Expect.equals(renames[mirrorRenamer.mirrorHelperGetNameFunctionNode.name], |
62 renames[getNameFunctionNode.expression.selector]); | 65 renames[getNameFunctionNode.expression.selector]); |
63 Expect.equals("", | 66 Expect.equals("", |
64 renames[getNameFunctionNode.expression.receiver]); | 67 renames[getNameFunctionNode.expression.receiver]); |
65 Expect.equals(1, imports.keys.length); | 68 Expect.equals(1, imports.keys.length); |
| 69 })); |
66 } | 70 } |
67 | 71 |
68 void testWithoutMirrorRenaming({bool minify}) { | 72 void testWithoutMirrorRenaming({bool minify}) { |
69 Compiler compiler = | 73 asyncTest(() => runCompiler(useMirrorHelperLibrary: false, minify: minify). |
70 runCompiler(useMirrorHelperLibrary: false, minify: minify); | 74 then((Compiler compiler) { |
71 | 75 |
72 DartBackend backend = compiler.backend; | 76 DartBackend backend = compiler.backend; |
73 Map<Node, String> renames = backend.renames; | 77 Map<Node, String> renames = backend.renames; |
74 Map<LibraryElement, String> imports = backend.imports; | 78 Map<LibraryElement, String> imports = backend.imports; |
75 | 79 |
76 Node getNameFunctionNode = | 80 Node getNameFunctionNode = |
77 backend.memberNodes.values.first.first.body.statements.nodes.head; | 81 backend.memberNodes.values.first.first.body.statements.nodes.head; |
78 | 82 |
79 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector)); | 83 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.selector))
; |
80 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver)); | 84 Expect.isFalse(renames.containsKey(getNameFunctionNode.expression.receiver))
; |
81 Expect.equals(1, imports.keys.length); | 85 Expect.equals(1, imports.keys.length); |
| 86 })); |
82 } | 87 } |
83 | 88 |
84 const MEMORY_SOURCE_FILES = const <String, String> { | 89 const MEMORY_SOURCE_FILES = const <String, String> { |
85 'main.dart': """ | 90 'main.dart': """ |
86 import 'dart:mirrors'; | 91 import 'dart:mirrors'; |
87 | 92 |
88 class Foo { | 93 class Foo { |
89 noSuchMethod(Invocation invocation) { | 94 noSuchMethod(Invocation invocation) { |
90 MirrorSystem.getName(invocation.memberName); | 95 MirrorSystem.getName(invocation.memberName); |
91 } | 96 } |
92 } | 97 } |
93 | 98 |
94 void main() { | 99 void main() { |
95 new Foo().fisk(); | 100 new Foo().fisk(); |
96 } | 101 } |
97 """}; | 102 """}; |
OLD | NEW |