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

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

Issue 1973753004: Change dart2js.dart to use compiler_new.dart (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 4 years, 7 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 7
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:io' show Platform; 9 import 'dart:io' show Platform;
10 10
11 import 'package:async_helper/async_helper.dart'; 11 import 'package:async_helper/async_helper.dart';
12 import 'package:expect/expect.dart'; 12 import 'package:expect/expect.dart';
13 13
14 import 'package:compiler/compiler.dart' as old_api;
15 import 'package:compiler/compiler_new.dart' as api; 14 import 'package:compiler/compiler_new.dart' as api;
16 import 'package:compiler/src/common/codegen.dart'; 15 import 'package:compiler/src/common/codegen.dart';
17 import 'package:compiler/src/compile_time_constants.dart'; 16 import 'package:compiler/src/compile_time_constants.dart';
18 import 'package:compiler/src/compiler.dart'; 17 import 'package:compiler/src/compiler.dart';
19 import 'package:compiler/src/dart2js.dart' as entry; 18 import 'package:compiler/src/dart2js.dart' as entry;
20 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; 19 import 'package:compiler/src/diagnostics/diagnostic_listener.dart';
21 import 'package:compiler/src/diagnostics/invariant.dart'; 20 import 'package:compiler/src/diagnostics/invariant.dart';
22 import 'package:compiler/src/diagnostics/messages.dart'; 21 import 'package:compiler/src/diagnostics/messages.dart';
23 import 'package:compiler/src/diagnostics/spannable.dart'; 22 import 'package:compiler/src/diagnostics/spannable.dart';
24 import 'package:compiler/src/apiimpl.dart' as apiimpl; 23 import 'package:compiler/src/apiimpl.dart' as apiimpl;
25 import 'package:compiler/src/enqueue.dart'; 24 import 'package:compiler/src/enqueue.dart';
26 import 'package:compiler/src/elements/elements.dart'; 25 import 'package:compiler/src/elements/elements.dart';
27 import 'package:compiler/src/library_loader.dart'; 26 import 'package:compiler/src/library_loader.dart';
28 import 'package:compiler/src/null_compiler_output.dart'; 27 import 'package:compiler/src/null_compiler_output.dart';
29 import 'package:compiler/src/old_to_new_api.dart';
30 import 'package:compiler/src/options.dart' show CompilerOptions; 28 import 'package:compiler/src/options.dart' show CompilerOptions;
31 import 'package:compiler/src/resolution/resolution.dart'; 29 import 'package:compiler/src/resolution/resolution.dart';
32 import 'package:compiler/src/scanner/scanner_task.dart'; 30 import 'package:compiler/src/scanner/scanner_task.dart';
33 import 'package:compiler/src/universe/world_impact.dart'; 31 import 'package:compiler/src/universe/world_impact.dart';
34 import 'diagnostic_reporter_helper.dart'; 32 import 'diagnostic_reporter_helper.dart';
35 33
36 class TestCompiler extends apiimpl.CompilerImpl { 34 class TestCompiler extends apiimpl.CompilerImpl {
37 final String testMarker; 35 final String testMarker;
38 final String testType; 36 final String testType;
39 final Function onTest; 37 final Function onTest;
40 TestDiagnosticReporter reporter; 38 TestDiagnosticReporter reporter;
41 39
42 TestCompiler(api.CompilerInput inputProvider, 40 TestCompiler(api.CompilerInput inputProvider,
43 api.CompilerOutput outputProvider, 41 api.CompilerOutput outputProvider,
44 api.CompilerDiagnostics handler, 42 api.CompilerDiagnostics handler,
45 Uri libraryRoot, 43 CompilerOptions options,
46 Uri packageRoot,
47 List<String> options,
48 Map<String, dynamic> environment,
49 Uri packageConfig,
50 api.PackagesDiscoveryProvider findPackages,
51 String this.testMarker, 44 String this.testMarker,
52 String this.testType, 45 String this.testType,
53 Function this.onTest) 46 Function this.onTest)
54 : reporter = new TestDiagnosticReporter(), 47 : reporter = new TestDiagnosticReporter(),
55 super(inputProvider, outputProvider, handler, 48 super(inputProvider, outputProvider, handler, options) {
56 new CompilerOptions.parse(
57 libraryRoot: libraryRoot,
58 packageRoot: packageRoot,
59 options: options,
60 environment: environment,
61 packageConfig: packageConfig,
62 packagesDiscoveryProvider: findPackages)) {
63 reporter.compiler = this; 49 reporter.compiler = this;
64 reporter.reporter = super.reporter; 50 reporter.reporter = super.reporter;
65 test('Compiler'); 51 test('Compiler');
66 } 52 }
67 53
68 @override 54 @override
69 ScannerTask createScannerTask() => new TestScanner(this); 55 ScannerTask createScannerTask() => new TestScanner(this);
70 56
71 @override 57 @override
72 ResolverTask createResolverTask() { 58 ResolverTask createResolverTask() {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 Future testExitCode( 165 Future testExitCode(
180 String marker, String type, int expectedExitCode, List options) { 166 String marker, String type, int expectedExitCode, List options) {
181 bool testOccurred = false; 167 bool testOccurred = false;
182 168
183 void onTest(String testMarker, String testType) { 169 void onTest(String testMarker, String testType) {
184 if (testMarker == marker && testType == type) { 170 if (testMarker == marker && testType == type) {
185 testOccurred = true; 171 testOccurred = true;
186 } 172 }
187 } 173 }
188 return new Future(() { 174 return new Future(() {
189 Future<old_api.CompilationResult> compile( 175 Future<api.CompilationResult> compile(
190 Uri script, 176 CompilerOptions compilerOptions,
191 Uri libraryRoot, 177 api.CompilerInput compilerInput,
192 Uri packageRoot, 178 api.CompilerDiagnostics compilerDiagnostics,
193 old_api.CompilerInputProvider inputProvider, 179 api.CompilerOutput compilerOutput) {
194 old_api.DiagnosticHandler handler, 180 compilerOutput = const NullCompilerOutput();
195 [List<String> options = const [],
196 old_api.CompilerOutputProvider outputProvider,
197 Map<String, dynamic> environment = const {},
198 Uri packageConfig,
199 api.PackagesDiscoveryProvider findPackages]) {
200 libraryRoot = Platform.script.resolve('../../../sdk/');
201 outputProvider = NullSink.outputProvider;
202 // Use this to silence the test when debugging: 181 // Use this to silence the test when debugging:
203 // handler = (uri, begin, end, message, kind) {}; 182 // handler = (uri, begin, end, message, kind) {};
204 Compiler compiler = new TestCompiler( 183 Compiler compiler = new TestCompiler(
205 new LegacyCompilerInput(inputProvider), 184 compilerInput,
206 new LegacyCompilerOutput(outputProvider), 185 compilerOutput,
207 new LegacyCompilerDiagnostics(handler), 186 compilerDiagnostics,
208 libraryRoot, 187 compilerOptions,
209 packageRoot,
210 options,
211 environment,
212 packageConfig,
213 findPackages,
214 marker, 188 marker,
215 type, 189 type,
216 onTest); 190 onTest);
217 return compiler.run(script).then((bool success) { 191 return compiler.run(compilerOptions.entryPoint).then((bool success) {
218 return new old_api.CompilationResult(compiler, isSuccess: success); 192 return new api.CompilationResult(compiler, isSuccess: success);
219 }); 193 });
220 } 194 }
221 195
222 int foundExitCode; 196 int foundExitCode;
223 197
224 checkResult() { 198 checkResult() {
225 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur'); 199 Expect.isTrue(testOccurred, 'testExitCode($marker, $type) did not occur');
226 if (foundExitCode == null) foundExitCode = 0; 200 if (foundExitCode == null) foundExitCode = 0;
227 print('testExitCode($marker, $type) ' 201 print('testExitCode($marker, $type) '
228 'exitCode=$foundExitCode expected=$expectedExitCode'); 202 'exitCode=$foundExitCode expected=$expectedExitCode');
229 Expect.equals(expectedExitCode, foundExitCode, 203 Expect.equals(expectedExitCode, foundExitCode,
230 'testExitCode($marker, $type) ' 204 'testExitCode($marker, $type) '
231 'exitCode=$foundExitCode expected=${expectedExitCode}'); 205 'exitCode=$foundExitCode expected=${expectedExitCode}');
232 checkedResults++; 206 checkedResults++;
233 } 207 }
234 208
235 void exit(exitCode) { 209 void exit(exitCode) {
236 if (foundExitCode == null) { 210 if (foundExitCode == null) {
237 foundExitCode = exitCode; 211 foundExitCode = exitCode;
238 } 212 }
239 }; 213 };
240 214
241 entry.exitFunc = exit; 215 entry.exitFunc = exit;
242 entry.compileFunc = compile; 216 entry.compileFunc = compile;
243 217
244 List<String> args = new List<String>.from(options) 218 List<String> args = new List<String>.from(options)
219 ..add("--library-root=${Platform.script.resolve('../../../sdk/')}")
245 ..add("tests/compiler/dart2js/data/exit_code_helper.dart"); 220 ..add("tests/compiler/dart2js/data/exit_code_helper.dart");
246 Future result = entry.internalMain(args); 221 Future result = entry.internalMain(args);
247 return result.catchError((e, s) { 222 return result.catchError((e, s) {
248 // Capture crashes. 223 // Capture crashes.
249 }).whenComplete(checkResult); 224 }).whenComplete(checkResult);
250 }); 225 });
251 } 226 }
252 227
253 Future testExitCodes( 228 Future testExitCodes(
254 String marker, Map<String,int> expectedExitCodes, List<String> options) { 229 String marker, Map<String,int> expectedExitCodes, List<String> options) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 281
307 expected = _expectedExitCode( 282 expected = _expectedExitCode(
308 beforeRun: tests[marker], fatalWarnings: true); 283 beforeRun: tests[marker], fatalWarnings: true);
309 totalExpectedErrors += expected.length; 284 totalExpectedErrors += expected.length;
310 await testExitCodes(marker, expected, ['--fatal-warnings']); 285 await testExitCodes(marker, expected, ['--fatal-warnings']);
311 } 286 }
312 287
313 Expect.equals(totalExpectedErrors, checkedResults); 288 Expect.equals(totalExpectedErrors, checkedResults);
314 }); 289 });
315 } 290 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/bad_output_io_test.dart ('k') | tests/compiler/dart2js/source_map_d2js_validity_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698