OLD | NEW |
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 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io' show Platform; | 8 import 'dart:io' show Platform; |
9 | 9 |
10 import 'package:async_helper/async_helper.dart'; | 10 import 'package:async_helper/async_helper.dart'; |
11 import 'package:expect/expect.dart'; | 11 import 'package:expect/expect.dart'; |
12 | 12 |
13 import 'package:compiler/compiler_new.dart' as api; | 13 import 'package:compiler/compiler_new.dart' as api; |
| 14 import 'package:compiler/src/common/backend_api.dart'; |
14 import 'package:compiler/src/common/codegen.dart'; | 15 import 'package:compiler/src/common/codegen.dart'; |
| 16 import 'package:compiler/src/common/resolution.dart'; |
15 import 'package:compiler/src/compile_time_constants.dart'; | 17 import 'package:compiler/src/compile_time_constants.dart'; |
16 import 'package:compiler/src/compiler.dart'; | 18 import 'package:compiler/src/compiler.dart'; |
17 import 'package:compiler/src/dart2js.dart' as entry; | 19 import 'package:compiler/src/dart2js.dart' as entry; |
18 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; | 20 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
19 import 'package:compiler/src/diagnostics/invariant.dart'; | 21 import 'package:compiler/src/diagnostics/invariant.dart'; |
20 import 'package:compiler/src/diagnostics/messages.dart'; | 22 import 'package:compiler/src/diagnostics/messages.dart'; |
21 import 'package:compiler/src/diagnostics/spannable.dart'; | 23 import 'package:compiler/src/diagnostics/spannable.dart'; |
22 import 'package:compiler/src/apiimpl.dart' as apiimpl; | 24 import 'package:compiler/src/apiimpl.dart' as apiimpl; |
23 import 'package:compiler/src/enqueue.dart'; | |
24 import 'package:compiler/src/elements/elements.dart'; | 25 import 'package:compiler/src/elements/elements.dart'; |
| 26 import 'package:compiler/src/js_backend/js_backend.dart'; |
25 import 'package:compiler/src/library_loader.dart'; | 27 import 'package:compiler/src/library_loader.dart'; |
26 import 'package:compiler/src/null_compiler_output.dart'; | 28 import 'package:compiler/src/null_compiler_output.dart'; |
27 import 'package:compiler/src/options.dart' show CompilerOptions; | 29 import 'package:compiler/src/options.dart' show CompilerOptions; |
28 import 'package:compiler/src/resolution/resolution.dart'; | 30 import 'package:compiler/src/resolution/resolution.dart'; |
29 import 'package:compiler/src/scanner/scanner_task.dart'; | 31 import 'package:compiler/src/scanner/scanner_task.dart'; |
30 import 'package:compiler/src/universe/world_impact.dart'; | 32 import 'package:compiler/src/universe/world_impact.dart'; |
31 import 'diagnostic_reporter_helper.dart'; | 33 import 'diagnostic_reporter_helper.dart'; |
32 | 34 |
33 class TestCompiler extends apiimpl.CompilerImpl { | 35 class TestCompiler extends apiimpl.CompilerImpl { |
34 final String testMarker; | 36 final String testMarker; |
(...skipping 10 matching lines...) Expand all Loading... |
45 String this.testType, | 47 String this.testType, |
46 Function this.onTest) | 48 Function this.onTest) |
47 : reporter = new TestDiagnosticReporter(), | 49 : reporter = new TestDiagnosticReporter(), |
48 super(inputProvider, outputProvider, handler, options) { | 50 super(inputProvider, outputProvider, handler, options) { |
49 reporter.compiler = this; | 51 reporter.compiler = this; |
50 reporter.reporter = super.reporter; | 52 reporter.reporter = super.reporter; |
51 test('Compiler'); | 53 test('Compiler'); |
52 } | 54 } |
53 | 55 |
54 @override | 56 @override |
| 57 Backend createBackend() { |
| 58 return new TestBackend(this); |
| 59 } |
| 60 |
| 61 @override |
55 ScannerTask createScannerTask() => new TestScanner(this); | 62 ScannerTask createScannerTask() => new TestScanner(this); |
56 | 63 |
57 @override | 64 @override |
| 65 Resolution createResolution() => new TestResolution(this); |
| 66 |
| 67 @override |
58 ResolverTask createResolverTask() { | 68 ResolverTask createResolverTask() { |
59 return new TestResolver(this, backend.constantCompilerTask); | 69 return new TestResolver(this, backend.constantCompilerTask); |
60 } | 70 } |
61 | 71 |
62 Future<bool> run(Uri uri) { | 72 Future<bool> run(Uri uri) { |
63 test('Compiler.run'); | 73 test('Compiler.run'); |
64 return super.run(uri); | 74 return super.run(uri); |
65 } | 75 } |
66 | 76 |
67 Future onLibraryScanned(LibraryElement element, LibraryLoader loader) { | 77 Future onLibraryScanned(LibraryElement element, LibraryLoader loader) { |
68 test('Compiler.onLibraryScanned'); | 78 test('Compiler.onLibraryScanned'); |
69 return super.onLibraryScanned(element, loader); | 79 return super.onLibraryScanned(element, loader); |
70 } | 80 } |
71 | 81 |
72 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 82 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
73 test('Compiler.onLibrariesLoaded'); | 83 test('Compiler.onLibrariesLoaded'); |
74 return super.onLibrariesLoaded(loadedLibraries); | 84 return super.onLibrariesLoaded(loadedLibraries); |
75 } | 85 } |
76 | 86 |
77 WorldImpact analyzeElement(Element element) { | |
78 test('Compiler.analyzeElement'); | |
79 return super.analyzeElement(element); | |
80 } | |
81 | |
82 WorldImpact codegen(CodegenWorkItem work, Enqueuer world) { | |
83 test('Compiler.codegen'); | |
84 return super.codegen(work, world); | |
85 } | |
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); |
(...skipping 17 matching lines...) Expand all Loading... |
114 null.foo; | 114 null.foo; |
115 break; | 115 break; |
116 case '': | 116 case '': |
117 onTest(testMarker, testType); | 117 onTest(testMarker, testType); |
118 break; | 118 break; |
119 } | 119 } |
120 } | 120 } |
121 } | 121 } |
122 } | 122 } |
123 | 123 |
| 124 class TestBackend extends JavaScriptBackend { |
| 125 final TestCompiler compiler; |
| 126 TestBackend(TestCompiler compiler) |
| 127 : this.compiler = compiler, |
| 128 super(compiler, |
| 129 generateSourceMap: compiler.options.generateSourceMap, |
| 130 useStartupEmitter: compiler.options.useStartupEmitter, |
| 131 useNewSourceInfo: compiler.options.useNewSourceInfo, |
| 132 useKernel: compiler.options.useKernel); |
| 133 |
| 134 @override |
| 135 WorldImpact codegen(CodegenWorkItem work) { |
| 136 compiler.test('Compiler.codegen'); |
| 137 return super.codegen(work); |
| 138 } |
| 139 } |
| 140 |
124 class TestDiagnosticReporter extends DiagnosticReporterWrapper { | 141 class TestDiagnosticReporter extends DiagnosticReporterWrapper { |
125 TestCompiler compiler; | 142 TestCompiler compiler; |
126 DiagnosticReporter reporter; | 143 DiagnosticReporter reporter; |
127 | 144 |
128 @override | 145 @override |
129 withCurrentElement(Element element, f()) { | 146 withCurrentElement(Element element, f()) { |
130 return super.withCurrentElement(element, () { | 147 return super.withCurrentElement(element, () { |
131 compiler.test('Compiler.withCurrentElement'); | 148 compiler.test('Compiler.withCurrentElement'); |
132 return f(); | 149 return f(); |
133 }); | 150 }); |
(...skipping 20 matching lines...) Expand all Loading... |
154 : this.compiler = compiler, | 171 : this.compiler = compiler, |
155 super(compiler.resolution, constantCompiler, compiler.openWorld, | 172 super(compiler.resolution, constantCompiler, compiler.openWorld, |
156 compiler.measurer); | 173 compiler.measurer); |
157 | 174 |
158 void computeClassMembers(ClassElement element) { | 175 void computeClassMembers(ClassElement element) { |
159 compiler.test('ResolverTask.computeClassMembers'); | 176 compiler.test('ResolverTask.computeClassMembers'); |
160 super.computeClassMembers(element); | 177 super.computeClassMembers(element); |
161 } | 178 } |
162 } | 179 } |
163 | 180 |
| 181 class TestResolution extends CompilerResolution { |
| 182 TestCompiler compiler; |
| 183 |
| 184 TestResolution(TestCompiler compiler) |
| 185 : this.compiler = compiler, |
| 186 super(compiler); |
| 187 |
| 188 @override |
| 189 WorldImpact computeWorldImpact(Element element) { |
| 190 compiler.test('Compiler.analyzeElement'); |
| 191 return super.computeWorldImpact(element); |
| 192 } |
| 193 } |
| 194 |
164 int checkedResults = 0; | 195 int checkedResults = 0; |
165 | 196 |
166 Future testExitCode( | 197 Future testExitCode( |
167 String marker, String type, int expectedExitCode, List options) { | 198 String marker, String type, int expectedExitCode, List options) { |
168 bool testOccurred = false; | 199 bool testOccurred = false; |
169 | 200 |
170 void onTest(String testMarker, String testType) { | 201 void onTest(String testMarker, String testType) { |
171 if (testMarker == marker && testType == type) { | 202 if (testMarker == marker && testType == type) { |
172 testOccurred = true; | 203 testOccurred = true; |
173 } | 204 } |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 312 |
282 expected = | 313 expected = |
283 _expectedExitCode(beforeRun: tests[marker], fatalWarnings: true); | 314 _expectedExitCode(beforeRun: tests[marker], fatalWarnings: true); |
284 totalExpectedErrors += expected.length; | 315 totalExpectedErrors += expected.length; |
285 await testExitCodes(marker, expected, ['--fatal-warnings']); | 316 await testExitCodes(marker, expected, ['--fatal-warnings']); |
286 } | 317 } |
287 | 318 |
288 Expect.equals(totalExpectedErrors, checkedResults); | 319 Expect.equals(totalExpectedErrors, checkedResults); |
289 }); | 320 }); |
290 } | 321 } |
OLD | NEW |