Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: tests/compiler/dart2js/kernel/visitor_test.dart

Issue 2609433002: Fix rasta unittests: now unit tests need to run the full compiler to use its (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/compiler/dart2js/kernel/class_hierarchy_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 'package:compiler/src/compiler.dart' show Compiler; 10 import 'package:compiler/src/compiler.dart' show Compiler;
10 import 'package:compiler/src/elements/elements.dart'; 11 import 'package:compiler/src/elements/elements.dart';
11 import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend; 12 import 'package:compiler/src/js_backend/backend.dart' show JavaScriptBackend;
12 import 'package:compiler/src/commandline_options.dart' show Flags; 13 import 'package:compiler/src/commandline_options.dart' show Flags;
13 import 'package:kernel/ast.dart'; 14 import 'package:kernel/ast.dart';
14 import 'package:kernel/text/ast_to_text.dart'; 15 import 'package:kernel/text/ast_to_text.dart';
15 import 'package:kernel/transformations/mixin_full_resolution.dart'; 16 import 'package:kernel/transformations/mixin_full_resolution.dart';
16 import 'package:kernel/class_hierarchy.dart'; 17 import 'package:kernel/class_hierarchy.dart';
17 import 'package:path/path.dart' as pathlib; 18 import 'package:path/path.dart' as pathlib;
18 import 'package:test/test.dart'; 19 import 'package:test/test.dart';
19 20
20 import '../memory_compiler.dart'; 21 import '../memory_compiler.dart';
21 22
22 const String TESTCASE_DIR = 'pkg/kernel/testcases/'; 23 const String TESTCASE_DIR = 'pkg/kernel/testcases/';
23 24
24 const List<String> SKIP_TESTS = const <String>[ 25 const List<String> SKIP_TESTS = const <String>[
25 /// The test expects an unpatched api. 26 /// The test expects an unpatched api.
26 'external', 27 'external',
27 ]; 28 ];
28 29
29 main(List<String> arguments) { 30 main(List<String> arguments) async {
30 Compiler compiler = compilerFor( 31
31 options: [Flags.analyzeOnly, Flags.analyzeMain, Flags.useKernel]);
32 Directory directory = new Directory('${TESTCASE_DIR}/input'); 32 Directory directory = new Directory('${TESTCASE_DIR}/input');
33 for (FileSystemEntity file in directory.listSync()) { 33 for (FileSystemEntity file in directory.listSync()) {
34 if (file is File && file.path.endsWith('.dart')) { 34 if (file is File && file.path.endsWith('.dart')) {
35 String name = pathlib.basenameWithoutExtension(file.path); 35 String name = pathlib.basenameWithoutExtension(file.path);
36 bool selected = arguments.contains(name); 36 bool selected = arguments.contains(name);
37 if (!selected) { 37 if (!selected) {
38 if (arguments.isNotEmpty) continue; 38 if (arguments.isNotEmpty) continue;
39 if (SKIP_TESTS.contains(name)) continue; 39 if (SKIP_TESTS.contains(name)) continue;
40 } 40 }
41 41
42 test(name, () async { 42 test(name, () async {
43 LibraryElement library = await compiler.analyzeUri(file.absolute.uri); 43 var compiler = await newCompiler();
44 await compiler.run(file.absolute.uri);
45 LibraryElement library =
46 await compiler.libraryLoader.loadLibrary(file.absolute.uri);
44 JavaScriptBackend backend = compiler.backend; 47 JavaScriptBackend backend = compiler.backend;
45 StringBuffer buffer = new StringBuffer(); 48 StringBuffer buffer = new StringBuffer();
46 Program program = backend.kernelTask.buildProgram(library); 49 Program program = backend.kernelTask.buildProgram(library);
47 new MixinFullResolution().transform(program); 50 new MixinFullResolution().transform(program);
48 new Printer(buffer) 51 new Printer(buffer)
49 .writeLibraryFile(program.mainMethod.enclosingLibrary); 52 .writeLibraryFile(program.mainMethod.enclosingLibrary);
50 String actual = buffer.toString(); 53 String actual = buffer.toString();
51 String expected = 54 String expected =
52 new File('${TESTCASE_DIR}/spec-mode/$name.baseline.txt') 55 new File('${TESTCASE_DIR}/spec-mode/$name.baseline.txt')
53 .readAsStringSync(); 56 .readAsStringSync();
54 if (selected) { 57 if (selected) {
55 String input = 58 String input =
56 new File('${TESTCASE_DIR}/input/$name.dart').readAsStringSync(); 59 new File('${TESTCASE_DIR}/input/$name.dart').readAsStringSync();
57 print('============================================================'); 60 print('============================================================');
58 print(name); 61 print(name);
59 print('--input-----------------------------------------------------'); 62 print('--input-----------------------------------------------------');
60 print(input); 63 print(input);
61 print('--expected--------------------------------------------------'); 64 print('--expected--------------------------------------------------');
62 print(expected); 65 print(expected);
63 print('--actual----------------------------------------------------'); 66 print('--actual----------------------------------------------------');
64 print(actual); 67 print(actual);
65 } 68 }
66 expect(actual, equals(expected)); 69 expect(actual, equals(expected));
67 }); 70 });
68 } 71 }
69 } 72 }
70 } 73 }
74
75 Future<Compiler> newCompiler() async {
76 Compiler compiler = compilerFor(
77 options: [Flags.analyzeOnly, Flags.analyzeAll, Flags.useKernel]);
78 await compiler.setupSdk();
79
80 // The visitor no longer enqueues elements that are not reachable from the
81 // program. The mixin-full resolution transform run by the test expects to
82 // find dart.core::Iterator.
83 var core = await compiler.libraryLoader.loadLibrary(Uri.parse('dart:core'));
84 var cls = core.implementation.localLookup('Iterator');
85 cls.ensureResolved(compiler.resolution);
86 return compiler;
87 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/kernel/class_hierarchy_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698