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

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

Issue 2345083003: dart2js: run dartfmt on tests (Closed)
Patch Set: revert another multipart test 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'dart:async'; 5 import 'dart:async';
6 import 'package:async_helper/async_helper.dart'; 6 import 'package:async_helper/async_helper.dart';
7 import 'package:expect/expect.dart'; 7 import 'package:expect/expect.dart';
8 import 'package:compiler/compiler_new.dart'; 8 import 'package:compiler/compiler_new.dart';
9 import 'memory_compiler.dart'; 9 import 'memory_compiler.dart';
10 10
11 final EXCEPTION = 'Crash'; 11 final EXCEPTION = 'Crash';
12 12
13 main() { 13 main() {
14 asyncTest(() async { 14 asyncTest(() async {
15 test('Empty program', await run()); 15 test('Empty program', await run());
16 test('Crash diagnostics', 16 test('Crash diagnostics', await run(diagnostics: new CrashingDiagnostics()),
17 await run(diagnostics: new CrashingDiagnostics()), 17 expectedLines: [
18 expectedLines: [ 18 'Uncaught exception in diagnostic handler: $EXCEPTION',
19 'Uncaught exception in diagnostic handler: $EXCEPTION', 19 null /* Stack trace*/
20 null /* Stack trace*/], 20 ],
21 expectedExceptions: [EXCEPTION]); 21 expectedExceptions: [
22 test('Throw in package discovery', 22 EXCEPTION
23 await run(packagesDiscoveryProvider: (_) { throw EXCEPTION; }), 23 ]);
24 expectedLines: [ 24 test(
25 'Uncaught exception in package discovery: $EXCEPTION', 25 'Throw in package discovery',
26 null /* Stack trace*/], 26 await run(packagesDiscoveryProvider: (_) {
27 expectedExceptions: [EXCEPTION]); 27 throw EXCEPTION;
28 test('new Future.error in package discovery', 28 }),
29 await run(packagesDiscoveryProvider: 29 expectedLines: [
30 (_) => new Future.error(EXCEPTION)), 30 'Uncaught exception in package discovery: $EXCEPTION',
31 expectedExceptions: [EXCEPTION]); 31 null /* Stack trace*/
32 ],
33 expectedExceptions: [
34 EXCEPTION
35 ]);
36 test(
37 'new Future.error in package discovery',
38 await run(
39 packagesDiscoveryProvider: (_) => new Future.error(EXCEPTION)),
40 expectedExceptions: [EXCEPTION]);
32 test('Throw in input provider', 41 test('Throw in input provider',
33 await run(memorySourceFiles: new CrashingMap()), 42 await run(memorySourceFiles: new CrashingMap()),
34 expectedLines: [ 43 expectedLines: [
35 'Uncaught exception in input provider: $EXCEPTION', 44 'Uncaught exception in input provider: $EXCEPTION',
36 null, // Stack trace 45 null, // Stack trace
37 'memory:main.dart:\nError: $EXCEPTION' /* READ_SELF_ERROR */]); 46 'memory:main.dart:\nError: $EXCEPTION' /* READ_SELF_ERROR */
47 ]);
38 }); 48 });
39 } 49 }
40 50
41 void test(String title, RunResult result, 51 void test(String title, RunResult result,
42 {List expectedLines: const [], 52 {List expectedLines: const [], List expectedExceptions: const []}) {
43 List expectedExceptions: const []}) {
44 print('--------------------------------------------------------------------'); 53 print('--------------------------------------------------------------------');
45 print('Running $title'); 54 print('Running $title');
46 print('--------------------------------------------------------------------'); 55 print('--------------------------------------------------------------------');
47 print('lines:'); 56 print('lines:');
48 result.lines.forEach(print); 57 result.lines.forEach(print);
49 print('exceptions:'); 58 print('exceptions:');
50 result.exceptions.forEach(print); 59 result.exceptions.forEach(print);
51 Expect.equals(expectedLines.length, result.lines.length, 60 Expect.equals(expectedLines.length, result.lines.length,
52 "Unexpected number of calls to print."); 61 "Unexpected number of calls to print.");
53 Expect.equals(expectedExceptions.length, result.exceptions.length, 62 Expect.equals(expectedExceptions.length, result.exceptions.length,
54 "Unexpected number of exceptions."); 63 "Unexpected number of exceptions.");
55 for (int i = 0; i < expectedLines.length; i++) { 64 for (int i = 0; i < expectedLines.length; i++) {
56 if (expectedLines[i] != null) { 65 if (expectedLines[i] != null) {
57 Expect.equals(expectedLines[i], result.lines[i]); 66 Expect.equals(expectedLines[i], result.lines[i]);
58 } 67 }
59 } 68 }
60 } 69 }
61 70
62 Future<RunResult> run( 71 Future<RunResult> run(
63 {Map<String, String> memorySourceFiles: const {'main.dart': 'main() {}'}, 72 {Map<String, String> memorySourceFiles: const {'main.dart': 'main() {}'},
64 CompilerDiagnostics diagnostics, 73 CompilerDiagnostics diagnostics,
65 PackagesDiscoveryProvider packagesDiscoveryProvider}) async { 74 PackagesDiscoveryProvider packagesDiscoveryProvider}) async {
66 RunResult result = new RunResult(); 75 RunResult result = new RunResult();
67 await runZoned(() async { 76 await runZoned(() async {
68 try { 77 try {
69 await runCompiler( 78 await runCompiler(
70 entryPoint: Uri.parse('memory:main.dart'), 79 entryPoint: Uri.parse('memory:main.dart'),
71 memorySourceFiles: memorySourceFiles, 80 memorySourceFiles: memorySourceFiles,
72 diagnosticHandler: diagnostics, 81 diagnosticHandler: diagnostics,
73 packagesDiscoveryProvider: packagesDiscoveryProvider); 82 packagesDiscoveryProvider: packagesDiscoveryProvider);
74 } catch (e) { 83 } catch (e) {
75 result.exceptions.add(e); 84 result.exceptions.add(e);
76 } 85 }
77 86 }, zoneSpecification: new ZoneSpecification(
78 }, 87 print: (Zone self, ZoneDelegate parent, Zone zone, String line) {
79 zoneSpecification: new ZoneSpecification(print:
80 (Zone self, ZoneDelegate parent, Zone zone, String line) {
81 result.lines.add(line); 88 result.lines.add(line);
82 })); 89 }));
83 return result; 90 return result;
84 } 91 }
85 92
86 class RunResult { 93 class RunResult {
87 List<String> lines = <String>[]; 94 List<String> lines = <String>[];
88 List exceptions = []; 95 List exceptions = [];
89 } 96 }
90 97
91 class CrashingDiagnostics extends DiagnosticCollector { 98 class CrashingDiagnostics extends DiagnosticCollector {
92 @override 99 @override
93 void report(code, Uri uri, int begin, int end, String text, Diagnostic kind) { 100 void report(code, Uri uri, int begin, int end, String text, Diagnostic kind) {
94 throw EXCEPTION; 101 throw EXCEPTION;
95 } 102 }
96 } 103 }
97 104
98 class CrashingMap implements Map<String, String> { 105 class CrashingMap implements Map<String, String> {
99 operator [](_) => throw EXCEPTION; 106 operator [](_) => throw EXCEPTION;
100 107
101 noSuchMethod(_) => null; 108 noSuchMethod(_) => null;
102 } 109 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/use_strict_test.dart ('k') | tests/compiler/dart2js/value_range2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698