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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
4 | 4 |
5 /// Tests basic functionality of the API tree-shaker. | 5 /// Tests basic functionality of the API tree-shaker. |
6 /// | 6 /// |
7 /// Each input file is built and tree-shaken, then we check that the set of | 7 /// Each input file is built and tree-shaken, then we check that the set of |
8 /// libraries, classes, and members that are retained match those declared in an | 8 /// libraries, classes, and members that are retained match those declared in an |
9 /// expectations file. | 9 /// expectations file. |
10 /// | 10 /// |
11 /// Input files may contain markers to turn on flags that configure this | 11 /// Input files may contain markers to turn on flags that configure this |
12 /// runner. Currently only the following marker is recognized: | 12 /// runner. Currently only the following marker is recognized: |
13 /// @@SHOW_CORE_LIBRARIES@@ - whether to check for retained information from | 13 /// @@SHOW_CORE_LIBRARIES@@ - whether to check for retained information from |
14 /// the core libraries. By default this runner only checks for members of | 14 /// the core libraries. By default this runner only checks for members of |
15 /// pkg/front_end/testcases/shaker/lib/lib.dart. | 15 /// pkg/front_end/testcases/shaker/lib/lib.dart. |
16 library fasta.test.shaker_test; | 16 library fasta.test.shaker_test; |
17 | 17 |
18 import 'dart:async' show Future; | 18 import 'dart:async' show Future; |
19 import 'dart:convert' show JSON; | 19 import 'dart:convert' show JSON; |
20 import 'dart:io' show File; | 20 import 'dart:io' show File; |
21 | 21 |
22 export 'package:testing/testing.dart' show Chain, runMe; | 22 export 'package:testing/testing.dart' show Chain, runMe; |
23 import 'package:front_end/physical_file_system.dart'; | 23 import 'package:front_end/physical_file_system.dart'; |
24 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; | 24 import 'package:front_end/src/fasta/dill/dill_target.dart' show DillTarget; |
25 import 'package:front_end/src/fasta/errors.dart' show InputError; | 25 import 'package:front_end/src/fasta/deprecated_problems.dart' |
| 26 show deprecated_InputError; |
26 import 'package:front_end/src/fasta/kernel/kernel_target.dart' | 27 import 'package:front_end/src/fasta/kernel/kernel_target.dart' |
27 show KernelTarget; | 28 show KernelTarget; |
28 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram; | 29 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram; |
29 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff; | 30 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff; |
30 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; | 31 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; |
31 import 'package:front_end/src/fasta/ticker.dart' show Ticker; | 32 import 'package:front_end/src/fasta/ticker.dart' show Ticker; |
32 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; | 33 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; |
33 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri; | 34 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri; |
34 import 'package:kernel/ast.dart' show Program; | 35 import 'package:kernel/ast.dart' show Program; |
35 import 'package:kernel/kernel.dart' show loadProgramFromBytes; | 36 import 'package:kernel/kernel.dart' show loadProgramFromBytes; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 var contents = new File.fromUri(inputUri).readAsStringSync(); | 127 var contents = new File.fromUri(inputUri).readAsStringSync(); |
127 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@"); | 128 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@"); |
128 | 129 |
129 await sourceTarget.buildOutlines(); | 130 await sourceTarget.buildOutlines(); |
130 // Note: We run the tree-shaker as a separate step on this suite to be | 131 // Note: We run the tree-shaker as a separate step on this suite to be |
131 // able to specify what libraries to tree shake (by default only the code | 132 // able to specify what libraries to tree shake (by default only the code |
132 // in the dillTarget gets tree-shaken). We could apply the tree-shaker | 133 // in the dillTarget gets tree-shaken). We could apply the tree-shaker |
133 // twice, but that seems unnecessary. | 134 // twice, but that seems unnecessary. |
134 var program = await sourceTarget.buildProgram(trimDependencies: true); | 135 var program = await sourceTarget.buildProgram(trimDependencies: true); |
135 return pass(new _IntermediateData(inputUri, program, showCoreLibraries)); | 136 return pass(new _IntermediateData(inputUri, program, showCoreLibraries)); |
136 } on InputError catch (e, s) { | 137 } on deprecated_InputError catch (e, s) { |
137 return fail(null, e.error, s); | 138 return fail(null, e.error, s); |
138 } | 139 } |
139 } | 140 } |
140 } | 141 } |
141 | 142 |
142 /// Intermediate result from the testing chain. | 143 /// Intermediate result from the testing chain. |
143 class _IntermediateData { | 144 class _IntermediateData { |
144 /// The input URI provided to the test. | 145 /// The input URI provided to the test. |
145 final Uri uri; | 146 final Uri uri; |
146 | 147 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 """ | 238 """ |
238 Please create file ${expectedFile.path} with this content: | 239 Please create file ${expectedFile.path} with this content: |
239 $buffer"""); | 240 $buffer"""); |
240 } | 241 } |
241 } | 242 } |
242 } | 243 } |
243 | 244 |
244 /// A special library used only to test the shaker. The suite above will | 245 /// A special library used only to test the shaker. The suite above will |
245 /// tree-shake the contents of this library. | 246 /// tree-shake the contents of this library. |
246 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart'; | 247 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart'; |
OLD | NEW |