| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:io'; | 6 import 'dart:io'; |
| 7 | 7 |
| 8 import 'package:compiler/src/commandline_options.dart'; | |
| 9 import 'package:compiler/src/common.dart'; | 8 import 'package:compiler/src/common.dart'; |
| 10 import 'package:compiler/src/common_elements.dart'; | 9 import 'package:compiler/src/common_elements.dart'; |
| 11 import 'package:compiler/src/compiler.dart'; | 10 import 'package:compiler/src/compiler.dart'; |
| 12 import 'package:compiler/src/elements/entities.dart'; | 11 import 'package:compiler/src/elements/entities.dart'; |
| 13 import 'package:expect/expect.dart'; | 12 import 'package:expect/expect.dart'; |
| 14 | 13 |
| 15 import '../annotated_code_helper.dart'; | 14 import '../annotated_code_helper.dart'; |
| 16 import '../memory_compiler.dart'; | 15 import '../memory_compiler.dart'; |
| 17 import '../equivalence/id_equivalence.dart'; | 16 import '../equivalence/id_equivalence.dart'; |
| 18 import '../kernel/compiler_helper.dart'; | 17 import '../kernel/compiler_helper.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 38 await compiler.run(mainUri); | 37 await compiler.run(mainUri); |
| 39 return compiler; | 38 return compiler; |
| 40 } | 39 } |
| 41 | 40 |
| 42 /// Compile [code] from .dill sources. | 41 /// Compile [code] from .dill sources. |
| 43 Future<Compiler> compileFromDill( | 42 Future<Compiler> compileFromDill( |
| 44 AnnotatedCode code, Uri mainUri, List<String> options) async { | 43 AnnotatedCode code, Uri mainUri, List<String> options) async { |
| 45 Compiler compiler = await compileWithDill( | 44 Compiler compiler = await compileWithDill( |
| 46 entryPoint: mainUri, | 45 entryPoint: mainUri, |
| 47 memorySourceFiles: {'main.dart': code.sourceCode}, | 46 memorySourceFiles: {'main.dart': code.sourceCode}, |
| 48 options: [Flags.disableTypeInference]..addAll(options), | 47 options: options, |
| 49 beforeRun: (Compiler compiler) { | 48 beforeRun: (Compiler compiler) { |
| 50 compiler.stopAfterTypeInference = true; | 49 compiler.stopAfterTypeInference = true; |
| 51 }); | 50 }); |
| 52 return compiler; | 51 return compiler; |
| 53 } | 52 } |
| 54 | 53 |
| 55 /// Compute expected and actual data for all members defined in [annotatedCode]. | 54 /// Compute expected and actual data for all members defined in [annotatedCode]. |
| 56 /// | 55 /// |
| 57 /// Actual data is computed using [computeMemberData] and [code] is compiled | 56 /// Actual data is computed using [computeMemberData] and [code] is compiled |
| 58 /// using [compileFunction]. | 57 /// using [compileFunction]. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 }); | 164 }); |
| 166 return withAnnotations(annotations); | 165 return withAnnotations(annotations); |
| 167 } | 166 } |
| 168 } | 167 } |
| 169 | 168 |
| 170 /// Check code for all test files int [data] using [computeFromAst] and | 169 /// Check code for all test files int [data] using [computeFromAst] and |
| 171 /// [computeFromKernel] from the respective front ends. If [skipForKernel] | 170 /// [computeFromKernel] from the respective front ends. If [skipForKernel] |
| 172 /// contains the name of the test file it isn't tested for kernel. | 171 /// contains the name of the test file it isn't tested for kernel. |
| 173 Future checkTests(Directory dataDir, ComputeMemberDataFunction computeFromAst, | 172 Future checkTests(Directory dataDir, ComputeMemberDataFunction computeFromAst, |
| 174 ComputeMemberDataFunction computeFromKernel, | 173 ComputeMemberDataFunction computeFromKernel, |
| 175 {List<String> skipForKernel: const <String>[], bool verbose: false}) async { | 174 {List<String> skipForKernel: const <String>[], |
| 175 List<String> options: const <String>[], |
| 176 bool verbose: false}) async { |
| 176 await for (FileSystemEntity entity in dataDir.list()) { | 177 await for (FileSystemEntity entity in dataDir.list()) { |
| 177 print('----------------------------------------------------------------'); | 178 print('----------------------------------------------------------------'); |
| 178 print('Checking ${entity.uri}'); | 179 print('Checking ${entity.uri}'); |
| 179 print('----------------------------------------------------------------'); | 180 print('----------------------------------------------------------------'); |
| 180 String annotatedCode = await new File.fromUri(entity.uri).readAsString(); | 181 String annotatedCode = await new File.fromUri(entity.uri).readAsString(); |
| 181 print('--from ast------------------------------------------------------'); | 182 print('--from ast------------------------------------------------------'); |
| 182 await checkCode(annotatedCode, computeFromAst, compileFromSource, | 183 await checkCode(annotatedCode, computeFromAst, compileFromSource, |
| 183 verbose: verbose); | 184 options: options, verbose: verbose); |
| 184 if (skipForKernel.contains(entity.uri.pathSegments.last)) { | 185 if (skipForKernel.contains(entity.uri.pathSegments.last)) { |
| 185 print('--skipped for kernel------------------------------------------'); | 186 print('--skipped for kernel------------------------------------------'); |
| 186 continue; | 187 continue; |
| 187 } | 188 } |
| 188 print('--from kernel---------------------------------------------------'); | 189 print('--from kernel---------------------------------------------------'); |
| 189 await checkCode(annotatedCode, computeFromKernel, compileFromDill, | 190 await checkCode(annotatedCode, computeFromKernel, compileFromDill, |
| 190 verbose: verbose); | 191 options: options, verbose: verbose); |
| 191 } | 192 } |
| 192 } | 193 } |
| 193 | 194 |
| 194 /// Compiles the [annotatedCode] with the provided [options] and calls | 195 /// Compiles the [annotatedCode] with the provided [options] and calls |
| 195 /// [computeMemberData] for each member. The result is checked against the | 196 /// [computeMemberData] for each member. The result is checked against the |
| 196 /// expected data derived from [annotatedCode]. | 197 /// expected data derived from [annotatedCode]. |
| 197 Future checkCode( | 198 Future checkCode( |
| 198 String annotatedCode, | 199 String annotatedCode, |
| 199 ComputeMemberDataFunction computeMemberData, | 200 ComputeMemberDataFunction computeMemberData, |
| 200 CompileFunction compileFunction, | 201 CompileFunction compileFunction, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 id = new NodeId(annotation.offset); | 276 id = new NodeId(annotation.offset); |
| 276 expected = text; | 277 expected = text; |
| 277 } else { | 278 } else { |
| 278 id = new ElementId(text.substring(0, colonPos)); | 279 id = new ElementId(text.substring(0, colonPos)); |
| 279 expected = text.substring(colonPos + 1); | 280 expected = text.substring(colonPos + 1); |
| 280 } | 281 } |
| 281 map[id] = expected; | 282 map[id] = expected; |
| 282 } | 283 } |
| 283 return map; | 284 return map; |
| 284 } | 285 } |
| OLD | NEW |