| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 | |
| 5 /// Test that the dart2js copy of [KernelVisitor] generates the expected IR as | |
| 6 /// defined by kernel spec-mode test files. | |
| 7 | |
| 8 import 'dart:io'; | |
| 9 import 'dart:async'; | |
| 10 import 'package:compiler/src/compiler.dart' show Compiler; | |
| 11 import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend; | |
| 12 import 'package:compiler/src/commandline_options.dart' show Flags; | |
| 13 import 'package:kernel/ast.dart'; | |
| 14 import 'package:kernel/class_hierarchy.dart'; | |
| 15 import 'package:kernel/core_types.dart'; | |
| 16 import 'package:kernel/text/ast_to_text.dart'; | |
| 17 import 'package:kernel/transformations/mixin_full_resolution.dart'; | |
| 18 import 'package:kernel/target/targets.dart'; | |
| 19 import 'package:test/test.dart'; | |
| 20 | |
| 21 import '../memory_compiler.dart'; | |
| 22 | |
| 23 const String TESTCASE_DIR = 'pkg/front_end/testcases/'; | |
| 24 | |
| 25 const List<String> TESTS = const <String>[ | |
| 26 // 'DeltaBlue', Issue 29853: super calls compiled as direct calls. | |
| 27 'argument', | |
| 28 'arithmetic', | |
| 29 'async_function', | |
| 30 'bad_store', | |
| 31 'call', | |
| 32 'closure', | |
| 33 // 'covariant_generic', Issue 29853: typedefs | |
| 34 'escape', | |
| 35 // 'fallthrough', Issue 29853: fall-through errors compiled differently from | |
| 36 // Fasta | |
| 37 'micro', | |
| 38 'named_parameters', | |
| 39 'null_aware', | |
| 40 'optional', | |
| 41 'override', | |
| 42 'prefer_baseclass', | |
| 43 // 'redirecting_factory', Issue 29853: redirecting factories | |
| 44 'static_setter', | |
| 45 'store_load', | |
| 46 'stringliteral', | |
| 47 // 'uninitialized_fields', Issue 29853: Disagrement on field initializers. | |
| 48 'unused_methods', | |
| 49 'void-methods', | |
| 50 ]; | |
| 51 | |
| 52 main(List<String> arguments) { | |
| 53 if (arguments.isEmpty) { | |
| 54 for (String testName in TESTS) { | |
| 55 scheduleTest(testName, selected: false); | |
| 56 } | |
| 57 } else { | |
| 58 for (String testName in arguments) { | |
| 59 scheduleTest(testName, selected: true); | |
| 60 } | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 scheduleTest(String name, {bool selected}) async { | |
| 65 test(name, () async { | |
| 66 Uri uri = Uri.base.resolve(TESTCASE_DIR).resolve('$name.dart'); | |
| 67 var compiler = await newCompiler(); | |
| 68 await compiler.run(uri); | |
| 69 var loadedLibraries = await compiler.libraryLoader.loadLibrary(uri); | |
| 70 compiler.processLoadedLibraries(loadedLibraries); | |
| 71 var library = loadedLibraries.rootLibrary; | |
| 72 JavaScriptBackend backend = compiler.backend; | |
| 73 StringBuffer buffer = new StringBuffer(); | |
| 74 Program program = backend.kernelTask.buildProgram(library); | |
| 75 CoreTypes coreTypes = new CoreTypes(program); | |
| 76 ClassHierarchy hierarchy = new ClosedWorldClassHierarchy(program); | |
| 77 new MixinFullResolution(new NoneTarget(null), coreTypes, hierarchy) | |
| 78 .transform(program.libraries); | |
| 79 new Printer(buffer).writeLibraryFile(program.mainMethod.enclosingLibrary); | |
| 80 String actual = buffer.toString(); | |
| 81 String expected = | |
| 82 new File('${TESTCASE_DIR}/$name.dart.direct.expect').readAsStringSync(); | |
| 83 if (selected) { | |
| 84 String input = new File('${TESTCASE_DIR}/$name.dart').readAsStringSync(); | |
| 85 print('============================================================'); | |
| 86 print(name); | |
| 87 print('--input-----------------------------------------------------'); | |
| 88 print(input); | |
| 89 print('--expected--------------------------------------------------'); | |
| 90 print(expected); | |
| 91 print('--actual----------------------------------------------------'); | |
| 92 print(actual); | |
| 93 } | |
| 94 expect(actual, equals(expected)); | |
| 95 }); | |
| 96 } | |
| 97 | |
| 98 Future<Compiler> newCompiler() async { | |
| 99 var compiler = compilerFor( | |
| 100 options: [Flags.analyzeOnly, Flags.analyzeAll, Flags.useKernelInSsa]); | |
| 101 await compiler.setupSdk(); | |
| 102 | |
| 103 // The visitor no longer enqueues elements that are not reachable from the | |
| 104 // program. The mixin-full resolution transform run by the test expects to | |
| 105 // find dart.core::Iterator. | |
| 106 var loadedLibraries = | |
| 107 await compiler.libraryLoader.loadLibrary(Uri.parse('dart:core')); | |
| 108 compiler.processLoadedLibraries(loadedLibraries); | |
| 109 dynamic core = loadedLibraries.rootLibrary; | |
| 110 compiler.startResolution(); | |
| 111 var cls = core.implementation.localLookup('Iterator'); | |
| 112 cls.ensureResolved(compiler.resolution); | |
| 113 return compiler; | |
| 114 } | |
| OLD | NEW |