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 'package:compiler/src/compiler.dart' show Compiler; | 9 import 'package:compiler/src/compiler.dart' show Compiler; |
| 10 import 'package:compiler/src/elements/elements.dart'; |
10 import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend; | 11 import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend; |
11 import 'package:compiler/src/commandline_options.dart' show Flags; | 12 import 'package:compiler/src/commandline_options.dart' show Flags; |
12 import 'package:kernel/ast.dart'; | 13 import 'package:kernel/ast.dart'; |
13 import 'package:kernel/text/ast_to_text.dart'; | 14 import 'package:kernel/text/ast_to_text.dart'; |
14 import 'package:kernel/transformations/mixin_full_resolution.dart'; | 15 import 'package:kernel/transformations/mixin_full_resolution.dart'; |
15 import 'package:path/path.dart' as pathlib; | 16 import 'package:path/path.dart' as pathlib; |
16 import 'package:test/test.dart'; | 17 import 'package:test/test.dart'; |
17 | 18 |
18 import '../memory_compiler.dart'; | 19 import '../memory_compiler.dart'; |
19 | 20 |
20 const String TESTCASE_DIR = 'third_party/pkg/kernel/testcases/'; | 21 const String TESTCASE_DIR = 'third_party/pkg/kernel/testcases/'; |
21 | 22 |
22 const List<String> SKIP_TESTS = const <String>[]; | 23 const List<String> SKIP_TESTS = const <String>[]; |
23 | 24 |
24 main(List<String> arguments) { | 25 main(List<String> arguments) { |
| 26 Compiler compiler = compilerFor( |
| 27 options: [Flags.analyzeOnly, Flags.analyzeMain, Flags.useKernel]); |
25 Directory directory = new Directory('${TESTCASE_DIR}/input'); | 28 Directory directory = new Directory('${TESTCASE_DIR}/input'); |
26 for (FileSystemEntity file in directory.listSync()) { | 29 for (FileSystemEntity file in directory.listSync()) { |
27 if (file is File && file.path.endsWith('.dart')) { | 30 if (file is File && file.path.endsWith('.dart')) { |
28 String name = pathlib.basenameWithoutExtension(file.path); | 31 String name = pathlib.basenameWithoutExtension(file.path); |
29 bool selected = arguments.contains(name); | 32 bool selected = arguments.contains(name); |
30 if (!selected) { | 33 if (!selected) { |
31 if (arguments.isNotEmpty) continue; | 34 if (arguments.isNotEmpty) continue; |
32 if (SKIP_TESTS.contains(name)) continue; | 35 if (SKIP_TESTS.contains(name)) continue; |
33 } | 36 } |
34 | 37 |
35 test(name, () async { | 38 test(name, () async { |
36 var result = await runCompiler( | 39 LibraryElement library = await compiler.analyzeUri(file.absolute.uri); |
37 entryPoint: file.absolute.uri, | |
38 options: [Flags.analyzeOnly, Flags.useKernel]); | |
39 Compiler compiler = result.compiler; | |
40 JavaScriptBackend backend = compiler.backend; | 40 JavaScriptBackend backend = compiler.backend; |
41 StringBuffer buffer = new StringBuffer(); | 41 StringBuffer buffer = new StringBuffer(); |
42 Program program = backend.kernelTask.program; | 42 Program program = backend.kernelTask.buildProgram(library); |
43 new MixinFullResolution().transform(program); | 43 new MixinFullResolution().transform(program); |
44 new Printer(buffer).writeLibraryFile( | 44 new Printer(buffer).writeLibraryFile( |
45 backend.kernelTask.program.mainMethod.enclosingLibrary); | 45 program.mainMethod.enclosingLibrary); |
46 String actual = buffer.toString(); | 46 String actual = buffer.toString(); |
47 String expected = | 47 String expected = |
48 new File('${TESTCASE_DIR}/spec-mode/$name.baseline.txt') | 48 new File('${TESTCASE_DIR}/spec-mode/$name.baseline.txt') |
49 .readAsStringSync(); | 49 .readAsStringSync(); |
50 if (selected) { | 50 if (selected) { |
51 String input = | 51 String input = |
52 new File('${TESTCASE_DIR}/input/$name.dart').readAsStringSync(); | 52 new File('${TESTCASE_DIR}/input/$name.dart').readAsStringSync(); |
53 print('============================================================'); | 53 print('============================================================'); |
54 print(name); | 54 print(name); |
55 print('--input-----------------------------------------------------'); | 55 print('--input-----------------------------------------------------'); |
56 print(input); | 56 print(input); |
57 print('--expected--------------------------------------------------'); | 57 print('--expected--------------------------------------------------'); |
58 print(expected); | 58 print(expected); |
59 print('--actual----------------------------------------------------'); | 59 print('--actual----------------------------------------------------'); |
60 print(actual); | 60 print(actual); |
61 } | 61 } |
62 expect(actual, equals(expected)); | 62 expect(actual, equals(expected)); |
63 }); | 63 }); |
64 } | 64 } |
65 } | 65 } |
66 } | 66 } |
OLD | NEW |