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