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'; | 6 import 'dart:async'; |
7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
8 import 'memory_compiler.dart' show compilerFor; | 8 import 'memory_compiler.dart' show compilerFor, OutputCollector; |
9 import 'package:compiler/src/apiimpl.dart' show | 9 import 'package:compiler/src/apiimpl.dart' show |
10 Compiler; | 10 Compiler; |
11 import 'package:compiler/src/tree/tree.dart' show | 11 import 'package:compiler/src/tree/tree.dart' show |
12 Node; | 12 Node; |
13 import 'package:compiler/src/dart_backend/dart_backend.dart'; | 13 import 'package:compiler/src/dart_backend/dart_backend.dart'; |
14 import 'package:compiler/src/mirror_renamer/mirror_renamer.dart'; | 14 import 'package:compiler/src/mirror_renamer/mirror_renamer.dart'; |
15 | 15 |
16 main() { | 16 main() { |
17 testWithMirrorHelperLibrary(minify: true); | 17 testWithMirrorHelperLibrary(minify: true); |
18 testWithMirrorHelperLibrary(minify: false); | 18 testWithMirrorHelperLibrary(minify: false); |
19 testWithoutMirrorHelperLibrary(minify: true); | 19 testWithoutMirrorHelperLibrary(minify: true); |
20 testWithoutMirrorHelperLibrary(minify: false); | 20 testWithoutMirrorHelperLibrary(minify: false); |
21 } | 21 } |
22 | 22 |
23 Future<Compiler> runCompiler({useMirrorHelperLibrary: false, minify: false}) { | 23 Future<Compiler> runCompiler({OutputCollector outputCollector, |
| 24 bool useMirrorHelperLibrary: false, |
| 25 bool minify: false}) { |
24 List<String> options = ['--output-type=dart']; | 26 List<String> options = ['--output-type=dart']; |
25 if (minify) { | 27 if (minify) { |
26 options.add('--minify'); | 28 options.add('--minify'); |
27 } | 29 } |
28 Compiler compiler = compilerFor(MEMORY_SOURCE_FILES, options: options); | 30 Compiler compiler = compilerFor( |
| 31 MEMORY_SOURCE_FILES, outputProvider: outputCollector, options: options); |
29 DartBackend backend = compiler.backend; | 32 DartBackend backend = compiler.backend; |
30 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; | 33 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
31 return | 34 return |
32 compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler); | 35 compiler.runCompiler(Uri.parse('memory:main.dart')).then((_) => compiler); |
33 } | 36 } |
34 | 37 |
35 void testWithMirrorHelperLibrary({bool minify}) { | 38 void testWithMirrorHelperLibrary({bool minify}) { |
36 asyncTest(() => runCompiler(useMirrorHelperLibrary: true, minify: minify). | 39 OutputCollector outputCollector = new OutputCollector(); |
37 then((Compiler compiler) { | 40 asyncTest(() => |
| 41 runCompiler(outputCollector: outputCollector, |
| 42 useMirrorHelperLibrary: true, |
| 43 minify: minify) |
| 44 .then((Compiler compiler) { |
38 DartBackend backend = compiler.backend; | 45 DartBackend backend = compiler.backend; |
39 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer; | 46 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer; |
40 Map<Node, String> renames = backend.placeholderRenamer.renames; | 47 Map<Node, String> renames = backend.placeholderRenamer.renames; |
41 Map<String, String> symbols = mirrorRenamer.symbols; | 48 Map<String, String> symbols = mirrorRenamer.symbols; |
42 | 49 |
43 Expect.isFalse(null == mirrorRenamer.helperLibrary); | 50 Expect.isFalse(null == mirrorRenamer.helperLibrary); |
44 Expect.isFalse(null == mirrorRenamer.getNameFunction); | 51 Expect.isFalse(null == mirrorRenamer.getNameFunction); |
45 | 52 |
46 for (Node n in renames.keys) { | 53 for (Node n in renames.keys) { |
47 if (symbols.containsKey(renames[n])) { | 54 if (symbols.containsKey(renames[n])) { |
48 if(n.toString() == 'getName') { | 55 if(n.toString() == 'getName') { |
49 Expect.equals( | 56 Expect.equals( |
50 MirrorRenamerImpl.MIRROR_HELPER_GET_NAME_FUNCTION, | 57 MirrorRenamerImpl.MIRROR_HELPER_GET_NAME_FUNCTION, |
51 symbols[renames[n]]); | 58 symbols[renames[n]]); |
52 } else { | 59 } else { |
53 Expect.equals(n.toString(), symbols[renames[n]]); | 60 Expect.equals(n.toString(), symbols[renames[n]]); |
54 } | 61 } |
55 } | 62 } |
56 } | 63 } |
57 | 64 |
58 String output = compiler.assembledCode; | 65 String output = outputCollector.getOutput('', 'dart'); |
59 String getNameMatch = MirrorRenamerImpl.MIRROR_HELPER_GET_NAME_FUNCTION; | 66 String getNameMatch = MirrorRenamerImpl.MIRROR_HELPER_GET_NAME_FUNCTION; |
60 Iterable i = getNameMatch.allMatches(output); | 67 Iterable i = getNameMatch.allMatches(output); |
61 print(output); | 68 print(output); |
62 if (minify) { | 69 if (minify) { |
63 Expect.equals(0, i.length); | 70 Expect.equals(0, i.length); |
64 } else { | 71 } else { |
65 // Appears twice in code (defined & called). | 72 // Appears twice in code (defined & called). |
66 Expect.equals(2, i.length); | 73 Expect.equals(2, i.length); |
67 } | 74 } |
68 | 75 |
(...skipping 21 matching lines...) Expand all Loading... |
90 class Foo { | 97 class Foo { |
91 noSuchMethod(Invocation invocation) { | 98 noSuchMethod(Invocation invocation) { |
92 MirrorSystem.getName(invocation.memberName); | 99 MirrorSystem.getName(invocation.memberName); |
93 } | 100 } |
94 } | 101 } |
95 | 102 |
96 void main() { | 103 void main() { |
97 new Foo().fisk(); | 104 new Foo().fisk(); |
98 } | 105 } |
99 """}; | 106 """}; |
OLD | NEW |