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

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

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: Created 4 years, 3 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, Enqueuer world) { 82 WorldImpact codegen(CodegenWorkItem work, Enqueuer 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 16 matching lines...) Expand all
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 {
153 final TestCompiler compiler; 151 final TestCompiler compiler;
154 152
155 TestResolver(TestCompiler compiler, ConstantCompiler constantCompiler) 153 TestResolver(TestCompiler compiler, ConstantCompiler constantCompiler)
156 : this.compiler = compiler, 154 : this.compiler = compiler,
157 super( 155 super(compiler.resolution, constantCompiler, compiler.world,
158 compiler.resolution,
159 constantCompiler,
160 compiler.world,
161 compiler.measurer); 156 compiler.measurer);
162 157
163 void computeClassMembers(ClassElement element) { 158 void computeClassMembers(ClassElement element) {
164 compiler.test('ResolverTask.computeClassMembers'); 159 compiler.test('ResolverTask.computeClassMembers');
165 super.computeClassMembers(element); 160 super.computeClassMembers(element);
166 } 161 }
167 } 162 }
168 163
169 int checkedResults = 0; 164 int checkedResults = 0;
170 165
171 Future testExitCode( 166 Future testExitCode(
172 String marker, String type, int expectedExitCode, List options) { 167 String marker, String type, int expectedExitCode, List options) {
173 bool testOccurred = false; 168 bool testOccurred = false;
174 169
175 void onTest(String testMarker, String testType) { 170 void onTest(String testMarker, String testType) {
176 if (testMarker == marker && testType == type) { 171 if (testMarker == marker && testType == type) {
177 testOccurred = true; 172 testOccurred = true;
178 } 173 }
179 } 174 }
180 return new Future(() { 175 return new Future(() {
181 Future<api.CompilationResult> compile( 176 Future<api.CompilationResult> compile(
182 CompilerOptions compilerOptions, 177 CompilerOptions compilerOptions,
183 api.CompilerInput compilerInput, 178 api.CompilerInput compilerInput,
184 api.CompilerDiagnostics compilerDiagnostics, 179 api.CompilerDiagnostics compilerDiagnostics,
185 api.CompilerOutput compilerOutput) { 180 api.CompilerOutput compilerOutput) {
186 compilerOutput = const NullCompilerOutput(); 181 compilerOutput = const NullCompilerOutput();
187 // Use this to silence the test when debugging: 182 // Use this to silence the test when debugging:
188 // handler = (uri, begin, end, message, kind) {}; 183 // handler = (uri, begin, end, message, kind) {};
189 Compiler compiler = new TestCompiler( 184 Compiler compiler = new TestCompiler(compilerInput, compilerOutput,
190 compilerInput, 185 compilerDiagnostics, compilerOptions, marker, type, onTest);
191 compilerOutput,
192 compilerDiagnostics,
193 compilerOptions,
194 marker,
195 type,
196 onTest);
197 return compiler.run(compilerOptions.entryPoint).then((bool success) { 186 return compiler.run(compilerOptions.entryPoint).then((bool success) {
198 return new api.CompilationResult(compiler, isSuccess: success); 187 return new api.CompilationResult(compiler, isSuccess: success);
199 }); 188 });
200 } 189 }
201 190
202 int foundExitCode; 191 int foundExitCode;
203 192
204 checkResult() { 193 checkResult() {
205 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur'); 194 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur');
206 if (foundExitCode == null) foundExitCode = 0; 195 if (foundExitCode == null) foundExitCode = 0;
207 print('testExitCode($marker, $type) ' 196 print('testExitCode($marker, $type) '
208 'exitCode=$foundExitCode expected=$expectedExitCode'); 197 'exitCode=$foundExitCode expected=$expectedExitCode');
209 Expect.equals(expectedExitCode, foundExitCode, 198 Expect.equals(
199 expectedExitCode,
200 foundExitCode,
210 'testExitCode($marker, $type) ' 201 'testExitCode($marker, $type) '
211 'exitCode=$foundExitCode expected=${expectedExitCode}'); 202 'exitCode=$foundExitCode expected=${expectedExitCode}');
212 checkedResults++; 203 checkedResults++;
213 } 204 }
214 205
215 void exit(exitCode) { 206 void exit(exitCode) {
216 if (foundExitCode == null) { 207 if (foundExitCode == null) {
217 foundExitCode = exitCode; 208 foundExitCode = exitCode;
218 } 209 }
219 }; 210 }
211 ;
220 212
221 entry.exitFunc = exit; 213 entry.exitFunc = exit;
222 entry.compileFunc = compile; 214 entry.compileFunc = compile;
223 215
224 List<String> args = new List<String>.from(options) 216 List<String> args = new List<String>.from(options)
225 ..add("--library-root=${Platform.script.resolve('../../../sdk/')}") 217 ..add("--library-root=${Platform.script.resolve('../../../sdk/')}")
226 ..add("tests/compiler/dart2js/data/exit_code_helper.dart"); 218 ..add("tests/compiler/dart2js/data/exit_code_helper.dart");
227 Future result = entry.internalMain(args); 219 Future result = entry.internalMain(args);
228 return result.catchError((e, s) { 220 return result.catchError((e, s) {
229 // Capture crashes. 221 // Capture crashes.
230 }).whenComplete(checkResult); 222 }).whenComplete(checkResult);
231 }); 223 });
232 } 224 }
233 225
234 Future testExitCodes( 226 Future testExitCodes(
235 String marker, Map<String,int> expectedExitCodes, List<String> options) { 227 String marker, Map<String, int> expectedExitCodes, List<String> options) {
236 return Future.forEach(expectedExitCodes.keys, (String type) { 228 return Future.forEach(expectedExitCodes.keys, (String type) {
237 return testExitCode(marker, type, expectedExitCodes[type], options); 229 return testExitCode(marker, type, expectedExitCodes[type], options);
238 }); 230 });
239 } 231 }
240 232
241 void main() { 233 void main() {
242 bool isCheckedMode = false; 234 bool isCheckedMode = false;
243 assert((isCheckedMode = true)); 235 assert((isCheckedMode = true));
244 236
245 Map _expectedExitCode({bool beforeRun: false, bool fatalWarnings: false}) { 237 Map _expectedExitCode({bool beforeRun: false, bool fatalWarnings: false}) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 'ResolverTask.computeClassMembers': duringRun, 270 'ResolverTask.computeClassMembers': duringRun,
279 }; 271 };
280 int totalExpectedErrors = 0; 272 int totalExpectedErrors = 0;
281 273
282 asyncTest(() async { 274 asyncTest(() async {
283 for (String marker in tests.keys) { 275 for (String marker in tests.keys) {
284 var expected = _expectedExitCode(beforeRun: tests[marker]); 276 var expected = _expectedExitCode(beforeRun: tests[marker]);
285 totalExpectedErrors += expected.length; 277 totalExpectedErrors += expected.length;
286 await testExitCodes(marker, expected, []); 278 await testExitCodes(marker, expected, []);
287 279
288 expected = _expectedExitCode( 280 expected =
289 beforeRun: tests[marker], fatalWarnings: true); 281 _expectedExitCode(beforeRun: tests[marker], fatalWarnings: true);
290 totalExpectedErrors += expected.length; 282 totalExpectedErrors += expected.length;
291 await testExitCodes(marker, expected, ['--fatal-warnings']); 283 await testExitCodes(marker, expected, ['--fatal-warnings']);
292 } 284 }
293 285
294 Expect.equals(totalExpectedErrors, checkedResults); 286 Expect.equals(totalExpectedErrors, checkedResults);
295 }); 287 });
296 } 288 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698