| 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:compiler/src/apiimpl.dart'; | 6 import 'package:compiler/src/apiimpl.dart'; |
| 7 import 'package:compiler/src/dart2jslib.dart' show NullSink; | |
| 8 import 'package:expect/expect.dart'; | 7 import 'package:expect/expect.dart'; |
| 9 import 'package:compiler/src/filenames.dart'; | |
| 10 import 'package:compiler/src/source_file_provider.dart'; | |
| 11 import 'package:compiler/src/elements/elements.dart' | 8 import 'package:compiler/src/elements/elements.dart' |
| 12 show ClassElement; | 9 show ClassElement; |
| 13 import 'package:compiler/src/resolution/class_members.dart' | 10 import 'package:compiler/src/resolution/class_members.dart' |
| 14 show ClassMemberMixin; | 11 show ClassMemberMixin; |
| 15 import "package:async_helper/async_helper.dart"; | 12 import "package:async_helper/async_helper.dart"; |
| 13 import 'memory_compiler.dart'; |
| 16 | 14 |
| 17 | 15 |
| 18 const String DART2JS_SOURCE = | 16 const String DART2JS_SOURCE = |
| 19 'pkg/compiler/lib/src/dart2js.dart'; | 17 'pkg/compiler/lib/src/dart2js.dart'; |
| 20 const List<String> DART2JS_OPTIONS = const <String>[ | 18 const List<String> DART2JS_OPTIONS = const <String>[ |
| 21 '--categories=Client,Server', | 19 '--categories=Client,Server', |
| 22 '--disable-type-inference' | 20 '--disable-type-inference' |
| 23 ]; | 21 ]; |
| 24 | 22 |
| 25 Iterable<ClassElement> computeLiveClasses(Compiler compiler) { | 23 Iterable<ClassElement> computeLiveClasses(Compiler compiler) { |
| 26 return new Set<ClassElement>() | 24 return new Set<ClassElement>() |
| 27 ..addAll(compiler.resolverWorld.instantiatedClasses) | 25 ..addAll(compiler.resolverWorld.directlyInstantiatedClasses) |
| 28 ..addAll(compiler.codegenWorld.instantiatedClasses); | 26 ..addAll(compiler.codegenWorld.directlyInstantiatedClasses); |
| 29 } | 27 } |
| 30 | 28 |
| 31 void checkClassInvariants(ClassElement cls) { | 29 void checkClassInvariants(ClassElement cls) { |
| 32 ClassMemberMixin impl = cls; | 30 ClassMemberMixin impl = cls; |
| 33 Expect.isTrue(impl.areAllMembersComputed(), | 31 Expect.isTrue(impl.areAllMembersComputed(), |
| 34 "Not all members have been computed for $cls."); | 32 "Not all members have been computed for $cls."); |
| 35 } | 33 } |
| 36 | 34 |
| 37 Future checkElementInvariantsAfterCompiling(Uri uri) { | 35 Future checkElementInvariantsAfterCompiling(Uri uri) { |
| 38 var inputProvider = new CompilerSourceFileProvider(); | 36 var compiler = compilerFor({}, options: DART2JS_OPTIONS); |
| 39 var handler = new FormattingDiagnosticHandler(inputProvider); | |
| 40 var compiler = new Compiler(inputProvider.readStringFromUri, | |
| 41 NullSink.outputProvider, | |
| 42 handler, | |
| 43 currentDirectory.resolve('sdk/'), | |
| 44 currentDirectory.resolve('sdk/'), | |
| 45 DART2JS_OPTIONS, | |
| 46 {}); | |
| 47 | |
| 48 return compiler.run(uri).then((passed) { | 37 return compiler.run(uri).then((passed) { |
| 49 Expect.isTrue(passed, "Compilation of dart2js failed."); | 38 Expect.isTrue(passed, "Compilation of dart2js failed."); |
| 50 | 39 |
| 51 computeLiveClasses(compiler).forEach(checkClassInvariants); | 40 computeLiveClasses(compiler).forEach(checkClassInvariants); |
| 52 }); | 41 }); |
| 53 } | 42 } |
| 54 | 43 |
| 55 void main () { | 44 void main () { |
| 56 var uri = currentDirectory.resolve(DART2JS_SOURCE); | 45 var uri = Uri.base.resolve(DART2JS_SOURCE); |
| 57 asyncTest(() => checkElementInvariantsAfterCompiling(uri)); | 46 asyncTest(() => checkElementInvariantsAfterCompiling(uri)); |
| 58 } | 47 } |
| OLD | NEW |