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