Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(200)

Side by Side Diff: pkg/front_end/test/fasta/shaker_test.dart

Issue 2970273004: Deprecate all diagnostics methods that use strings. (Closed)
Patch Set: Merged with 4df146dd9a465d63344330bf3e45524b927c92ec Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_outline_shaker.dart'; 27 import 'package:front_end/src/fasta/kernel/kernel_outline_shaker.dart';
27 import 'package:front_end/src/fasta/kernel/kernel_target.dart' 28 import 'package:front_end/src/fasta/kernel/kernel_target.dart'
28 show KernelTarget; 29 show KernelTarget;
29 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram; 30 import 'package:front_end/src/fasta/kernel/verifier.dart' show verifyProgram;
30 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff; 31 import 'package:front_end/src/fasta/testing/kernel_chain.dart' show runDiff;
31 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart'; 32 import 'package:front_end/src/fasta/testing/patched_sdk_location.dart';
32 import 'package:front_end/src/fasta/ticker.dart' show Ticker; 33 import 'package:front_end/src/fasta/ticker.dart' show Ticker;
33 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri; 34 import 'package:front_end/src/fasta/translate_uri.dart' show TranslateUri;
34 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri; 35 import 'package:front_end/src/fasta/util/relativize.dart' show relativizeUri;
35 import 'package:kernel/ast.dart' show Program; 36 import 'package:kernel/ast.dart' show Program;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 var libUri = inputUri.resolve('lib/lib.dart'); 112 var libUri = inputUri.resolve('lib/lib.dart');
112 sourceTarget.read(libUri); 113 sourceTarget.read(libUri);
113 sourceTarget.read(inputUri); 114 sourceTarget.read(inputUri);
114 var contents = new File.fromUri(inputUri).readAsStringSync(); 115 var contents = new File.fromUri(inputUri).readAsStringSync();
115 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@"); 116 var showCoreLibraries = contents.contains("@@SHOW_CORE_LIBRARIES@@");
116 await sourceTarget.buildOutlines(); 117 await sourceTarget.buildOutlines();
117 var program = await sourceTarget.buildProgram(); 118 var program = await sourceTarget.buildProgram();
118 bool isIncluded(Uri uri) => !_isTreeShaken(uri); 119 bool isIncluded(Uri uri) => !_isTreeShaken(uri);
119 trimProgram(program, isIncluded); 120 trimProgram(program, isIncluded);
120 return pass(new _IntermediateData(inputUri, program, showCoreLibraries)); 121 return pass(new _IntermediateData(inputUri, program, showCoreLibraries));
121 } on InputError catch (e, s) { 122 } on deprecated_InputError catch (e, s) {
122 return fail(null, e.error, s); 123 return fail(null, e.error, s);
123 } 124 }
124 } 125 }
125 } 126 }
126 127
127 /// Intermediate result from the testing chain. 128 /// Intermediate result from the testing chain.
128 class _IntermediateData { 129 class _IntermediateData {
129 /// The input URI provided to the test. 130 /// The input URI provided to the test.
130 final Uri uri; 131 final Uri uri;
131 132
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 null, "$entryUri doesn't match ${expectedFile.uri}\n$diff"); 203 null, "$entryUri doesn't match ${expectedFile.uri}\n$diff");
203 } 204 }
204 } else { 205 } else {
205 return pass(actualResult); 206 return pass(actualResult);
206 } 207 }
207 } 208 }
208 if (updateExpectations) { 209 if (updateExpectations) {
209 expectedFile.writeAsStringSync(actualResult); 210 expectedFile.writeAsStringSync(actualResult);
210 return pass(actualResult); 211 return pass(actualResult);
211 } else { 212 } else {
212 return fail( 213 return fail(actualResult, """
213 actualResult,
214 """
215 Please create file ${expectedFile.path} with this content: 214 Please create file ${expectedFile.path} with this content:
216 $buffer"""); 215 $buffer""");
217 } 216 }
218 } 217 }
219 } 218 }
220 219
221 /// A special library used only to test the shaker. The suite above will 220 /// A special library used only to test the shaker. The suite above will
222 /// tree-shake the contents of this library. 221 /// tree-shake the contents of this library.
223 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart'; 222 const _specialLibraryPath = 'pkg/front_end/testcases/shaker/lib/lib.dart';
224 223
225 /// Tree-shake dart:* libraries and the library under [_specialLibraryPath]. 224 /// Tree-shake dart:* libraries and the library under [_specialLibraryPath].
226 bool _isTreeShaken(Uri uri) => 225 bool _isTreeShaken(Uri uri) =>
227 uri.isScheme('dart') || 226 uri.isScheme('dart') ||
228 Uri.base.resolveUri(uri).path.endsWith(_specialLibraryPath); 227 Uri.base.resolveUri(uri).path.endsWith(_specialLibraryPath);
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/kernel_generator_impl.dart ('k') | pkg/front_end/test/fasta/testing/suite.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698