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 import 'dart:io'; | 4 import 'dart:io'; |
5 | 5 |
6 import 'package:analyzer/src/kernel/loader.dart'; | 6 import 'package:analyzer/src/kernel/loader.dart'; |
7 import 'package:kernel/application_root.dart'; | 7 import 'package:kernel/application_root.dart'; |
| 8 import 'package:kernel/class_hierarchy.dart'; |
8 import 'package:kernel/core_types.dart'; | 9 import 'package:kernel/core_types.dart'; |
9 import 'package:kernel/kernel.dart'; | 10 import 'package:kernel/kernel.dart'; |
10 import 'package:kernel/target/targets.dart'; | 11 import 'package:kernel/target/targets.dart'; |
11 import 'package:kernel/text/ast_to_text.dart'; | 12 import 'package:kernel/text/ast_to_text.dart'; |
12 import 'package:kernel/verifier.dart'; | 13 import 'package:kernel/verifier.dart'; |
13 import 'package:path/path.dart' as pathlib; | 14 import 'package:path/path.dart' as pathlib; |
14 import 'package:test/test.dart'; | 15 import 'package:test/test.dart'; |
15 | 16 |
16 final String testcaseDirectory = 'pkg/kernel/testcases'; | 17 final String testcaseDirectory = 'pkg/kernel/testcases'; |
17 final String inputDirectory = 'pkg/kernel/testcases/input'; | 18 final String inputDirectory = 'pkg/kernel/testcases/input'; |
18 final String sdkDirectory = 'sdk'; | 19 final String sdkDirectory = 'sdk'; |
19 | 20 |
20 /// A target to be used for testing. | 21 /// A target to be used for testing. |
21 /// | 22 /// |
22 /// To simplify testing dependencies, we avoid transformations that rely on | 23 /// To simplify testing dependencies, we avoid transformations that rely on |
23 /// a patched SDK or any SDK changes that have not landed in the main SDK. | 24 /// a patched SDK or any SDK changes that have not landed in the main SDK. |
24 abstract class TestTarget extends Target { | 25 abstract class TestTarget extends Target { |
25 /// Annotations to apply on the textual output. | 26 /// Annotations to apply on the textual output. |
26 Annotator get annotator => null; | 27 Annotator get annotator => null; |
27 | 28 |
28 // Return a list of strings so that we can accumulate errors. | 29 // Return a list of strings so that we can accumulate errors. |
29 List<String> performModularTransformations( | 30 List<String> performModularTransformations( |
30 CoreTypes coreTypes, Program program); | 31 CoreTypes coreTypes, ClassHierarchy hierarchy, Program program); |
31 List<String> performGlobalTransformations( | 32 List<String> performGlobalTransformations( |
32 CoreTypes coreTypes, Program program); | 33 CoreTypes coreTypes, Program program); |
33 } | 34 } |
34 | 35 |
35 void runBaselineTests(String folderName, TestTarget target) { | 36 void runBaselineTests(String folderName, TestTarget target) { |
36 String outputDirectory = '$testcaseDirectory/$folderName'; | 37 String outputDirectory = '$testcaseDirectory/$folderName'; |
37 var batch = new DartLoaderBatch(); | 38 var batch = new DartLoaderBatch(); |
38 Directory directory = new Directory(inputDirectory); | 39 Directory directory = new Directory(inputDirectory); |
39 var applicationRoot = new ApplicationRoot(directory.absolute.path); | 40 var applicationRoot = new ApplicationRoot(directory.absolute.path); |
40 for (FileSystemEntity file in directory.listSync()) { | 41 for (FileSystemEntity file in directory.listSync()) { |
41 if (file is File && file.path.endsWith('.dart')) { | 42 if (file is File && file.path.endsWith('.dart')) { |
42 String name = pathlib.basename(file.path); | 43 String name = pathlib.basename(file.path); |
43 test(name, () async { | 44 test(name, () async { |
44 Uri dartPath = | 45 Uri dartPath = |
45 new Uri(scheme: 'file', path: pathlib.absolute(file.path)); | 46 new Uri(scheme: 'file', path: pathlib.absolute(file.path)); |
46 String shortName = pathlib.withoutExtension(name); | 47 String shortName = pathlib.withoutExtension(name); |
47 String filenameOfBaseline = '$outputDirectory/$shortName.baseline.txt'; | 48 String filenameOfBaseline = '$outputDirectory/$shortName.baseline.txt'; |
48 String filenameOfCurrent = '$outputDirectory/$shortName.current.txt'; | 49 String filenameOfCurrent = '$outputDirectory/$shortName.current.txt'; |
49 | 50 |
50 var program = new Program(); | 51 var program = new Program(); |
51 var coreTypes = new CoreTypes(program); | 52 var coreTypes = new CoreTypes(program); |
| 53 var hierarchy = new ClosedWorldClassHierarchy(program); |
52 var loader = await batch.getLoader( | 54 var loader = await batch.getLoader( |
53 program, | 55 program, |
54 new DartOptions( | 56 new DartOptions( |
55 strongMode: target.strongMode, | 57 strongMode: target.strongMode, |
56 sdk: sdkDirectory, | 58 sdk: sdkDirectory, |
57 declaredVariables: target.extraDeclaredVariables, | 59 declaredVariables: target.extraDeclaredVariables, |
58 applicationRoot: applicationRoot)); | 60 applicationRoot: applicationRoot)); |
59 loader.loadProgram(dartPath, target: target); | 61 loader.loadProgram(dartPath, target: target); |
60 verifyProgram(program); | 62 verifyProgram(program); |
61 var errors = <String>[]; | 63 var errors = <String>[]; |
62 errors.addAll(target.performModularTransformations(coreTypes, program)); | 64 errors.addAll(target.performModularTransformations( |
| 65 coreTypes, hierarchy, program)); |
63 verifyProgram(program); | 66 verifyProgram(program); |
64 errors.addAll(target.performGlobalTransformations(coreTypes, program)); | 67 errors.addAll(target.performGlobalTransformations(coreTypes, program)); |
65 verifyProgram(program); | 68 verifyProgram(program); |
66 | 69 |
67 var buffer = new StringBuffer(); | 70 var buffer = new StringBuffer(); |
68 for (var error in errors) { | 71 for (var error in errors) { |
69 buffer.writeln('// $error'); | 72 buffer.writeln('// $error'); |
70 } | 73 } |
71 new Printer(buffer, annotator: target.annotator) | 74 new Printer(buffer, annotator: target.annotator) |
72 .writeLibraryFile(program.mainMethod.enclosingLibrary); | 75 .writeLibraryFile(program.mainMethod.enclosingLibrary); |
(...skipping 11 matching lines...) Expand all Loading... |
84 ' rm $filenameOfBaseline\n' | 87 ' rm $filenameOfBaseline\n' |
85 'Command to see the diff:\n' | 88 'Command to see the diff:\n' |
86 ' diff -cd $outputDirectory/$shortName.{baseline,current}.txt' | 89 ' diff -cd $outputDirectory/$shortName.{baseline,current}.txt' |
87 '\n'); | 90 '\n'); |
88 } | 91 } |
89 } | 92 } |
90 }); | 93 }); |
91 } | 94 } |
92 } | 95 } |
93 } | 96 } |
OLD | NEW |