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