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