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 | 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; | 14 import 'package:compiler/compiler.dart' as old_api; |
15 import 'package:compiler/compiler_new.dart' as api; | 15 import 'package:compiler/compiler_new.dart' as api; |
16 import 'package:compiler/src/common/codegen.dart'; | 16 import 'package:compiler/src/common/codegen.dart'; |
17 import 'package:compiler/src/compile_time_constants.dart'; | 17 import 'package:compiler/src/compile_time_constants.dart'; |
18 import 'package:compiler/src/compiler.dart'; | 18 import 'package:compiler/src/compiler.dart'; |
19 import 'package:compiler/src/dart2js.dart' as entry; | 19 import 'package:compiler/src/dart2js.dart' as entry; |
| 20 import 'package:compiler/src/diagnostics/diagnostic_listener.dart'; |
20 import 'package:compiler/src/diagnostics/invariant.dart'; | 21 import 'package:compiler/src/diagnostics/invariant.dart'; |
21 import 'package:compiler/src/diagnostics/messages.dart'; | 22 import 'package:compiler/src/diagnostics/messages.dart'; |
22 import 'package:compiler/src/diagnostics/spannable.dart'; | 23 import 'package:compiler/src/diagnostics/spannable.dart'; |
23 import 'package:compiler/src/apiimpl.dart' as apiimpl; | 24 import 'package:compiler/src/apiimpl.dart' as apiimpl; |
24 import 'package:compiler/src/enqueue.dart'; | 25 import 'package:compiler/src/enqueue.dart'; |
25 import 'package:compiler/src/elements/elements.dart'; | 26 import 'package:compiler/src/elements/elements.dart'; |
26 import 'package:compiler/src/library_loader.dart'; | 27 import 'package:compiler/src/library_loader.dart'; |
27 import 'package:compiler/src/null_compiler_output.dart'; | 28 import 'package:compiler/src/null_compiler_output.dart'; |
28 import 'package:compiler/src/old_to_new_api.dart'; | 29 import 'package:compiler/src/old_to_new_api.dart'; |
29 import 'package:compiler/src/resolution/resolution.dart'; | 30 import 'package:compiler/src/resolution/resolution.dart'; |
30 import 'package:compiler/src/scanner/scanner_task.dart'; | 31 import 'package:compiler/src/scanner/scanner_task.dart'; |
| 32 import 'diagnostic_reporter_helper.dart'; |
31 | 33 |
32 class TestCompiler extends apiimpl.Compiler { | 34 class TestCompiler extends apiimpl.Compiler { |
33 final String testMarker; | 35 final String testMarker; |
34 final String testType; | 36 final String testType; |
35 final Function onTest; | 37 final Function onTest; |
| 38 DiagnosticReporter reporter; |
36 | 39 |
37 TestCompiler(api.CompilerInput inputProvider, | 40 TestCompiler(api.CompilerInput inputProvider, |
38 api.CompilerOutput outputProvider, | 41 api.CompilerOutput outputProvider, |
39 api.CompilerDiagnostics handler, | 42 api.CompilerDiagnostics handler, |
40 Uri libraryRoot, | 43 Uri libraryRoot, |
41 Uri packageRoot, | 44 Uri packageRoot, |
42 List<String> options, | 45 List<String> options, |
43 Map<String, dynamic> environment, | 46 Map<String, dynamic> environment, |
44 Uri packageConfig, | 47 Uri packageConfig, |
45 api.PackagesDiscoveryProvider findPackages, | 48 api.PackagesDiscoveryProvider findPackages, |
46 String this.testMarker, | 49 String this.testMarker, |
47 String this.testType, | 50 String this.testType, |
48 Function this.onTest) | 51 Function this.onTest) |
49 : super(inputProvider, outputProvider, handler, libraryRoot, | 52 : super(inputProvider, outputProvider, handler, libraryRoot, |
50 packageRoot, options, environment, packageConfig, findPackages) { | 53 packageRoot, options, environment, packageConfig, findPackages) { |
51 scanner = new TestScanner(this); | 54 scanner = new TestScanner(this); |
52 resolver = new TestResolver(this, backend.constantCompilerTask); | 55 resolver = new TestResolver(this, backend.constantCompilerTask); |
| 56 reporter = new TestDiagnosticReporter(this, super.reporter); |
53 test('Compiler'); | 57 test('Compiler'); |
54 } | 58 } |
55 | 59 |
56 Future<bool> run(Uri uri) { | 60 Future<bool> run(Uri uri) { |
57 test('Compiler.run'); | 61 test('Compiler.run'); |
58 return super.run(uri); | 62 return super.run(uri); |
59 } | 63 } |
60 | 64 |
61 Future onLibraryScanned(LibraryElement element, LibraryLoader loader) { | 65 Future onLibraryScanned(LibraryElement element, LibraryLoader loader) { |
62 test('Compiler.onLibraryScanned'); | 66 test('Compiler.onLibraryScanned'); |
63 return super.onLibraryScanned(element, loader); | 67 return super.onLibraryScanned(element, loader); |
64 } | 68 } |
65 | 69 |
66 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { | 70 Future onLibrariesLoaded(LoadedLibraries loadedLibraries) { |
67 test('Compiler.onLibrariesLoaded'); | 71 test('Compiler.onLibrariesLoaded'); |
68 return super.onLibrariesLoaded(loadedLibraries); | 72 return super.onLibrariesLoaded(loadedLibraries); |
69 } | 73 } |
70 | 74 |
71 WorldImpact analyzeElement(Element element) { | 75 WorldImpact analyzeElement(Element element) { |
72 test('Compiler.analyzeElement'); | 76 test('Compiler.analyzeElement'); |
73 return super.analyzeElement(element); | 77 return super.analyzeElement(element); |
74 } | 78 } |
75 | 79 |
76 WorldImpact codegen(CodegenWorkItem work, CodegenEnqueuer world) { | 80 WorldImpact codegen(CodegenWorkItem work, CodegenEnqueuer world) { |
77 test('Compiler.codegen'); | 81 test('Compiler.codegen'); |
78 return super.codegen(work, world); | 82 return super.codegen(work, world); |
79 } | 83 } |
80 | 84 |
81 withCurrentElement(Element element, f()) { | |
82 return super.withCurrentElement(element, () { | |
83 test('Compiler.withCurrentElement'); | |
84 return f(); | |
85 }); | |
86 } | |
87 | |
88 test(String marker) { | 85 test(String marker) { |
89 if (marker == testMarker) { | 86 if (marker == testMarker) { |
90 switch (testType) { | 87 switch (testType) { |
91 case 'assert': | 88 case 'assert': |
92 onTest(testMarker, testType); | 89 onTest(testMarker, testType); |
93 assert(false); | 90 assert(false); |
94 break; | 91 break; |
95 case 'invariant': | 92 case 'invariant': |
96 onTest(testMarker, testType); | 93 onTest(testMarker, testType); |
97 invariant(NO_LOCATION_SPANNABLE, false, message: marker); | 94 invariant(NO_LOCATION_SPANNABLE, false, message: marker); |
98 break; | 95 break; |
99 case 'warning': | 96 case 'warning': |
100 onTest(testMarker, testType); | 97 onTest(testMarker, testType); |
101 reportWarning(createMessage( | 98 reporter.reportWarningMessage( |
102 NO_LOCATION_SPANNABLE, | 99 NO_LOCATION_SPANNABLE, |
103 MessageKind.GENERIC, {'text': marker})); | 100 MessageKind.GENERIC, {'text': marker}); |
104 break; | 101 break; |
105 case 'error': | 102 case 'error': |
106 onTest(testMarker, testType); | 103 onTest(testMarker, testType); |
107 reportError(createMessage( | 104 reporter.reportErrorMessage( |
108 NO_LOCATION_SPANNABLE, | 105 NO_LOCATION_SPANNABLE, |
109 MessageKind.GENERIC, {'text': marker})); | 106 MessageKind.GENERIC, {'text': marker}); |
110 break; | 107 break; |
111 case 'internalError': | 108 case 'internalError': |
112 onTest(testMarker, testType); | 109 onTest(testMarker, testType); |
113 internalError(NO_LOCATION_SPANNABLE, marker); | 110 reporter.internalError(NO_LOCATION_SPANNABLE, marker); |
114 break; | 111 break; |
115 case 'NoSuchMethodError': | 112 case 'NoSuchMethodError': |
116 onTest(testMarker, testType); | 113 onTest(testMarker, testType); |
117 null.foo; | 114 null.foo; |
118 break; | 115 break; |
119 case '': | 116 case '': |
120 onTest(testMarker, testType); | 117 onTest(testMarker, testType); |
121 break; | 118 break; |
122 } | 119 } |
123 } | 120 } |
124 } | 121 } |
125 } | 122 } |
126 | 123 |
| 124 class TestDiagnosticReporter extends DiagnosticReporterWrapper { |
| 125 final TestCompiler compiler; |
| 126 final DiagnosticReporter reporter; |
| 127 |
| 128 TestDiagnosticReporter(this.compiler, this.reporter); |
| 129 |
| 130 @override |
| 131 withCurrentElement(Element element, f()) { |
| 132 return super.withCurrentElement(element, () { |
| 133 compiler.test('Compiler.withCurrentElement'); |
| 134 return f(); |
| 135 }); |
| 136 } |
| 137 } |
| 138 |
127 class TestScanner extends ScannerTask { | 139 class TestScanner extends ScannerTask { |
128 TestScanner(TestCompiler compiler) : super(compiler); | 140 TestScanner(TestCompiler compiler) : super(compiler); |
129 | 141 |
130 TestCompiler get compiler => super.compiler; | 142 TestCompiler get compiler => super.compiler; |
131 | 143 |
132 void scanElements(CompilationUnitElement compilationUnit) { | 144 void scanElements(CompilationUnitElement compilationUnit) { |
133 compiler.test('ScannerTask.scanElements'); | 145 compiler.test('ScannerTask.scanElements'); |
134 super.scanElements(compilationUnit); | 146 super.scanElements(compilationUnit); |
135 } | 147 } |
136 } | 148 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 | 291 |
280 expected = _expectedExitCode( | 292 expected = _expectedExitCode( |
281 beforeRun: tests[marker], fatalWarnings: true); | 293 beforeRun: tests[marker], fatalWarnings: true); |
282 totalExpectedErrors += expected.length; | 294 totalExpectedErrors += expected.length; |
283 await testExitCodes(marker, expected, ['--fatal-warnings']); | 295 await testExitCodes(marker, expected, ['--fatal-warnings']); |
284 } | 296 } |
285 | 297 |
286 Expect.equals(totalExpectedErrors, checkedResults); | 298 Expect.equals(totalExpectedErrors, checkedResults); |
287 }); | 299 }); |
288 } | 300 } |
OLD | NEW |