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