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:kernel/analyzer/loader.dart'; | 6 import 'package:kernel/analyzer/loader.dart'; |
| 7 import 'package:kernel/application_root.dart'; |
7 import 'package:kernel/kernel.dart'; | 8 import 'package:kernel/kernel.dart'; |
8 import 'package:kernel/target/targets.dart'; | 9 import 'package:kernel/target/targets.dart'; |
9 import 'package:kernel/text/ast_to_text.dart'; | 10 import 'package:kernel/text/ast_to_text.dart'; |
10 import 'package:kernel/verifier.dart'; | 11 import 'package:kernel/verifier.dart'; |
11 import 'package:path/path.dart' as pathlib; | 12 import 'package:path/path.dart' as pathlib; |
12 import 'package:test/test.dart'; | 13 import 'package:test/test.dart'; |
13 | 14 |
14 final String testcaseDirectory = 'pkg/kernel/testcases'; | 15 final String testcaseDirectory = 'pkg/kernel/testcases'; |
15 final String inputDirectory = 'pkg/kernel/testcases/input'; | 16 final String inputDirectory = 'pkg/kernel/testcases/input'; |
16 final String sdkDirectory = 'sdk'; | 17 final String sdkDirectory = 'sdk'; |
17 | 18 |
18 /// A target to be used for testing. | 19 /// A target to be used for testing. |
19 /// | 20 /// |
20 /// To simplify testing dependencies, we avoid transformations that rely on | 21 /// To simplify testing dependencies, we avoid transformations that rely on |
21 /// a patched SDK or any SDK changes that have not landed in the main SDK. | 22 /// a patched SDK or any SDK changes that have not landed in the main SDK. |
22 abstract class TestTarget extends Target { | 23 abstract class TestTarget extends Target { |
23 /// Annotations to apply on the textual output. | 24 /// Annotations to apply on the textual output. |
24 Annotator get annotator => null; | 25 Annotator get annotator => null; |
25 | 26 |
26 List<String> transformProgram(Program program); | 27 List<String> transformProgram(Program program); |
27 } | 28 } |
28 | 29 |
29 void runBaselineTests(String folderName, TestTarget target) { | 30 void runBaselineTests(String folderName, TestTarget target) { |
30 String outputDirectory = '$testcaseDirectory/$folderName'; | 31 String outputDirectory = '$testcaseDirectory/$folderName'; |
31 var batch = new DartLoaderBatch(); | 32 var batch = new DartLoaderBatch(); |
32 Directory directory = new Directory(inputDirectory); | 33 Directory directory = new Directory(inputDirectory); |
| 34 var applicationRoot = new ApplicationRoot(directory.absolute.path); |
33 for (FileSystemEntity file in directory.listSync()) { | 35 for (FileSystemEntity file in directory.listSync()) { |
34 if (file is File && file.path.endsWith('.dart')) { | 36 if (file is File && file.path.endsWith('.dart')) { |
35 String name = pathlib.basename(file.path); | 37 String name = pathlib.basename(file.path); |
36 test(name, () async { | 38 test(name, () async { |
37 String dartPath = file.path; | 39 Uri dartPath = |
| 40 new Uri(scheme: 'file', path: pathlib.absolute(file.path)); |
38 String shortName = pathlib.withoutExtension(name); | 41 String shortName = pathlib.withoutExtension(name); |
39 String filenameOfBaseline = '$outputDirectory/$shortName.baseline.txt'; | 42 String filenameOfBaseline = '$outputDirectory/$shortName.baseline.txt'; |
40 String filenameOfCurrent = '$outputDirectory/$shortName.current.txt'; | 43 String filenameOfCurrent = '$outputDirectory/$shortName.current.txt'; |
41 | 44 |
42 var repository = new Repository(); | 45 var repository = new Repository(); |
43 var loader = await batch.getLoader( | 46 var loader = await batch.getLoader( |
44 repository, | 47 repository, |
45 new DartOptions( | 48 new DartOptions( |
46 strongMode: target.strongMode, | 49 strongMode: target.strongMode, |
47 sdk: sdkDirectory, | 50 sdk: sdkDirectory, |
48 declaredVariables: target.extraDeclaredVariables)); | 51 declaredVariables: target.extraDeclaredVariables, |
| 52 applicationRoot: applicationRoot)); |
49 var program = loader.loadProgram(dartPath, target: target); | 53 var program = loader.loadProgram(dartPath, target: target); |
50 verifyProgram(program); | 54 verifyProgram(program); |
51 var errors = target.transformProgram(program); | 55 var errors = target.transformProgram(program); |
52 verifyProgram(program); | 56 verifyProgram(program); |
53 | 57 |
54 var buffer = new StringBuffer(); | 58 var buffer = new StringBuffer(); |
55 for (var error in errors) { | 59 for (var error in errors) { |
56 buffer.writeln('// $error'); | 60 buffer.writeln('// $error'); |
57 } | 61 } |
58 new Printer(buffer, annotator: target.annotator) | 62 new Printer(buffer, annotator: target.annotator) |
(...skipping 12 matching lines...) Expand all Loading... |
71 ' rm $filenameOfBaseline\n' | 75 ' rm $filenameOfBaseline\n' |
72 'Command to see the diff:\n' | 76 'Command to see the diff:\n' |
73 ' diff -cd $outputDirectory/$shortName.{baseline,current}.txt' | 77 ' diff -cd $outputDirectory/$shortName.{baseline,current}.txt' |
74 '\n'); | 78 '\n'); |
75 } | 79 } |
76 } | 80 } |
77 }); | 81 }); |
78 } | 82 } |
79 } | 83 } |
80 } | 84 } |
OLD | NEW |