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 import 'dart:async'; | 5 import 'dart:async'; |
6 import 'package:async_helper/async_helper.dart'; | 6 import 'package:async_helper/async_helper.dart'; |
7 import 'package:compiler/src/apiimpl.dart'; | 7 import 'package:compiler/src/apiimpl.dart'; |
8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
9 import 'package:compiler/src/elements/elements.dart' | 9 import 'package:compiler/src/elements/elements.dart' show ClassElement; |
10 show ClassElement; | |
11 import 'package:compiler/src/resolution/class_members.dart' | 10 import 'package:compiler/src/resolution/class_members.dart' |
12 show ClassMemberMixin; | 11 show ClassMemberMixin; |
13 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
14 | 13 |
15 | 14 const String DART2JS_SOURCE = 'pkg/compiler/lib/src/dart2js.dart'; |
16 const String DART2JS_SOURCE = | |
17 'pkg/compiler/lib/src/dart2js.dart'; | |
18 const List<String> DART2JS_OPTIONS = const <String>[ | 15 const List<String> DART2JS_OPTIONS = const <String>[ |
19 '--categories=Client,Server', | 16 '--categories=Client,Server', |
20 '--disable-type-inference' | 17 '--disable-type-inference' |
21 ]; | 18 ]; |
22 | 19 |
23 Iterable<ClassElement> computeLiveClasses(CompilerImpl compiler) { | 20 Iterable<ClassElement> computeLiveClasses(CompilerImpl compiler) { |
24 return new Set<ClassElement>() | 21 return new Set<ClassElement>() |
25 ..addAll(compiler.resolverWorld.directlyInstantiatedClasses) | 22 ..addAll(compiler.resolverWorld.directlyInstantiatedClasses) |
26 ..addAll(compiler.codegenWorld.directlyInstantiatedClasses); | 23 ..addAll(compiler.codegenWorld.directlyInstantiatedClasses); |
27 } | 24 } |
28 | 25 |
29 void checkClassInvariants(ClassElement cls) { | 26 void checkClassInvariants(ClassElement cls) { |
30 ClassMemberMixin impl = cls; | 27 ClassMemberMixin impl = cls; |
31 Expect.isTrue(impl.areAllMembersComputed(), | 28 Expect.isTrue(impl.areAllMembersComputed(), |
32 "Not all members have been computed for $cls."); | 29 "Not all members have been computed for $cls."); |
33 } | 30 } |
34 | 31 |
35 Future checkElementInvariantsAfterCompiling(Uri uri) async { | 32 Future checkElementInvariantsAfterCompiling(Uri uri) async { |
36 CompilationResult result = | 33 CompilationResult result = |
37 await runCompiler(entryPoint: uri, options: DART2JS_OPTIONS); | 34 await runCompiler(entryPoint: uri, options: DART2JS_OPTIONS); |
38 Expect.isTrue(result.isSuccess, "Compilation of dart2js failed."); | 35 Expect.isTrue(result.isSuccess, "Compilation of dart2js failed."); |
39 | 36 |
40 computeLiveClasses(result.compiler).forEach(checkClassInvariants); | 37 computeLiveClasses(result.compiler).forEach(checkClassInvariants); |
41 } | 38 } |
42 | 39 |
43 void main () { | 40 void main() { |
44 var uri = Uri.base.resolve(DART2JS_SOURCE); | 41 var uri = Uri.base.resolve(DART2JS_SOURCE); |
45 asyncTest(() => checkElementInvariantsAfterCompiling(uri)); | 42 asyncTest(() => checkElementInvariantsAfterCompiling(uri)); |
46 } | 43 } |
OLD | NEW |