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 runCompiler, OutputCollector; | 8 import 'memory_compiler.dart' show runCompiler, OutputCollector; |
9 import 'package:compiler/src/apiimpl.dart' show | 9 import 'package:compiler/src/apiimpl.dart' show |
10 Compiler; | 10 CompilerImpl; |
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 asyncTest(() async { | 17 asyncTest(() async { |
18 await testWithMirrorHelperLibrary(minify: true); | 18 await testWithMirrorHelperLibrary(minify: true); |
19 await testWithMirrorHelperLibrary(minify: false); | 19 await testWithMirrorHelperLibrary(minify: false); |
20 await testWithoutMirrorHelperLibrary(minify: true); | 20 await testWithoutMirrorHelperLibrary(minify: true); |
21 await testWithoutMirrorHelperLibrary(minify: false); | 21 await testWithoutMirrorHelperLibrary(minify: false); |
22 }); | 22 }); |
23 } | 23 } |
24 | 24 |
25 Future<Compiler> run({OutputCollector outputCollector, | 25 Future<CompilerImpl> run({OutputCollector outputCollector, |
26 bool useMirrorHelperLibrary: false, | 26 bool useMirrorHelperLibrary: false, |
27 bool minify: false}) async { | 27 bool minify: false}) async { |
28 List<String> options = ['--output-type=dart']; | 28 List<String> options = ['--output-type=dart']; |
29 if (minify) { | 29 if (minify) { |
30 options.add('--minify'); | 30 options.add('--minify'); |
31 } | 31 } |
32 var result = await runCompiler( | 32 var result = await runCompiler( |
33 memorySourceFiles: MEMORY_SOURCE_FILES, | 33 memorySourceFiles: MEMORY_SOURCE_FILES, |
34 outputProvider: outputCollector, | 34 outputProvider: outputCollector, |
35 options: options, | 35 options: options, |
36 beforeRun: (Compiler compiler) { | 36 beforeRun: (CompilerImpl compiler) { |
37 DartBackend backend = compiler.backend; | 37 DartBackend backend = compiler.backend; |
38 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; | 38 backend.useMirrorHelperLibrary = useMirrorHelperLibrary; |
39 }); | 39 }); |
40 return result.compiler; | 40 return result.compiler; |
41 } | 41 } |
42 | 42 |
43 Future testWithMirrorHelperLibrary({bool minify}) async { | 43 Future testWithMirrorHelperLibrary({bool minify}) async { |
44 OutputCollector outputCollector = new OutputCollector(); | 44 OutputCollector outputCollector = new OutputCollector(); |
45 Compiler compiler = await run( | 45 CompilerImpl compiler = await run( |
46 outputCollector: outputCollector, | 46 outputCollector: outputCollector, |
47 useMirrorHelperLibrary: true, | 47 useMirrorHelperLibrary: true, |
48 minify: minify); | 48 minify: minify); |
49 DartBackend backend = compiler.backend; | 49 DartBackend backend = compiler.backend; |
50 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer; | 50 MirrorRenamerImpl mirrorRenamer = backend.mirrorRenamer; |
51 Map<Node, String> renames = backend.placeholderRenamer.renames; | 51 Map<Node, String> renames = backend.placeholderRenamer.renames; |
52 Map<String, String> symbols = mirrorRenamer.symbols; | 52 Map<String, String> symbols = mirrorRenamer.symbols; |
53 | 53 |
54 Expect.isFalse(null == mirrorRenamer.helperLibrary); | 54 Expect.isFalse(null == mirrorRenamer.helperLibrary); |
55 Expect.isFalse(null == mirrorRenamer.getNameFunction); | 55 Expect.isFalse(null == mirrorRenamer.getNameFunction); |
(...skipping 20 matching lines...) Expand all Loading... |
76 // Appears twice in code (defined & called). | 76 // Appears twice in code (defined & called). |
77 Expect.equals(2, i.length); | 77 Expect.equals(2, i.length); |
78 } | 78 } |
79 | 79 |
80 RegExp mapMatch = new RegExp('const<String,( )?String>'); | 80 RegExp mapMatch = new RegExp('const<String,( )?String>'); |
81 i = mapMatch.allMatches(output); | 81 i = mapMatch.allMatches(output); |
82 Expect.equals(1, i.length); | 82 Expect.equals(1, i.length); |
83 } | 83 } |
84 | 84 |
85 Future testWithoutMirrorHelperLibrary({bool minify}) async { | 85 Future testWithoutMirrorHelperLibrary({bool minify}) async { |
86 Compiler compiler = await run(useMirrorHelperLibrary: false, minify: minify); | 86 CompilerImpl compiler = |
| 87 await run(useMirrorHelperLibrary: false, minify: minify); |
87 DartBackend backend = compiler.backend; | 88 DartBackend backend = compiler.backend; |
88 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; | 89 MirrorRenamer mirrorRenamer = backend.mirrorRenamer; |
89 | 90 |
90 Expect.equals(null, mirrorRenamer.helperLibrary); | 91 Expect.equals(null, mirrorRenamer.helperLibrary); |
91 Expect.equals(null, mirrorRenamer.getNameFunction); | 92 Expect.equals(null, mirrorRenamer.getNameFunction); |
92 } | 93 } |
93 | 94 |
94 const MEMORY_SOURCE_FILES = const <String, String> { | 95 const MEMORY_SOURCE_FILES = const <String, String> { |
95 'main.dart': """ | 96 'main.dart': """ |
96 import 'dart:mirrors'; | 97 import 'dart:mirrors'; |
97 | 98 |
98 class Foo { | 99 class Foo { |
99 noSuchMethod(Invocation invocation) { | 100 noSuchMethod(Invocation invocation) { |
100 MirrorSystem.getName(invocation.memberName); | 101 MirrorSystem.getName(invocation.memberName); |
101 } | 102 } |
102 } | 103 } |
103 | 104 |
104 void main() { | 105 void main() { |
105 new Foo().fisk(); | 106 new Foo().fisk(); |
106 } | 107 } |
107 """}; | 108 """}; |
OLD | NEW |