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

Side by Side Diff: tests/compiler/dart2js/exit_code_test.dart

Issue 2123073003: remove dependency on compiler from resolution (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 // Test the exit code of dart2js in case of exceptions, errors, warnings, etc. 5 // Test the exit code of dart2js in case of exceptions, errors, warnings, etc.
6 6
7
8 import 'dart:async'; 7 import 'dart:async';
9 import 'dart:io' show Platform; 8 import 'dart:io' show Platform;
10 9
11 import 'package:async_helper/async_helper.dart'; 10 import 'package:async_helper/async_helper.dart';
12 import 'package:expect/expect.dart'; 11 import 'package:expect/expect.dart';
13 12
14 import 'package:compiler/compiler_new.dart' as api; 13 import 'package:compiler/compiler_new.dart' as api;
15 import 'package:compiler/src/common/codegen.dart'; 14 import 'package:compiler/src/common/codegen.dart';
16 import 'package:compiler/src/compile_time_constants.dart'; 15 import 'package:compiler/src/compile_time_constants.dart';
17 import 'package:compiler/src/compiler.dart'; 16 import 'package:compiler/src/compiler.dart';
(...skipping 12 matching lines...) Expand all
30 import 'package:compiler/src/scanner/scanner_task.dart'; 29 import 'package:compiler/src/scanner/scanner_task.dart';
31 import 'package:compiler/src/universe/world_impact.dart'; 30 import 'package:compiler/src/universe/world_impact.dart';
32 import 'diagnostic_reporter_helper.dart'; 31 import 'diagnostic_reporter_helper.dart';
33 32
34 class TestCompiler extends apiimpl.CompilerImpl { 33 class TestCompiler extends apiimpl.CompilerImpl {
35 final String testMarker; 34 final String testMarker;
36 final String testType; 35 final String testType;
37 final Function onTest; 36 final Function onTest;
38 TestDiagnosticReporter reporter; 37 TestDiagnosticReporter reporter;
39 38
40 TestCompiler(api.CompilerInput inputProvider, 39 TestCompiler(
41 api.CompilerOutput outputProvider, 40 api.CompilerInput inputProvider,
42 api.CompilerDiagnostics handler, 41 api.CompilerOutput outputProvider,
43 CompilerOptions options, 42 api.CompilerDiagnostics handler,
44 String this.testMarker, 43 CompilerOptions options,
45 String this.testType, 44 String this.testMarker,
46 Function this.onTest) 45 String this.testType,
46 Function this.onTest)
47 : reporter = new TestDiagnosticReporter(), 47 : reporter = new TestDiagnosticReporter(),
48 super(inputProvider, outputProvider, handler, options) { 48 super(inputProvider, outputProvider, handler, options) {
49 reporter.compiler = this; 49 reporter.compiler = this;
50 reporter.reporter = super.reporter; 50 reporter.reporter = super.reporter;
51 test('Compiler'); 51 test('Compiler');
52 } 52 }
53 53
54 @override 54 @override
55 ScannerTask createScannerTask() => new TestScanner(this); 55 ScannerTask createScannerTask() => new TestScanner(this);
56 56
(...skipping 23 matching lines...) Expand all
80 } 80 }
81 81
82 WorldImpact codegen(CodegenWorkItem work, CodegenEnqueuer world) { 82 WorldImpact codegen(CodegenWorkItem work, CodegenEnqueuer world) {
83 test('Compiler.codegen'); 83 test('Compiler.codegen');
84 return super.codegen(work, world); 84 return super.codegen(work, world);
85 } 85 }
86 86
87 test(String marker) { 87 test(String marker) {
88 if (marker == testMarker) { 88 if (marker == testMarker) {
89 switch (testType) { 89 switch (testType) {
90 case 'assert': 90 case 'assert':
91 onTest(testMarker, testType); 91 onTest(testMarker, testType);
92 assert(false); 92 assert(false);
93 break; 93 break;
94 case 'invariant': 94 case 'invariant':
95 onTest(testMarker, testType); 95 onTest(testMarker, testType);
96 invariant(NO_LOCATION_SPANNABLE, false, message: marker); 96 invariant(NO_LOCATION_SPANNABLE, false, message: marker);
97 break; 97 break;
98 case 'warning': 98 case 'warning':
99 onTest(testMarker, testType); 99 onTest(testMarker, testType);
100 reporter.reportWarningMessage( 100 reporter.reportWarningMessage(
101 NO_LOCATION_SPANNABLE, 101 NO_LOCATION_SPANNABLE, MessageKind.GENERIC, {'text': marker});
102 MessageKind.GENERIC, {'text': marker}); 102 break;
103 break; 103 case 'error':
104 case 'error': 104 onTest(testMarker, testType);
105 onTest(testMarker, testType); 105 reporter.reportErrorMessage(
106 reporter.reportErrorMessage( 106 NO_LOCATION_SPANNABLE, MessageKind.GENERIC, {'text': marker});
107 NO_LOCATION_SPANNABLE, 107 break;
108 MessageKind.GENERIC, {'text': marker}); 108 case 'internalError':
109 break; 109 onTest(testMarker, testType);
110 case 'internalError': 110 reporter.internalError(NO_LOCATION_SPANNABLE, marker);
111 onTest(testMarker, testType); 111 break;
112 reporter.internalError(NO_LOCATION_SPANNABLE, marker); 112 case 'NoSuchMethodError':
113 break; 113 onTest(testMarker, testType);
114 case 'NoSuchMethodError': 114 null.foo;
115 onTest(testMarker, testType); 115 break;
116 null.foo; 116 case '':
117 break; 117 onTest(testMarker, testType);
118 case '': 118 break;
119 onTest(testMarker, testType);
120 break;
121 } 119 }
122 } 120 }
123 } 121 }
124 } 122 }
125 123
126 class TestDiagnosticReporter extends DiagnosticReporterWrapper { 124 class TestDiagnosticReporter extends DiagnosticReporterWrapper {
127 TestCompiler compiler; 125 TestCompiler compiler;
128 DiagnosticReporter reporter; 126 DiagnosticReporter reporter;
129 127
130 @override 128 @override
(...skipping 12 matching lines...) Expand all
143 : compiler = compiler, 141 : compiler = compiler,
144 super(compiler.dietParser, compiler.reporter, compiler.measurer); 142 super(compiler.dietParser, compiler.reporter, compiler.measurer);
145 143
146 void scanElements(CompilationUnitElement compilationUnit) { 144 void scanElements(CompilationUnitElement compilationUnit) {
147 compiler.test('ScannerTask.scanElements'); 145 compiler.test('ScannerTask.scanElements');
148 super.scanElements(compilationUnit); 146 super.scanElements(compilationUnit);
149 } 147 }
150 } 148 }
151 149
152 class TestResolver extends ResolverTask { 150 class TestResolver extends ResolverTask {
151 final TestCompiler _compiler;
153 TestResolver(TestCompiler compiler, ConstantCompiler constantCompiler) 152 TestResolver(TestCompiler compiler, ConstantCompiler constantCompiler)
154 : super(compiler, constantCompiler); 153 : this._compiler = compiler,
154 super(compiler.resolution, constantCompiler, compiler.world,
155 compiler.measurer);
155 156
156 TestCompiler get compiler => super.compiler; 157 TestCompiler get compiler => this._compiler;
157 158
158 void computeClassMembers(ClassElement element) { 159 void computeClassMembers(ClassElement element) {
159 compiler.test('ResolverTask.computeClassMembers'); 160 compiler.test('ResolverTask.computeClassMembers');
160 super.computeClassMembers(element); 161 super.computeClassMembers(element);
161 } 162 }
162 } 163 }
163 164
164 int checkedResults = 0; 165 int checkedResults = 0;
165 166
166 Future testExitCode( 167 Future testExitCode(
167 String marker, String type, int expectedExitCode, List options) { 168 String marker, String type, int expectedExitCode, List options) {
168 bool testOccurred = false; 169 bool testOccurred = false;
169 170
170 void onTest(String testMarker, String testType) { 171 void onTest(String testMarker, String testType) {
171 if (testMarker == marker && testType == type) { 172 if (testMarker == marker && testType == type) {
172 testOccurred = true; 173 testOccurred = true;
173 } 174 }
174 } 175 }
175 return new Future(() { 176 return new Future(() {
176 Future<api.CompilationResult> compile( 177 Future<api.CompilationResult> compile(
177 CompilerOptions compilerOptions, 178 CompilerOptions compilerOptions,
178 api.CompilerInput compilerInput, 179 api.CompilerInput compilerInput,
179 api.CompilerDiagnostics compilerDiagnostics, 180 api.CompilerDiagnostics compilerDiagnostics,
180 api.CompilerOutput compilerOutput) { 181 api.CompilerOutput compilerOutput) {
181 compilerOutput = const NullCompilerOutput(); 182 compilerOutput = const NullCompilerOutput();
182 // Use this to silence the test when debugging: 183 // Use this to silence the test when debugging:
183 // handler = (uri, begin, end, message, kind) {}; 184 // handler = (uri, begin, end, message, kind) {};
184 Compiler compiler = new TestCompiler( 185 Compiler compiler = new TestCompiler(compilerInput, compilerOutput,
185 compilerInput, 186 compilerDiagnostics, compilerOptions, marker, type, onTest);
186 compilerOutput,
187 compilerDiagnostics,
188 compilerOptions,
189 marker,
190 type,
191 onTest);
192 return compiler.run(compilerOptions.entryPoint).then((bool success) { 187 return compiler.run(compilerOptions.entryPoint).then((bool success) {
193 return new api.CompilationResult(compiler, isSuccess: success); 188 return new api.CompilationResult(compiler, isSuccess: success);
194 }); 189 });
195 } 190 }
196 191
197 int foundExitCode; 192 int foundExitCode;
198 193
199 checkResult() { 194 checkResult() {
200 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur'); 195 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur');
201 if (foundExitCode == null) foundExitCode = 0; 196 if (foundExitCode == null) foundExitCode = 0;
202 print('testExitCode($marker, $type) ' 197 print('testExitCode($marker, $type) '
203 'exitCode=$foundExitCode expected=$expectedExitCode'); 198 'exitCode=$foundExitCode expected=$expectedExitCode');
204 Expect.equals(expectedExitCode, foundExitCode, 199 Expect.equals(
200 expectedExitCode,
201 foundExitCode,
205 'testExitCode($marker, $type) ' 202 'testExitCode($marker, $type) '
206 'exitCode=$foundExitCode expected=${expectedExitCode}'); 203 'exitCode=$foundExitCode expected=${expectedExitCode}');
207 checkedResults++; 204 checkedResults++;
208 } 205 }
209 206
210 void exit(exitCode) { 207 void exit(exitCode) {
211 if (foundExitCode == null) { 208 if (foundExitCode == null) {
212 foundExitCode = exitCode; 209 foundExitCode = exitCode;
213 } 210 }
214 }; 211 }
212 ;
215 213
216 entry.exitFunc = exit; 214 entry.exitFunc = exit;
217 entry.compileFunc = compile; 215 entry.compileFunc = compile;
218 216
219 List<String> args = new List<String>.from(options) 217 List<String> args = new List<String>.from(options)
220 ..add("--library-root=${Platform.script.resolve('../../../sdk/')}") 218 ..add("--library-root=${Platform.script.resolve('../../../sdk/')}")
221 ..add("tests/compiler/dart2js/data/exit_code_helper.dart"); 219 ..add("tests/compiler/dart2js/data/exit_code_helper.dart");
222 Future result = entry.internalMain(args); 220 Future result = entry.internalMain(args);
223 return result.catchError((e, s) { 221 return result.catchError((e, s) {
224 // Capture crashes. 222 // Capture crashes.
225 }).whenComplete(checkResult); 223 }).whenComplete(checkResult);
226 }); 224 });
227 } 225 }
228 226
229 Future testExitCodes( 227 Future testExitCodes(
230 String marker, Map<String,int> expectedExitCodes, List<String> options) { 228 String marker, Map<String, int> expectedExitCodes, List<String> options) {
231 return Future.forEach(expectedExitCodes.keys, (String type) { 229 return Future.forEach(expectedExitCodes.keys, (String type) {
232 return testExitCode(marker, type, expectedExitCodes[type], options); 230 return testExitCode(marker, type, expectedExitCodes[type], options);
233 }); 231 });
234 } 232 }
235 233
236 void main() { 234 void main() {
237 bool isCheckedMode = false; 235 bool isCheckedMode = false;
238 assert((isCheckedMode = true)); 236 assert((isCheckedMode = true));
239 237
240 Map _expectedExitCode({bool beforeRun: false, bool fatalWarnings: false}) { 238 Map _expectedExitCode({bool beforeRun: false, bool fatalWarnings: false}) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 'ResolverTask.computeClassMembers': duringRun, 271 'ResolverTask.computeClassMembers': duringRun,
274 }; 272 };
275 int totalExpectedErrors = 0; 273 int totalExpectedErrors = 0;
276 274
277 asyncTest(() async { 275 asyncTest(() async {
278 for (String marker in tests.keys) { 276 for (String marker in tests.keys) {
279 var expected = _expectedExitCode(beforeRun: tests[marker]); 277 var expected = _expectedExitCode(beforeRun: tests[marker]);
280 totalExpectedErrors += expected.length; 278 totalExpectedErrors += expected.length;
281 await testExitCodes(marker, expected, []); 279 await testExitCodes(marker, expected, []);
282 280
283 expected = _expectedExitCode( 281 expected =
284 beforeRun: tests[marker], fatalWarnings: true); 282 _expectedExitCode(beforeRun: tests[marker], fatalWarnings: true);
285 totalExpectedErrors += expected.length; 283 totalExpectedErrors += expected.length;
286 await testExitCodes(marker, expected, ['--fatal-warnings']); 284 await testExitCodes(marker, expected, ['--fatal-warnings']);
287 } 285 }
288 286
289 Expect.equals(totalExpectedErrors, checkedResults); 287 Expect.equals(totalExpectedErrors, checkedResults);
290 }); 288 });
291 } 289 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698