| 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 '../compiler_helper.dart'; | 5 library dart_backend.test_helper; |
| 6 |
| 6 import 'dart:async'; | 7 import 'dart:async'; |
| 7 import 'package:async_helper/async_helper.dart'; | 8 import 'package:async_helper/async_helper.dart'; |
| 8 import 'package:compiler/implementation/dart2jslib.dart'; | 9 import 'package:compiler/implementation/dart2jslib.dart'; |
| 9 import 'package:compiler/implementation/dart_backend/dart_backend.dart'; | 10 import '../../../../pkg/analyzer2dart/test/test_helper.dart'; |
| 10 import 'package:compiler/implementation/dart_backend/backend_ast_to_frontend_ast
.dart' | 11 import '../compiler_helper.dart'; |
| 11 show INSERT_NEW_BACKEND_COMMENT; | |
| 12 | 12 |
| 13 const String TestStaticField = """ | 13 /// Compiles the given dart code (which must include a 'main' function) and |
| 14 class Foo { | 14 /// returns the compiler. |
| 15 static int x = 1; | 15 Future<Compiler> compilerFor(String code) { |
| 16 } | |
| 17 main() { | |
| 18 print(Foo.x); | |
| 19 } | |
| 20 """; | |
| 21 | |
| 22 Future<String> compile(String code) { | |
| 23 MockCompiler compiler = new MockCompiler.internal( | 16 MockCompiler compiler = new MockCompiler.internal( |
| 24 emitJavaScript: false, | 17 emitJavaScript: false, |
| 25 enableMinification: false); | 18 enableMinification: false); |
| 19 compiler.diagnosticHandler = createHandler(compiler, code); |
| 26 return compiler.init().then((_) { | 20 return compiler.init().then((_) { |
| 27 compiler.parseScript(code); | 21 compiler.parseScript(code); |
| 22 |
| 28 Element element = compiler.mainApp.find('main'); | 23 Element element = compiler.mainApp.find('main'); |
| 29 if (element == null) return null; | 24 if (element == null) return null; |
| 25 |
| 30 compiler.mainFunction = element; | 26 compiler.mainFunction = element; |
| 31 compiler.phase = Compiler.PHASE_RESOLVING; | 27 compiler.phase = Compiler.PHASE_RESOLVING; |
| 32 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution, | 28 compiler.backend.enqueueHelpers(compiler.enqueuer.resolution, |
| 33 compiler.globalDependencies); | 29 compiler.globalDependencies); |
| 34 compiler.processQueue(compiler.enqueuer.resolution, element); | 30 compiler.processQueue(compiler.enqueuer.resolution, element); |
| 35 compiler.world.populate(); | 31 compiler.world.populate(); |
| 36 compiler.backend.onResolutionComplete(); | 32 compiler.backend.onResolutionComplete(); |
| 33 |
| 37 compiler.irBuilder.buildNodes(useNewBackend: true); | 34 compiler.irBuilder.buildNodes(useNewBackend: true); |
| 38 compiler.phase = Compiler.PHASE_COMPILING; | 35 |
| 39 DartBackend backend = compiler.backend; | 36 return compiler; |
| 40 backend.assembleProgram(); | |
| 41 String generated = compiler.assembledCode; | |
| 42 return generated; | |
| 43 }); | 37 }); |
| 44 } | 38 } |
| 45 | 39 |
| 46 Future test(String code, String feature) { | 40 /// Test group using async_helper. |
| 47 return compile(code).then((output) { | 41 asyncTester(Group group, RunTest runTest) { |
| 48 if (output == null || !output.contains('main() /* new backend */')) { | 42 asyncTest(() => Future.forEach(group.results, runTest)); |
| 49 throw 'New backend appears to be deactivated for $feature.\n' | |
| 50 'Output was: $output'; | |
| 51 } | |
| 52 }); | |
| 53 } | 43 } |
| 54 | |
| 55 main() { | |
| 56 INSERT_NEW_BACKEND_COMMENT = true; | |
| 57 | |
| 58 asyncTest(() => Future.forEach([ | |
| 59 () => test(TestStaticField, 'static fields'), | |
| 60 ], (f) => f())); | |
| 61 } | |
| OLD | NEW |