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 that dart2js produces the expected static type warnings for type | 5 // Test that dart2js produces the expected static type warnings to ensures that |
6 // promotion langauge tests. This ensures that the analyzer and dart2js agrees | 6 // the analyzer and dart2js agrees on the tests. |
7 // on these tests. | |
8 | 7 |
9 import 'dart:async'; | 8 import 'dart:async'; |
10 import 'dart:io'; | 9 import 'dart:io'; |
11 import 'package:expect/expect.dart'; | 10 import 'package:expect/expect.dart'; |
| 11 import 'package:async_helper/async_helper.dart'; |
12 import 'memory_compiler.dart'; | 12 import 'memory_compiler.dart'; |
13 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; | 13 import '../../../sdk/lib/_internal/compiler/implementation/filenames.dart'; |
14 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; | 14 import '../../../sdk/lib/_internal/compiler/implementation/source_file.dart'; |
15 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; | 15 import '../../../sdk/lib/_internal/compiler/implementation/source_file_provider.
dart'; |
16 import '../../../sdk/lib/_internal/compiler/implementation/util/uri_extras.dart'
; | 16 import '../../../sdk/lib/_internal/compiler/implementation/util/uri_extras.dart'
; |
17 import 'dart:convert'; | 17 import 'dart:convert'; |
18 | 18 |
19 /// Map from test files to a map of their expected status. If the status map is | 19 void checkWarnings(Map<String, dynamic> tests) { |
20 /// `null` no warnings must be missing or unexpected, otherwise the status map | |
21 /// can contain a list of line numbers for keys 'missing' and 'unexpected' for | |
22 /// the warnings of each category. | |
23 const Map<String, dynamic> TESTS = const { | |
24 'language/type_promotion_assign_test.dart': null, | |
25 'language/type_promotion_closure_test.dart': null, | |
26 'language/type_promotion_functions_test.dart': | |
27 const {'missing': const [62, 63, 64]}, // Issue 14933. | |
28 'language/type_promotion_local_test.dart': null, | |
29 'language/type_promotion_logical_and_test.dart': null, | |
30 'language/type_promotion_more_specific_test.dart': null, | |
31 'language/type_promotion_multiple_test.dart': null, | |
32 'language/type_promotion_parameter_test.dart': null, | |
33 }; | |
34 | |
35 void main() { | |
36 bool isWindows = Platform.isWindows; | 20 bool isWindows = Platform.isWindows; |
37 Uri script = currentDirectory.resolveUri(Platform.script); | 21 Uri script = currentDirectory.resolveUri(Platform.script); |
38 bool warningsMismatch = false; | 22 bool warningsMismatch = false; |
39 Future.forEach(TESTS.keys, (String test) { | 23 asyncTest(() => Future.forEach(tests.keys, (String test) { |
40 Uri uri = script.resolve('../../$test'); | 24 Uri uri = script.resolve('../../$test'); |
41 String source = UTF8.decode(readAll(uriPathToNative(uri.path))); | 25 String source = UTF8.decode(readAll(uriPathToNative(uri.path))); |
42 SourceFile file = new StringSourceFile( | 26 SourceFile file = new StringSourceFile( |
43 relativize(currentDirectory, uri, isWindows), source); | 27 relativize(currentDirectory, uri, isWindows), source); |
44 Map<int,String> expectedWarnings = {}; | 28 Map<int,String> expectedWarnings = {}; |
45 int lineNo = 0; | 29 int lineNo = 0; |
46 for (String line in source.split('\n')) { | 30 for (String line in source.split('\n')) { |
47 if (line.contains('///') && line.contains('static type warning')) { | 31 if (line.contains('///') && line.contains('static type warning')) { |
48 expectedWarnings[lineNo] = line; | 32 expectedWarnings[lineNo] = line; |
49 } | 33 } |
50 lineNo++; | 34 lineNo++; |
51 } | 35 } |
52 Set<int> unseenWarnings = new Set<int>.from(expectedWarnings.keys); | 36 Set<int> unseenWarnings = new Set<int>.from(expectedWarnings.keys); |
53 DiagnosticCollector collector = new DiagnosticCollector(); | 37 DiagnosticCollector collector = new DiagnosticCollector(); |
54 var compiler = compilerFor(const {}, | 38 var compiler = compilerFor(const {}, |
55 diagnosticHandler: collector, | 39 diagnosticHandler: collector, |
56 options: ['--analyze-only'], | 40 options: ['--analyze-only'], |
57 showDiagnostics: false); | 41 showDiagnostics: false); |
58 return compiler.run(uri).then((_) { | 42 return compiler.run(uri).then((_) { |
59 Map<String, List<int>> statusMap = TESTS[test]; | 43 Map<String, List<int>> statusMap = tests[test]; |
60 // Line numbers with known unexpected warnings. | 44 // Line numbers with known unexpected warnings. |
61 List<int> unexpectedStatus = []; | 45 List<int> unexpectedStatus = []; |
62 if (statusMap != null && statusMap.containsKey('unexpected')) { | 46 if (statusMap != null && statusMap.containsKey('unexpected')) { |
63 unexpectedStatus = statusMap['unexpected']; | 47 unexpectedStatus = statusMap['unexpected']; |
64 } | 48 } |
65 // Line numbers with known missing warnings. | 49 // Line numbers with known missing warnings. |
66 List<int> missingStatus = []; | 50 List<int> missingStatus = []; |
67 if (statusMap != null && statusMap.containsKey('missing')) { | 51 if (statusMap != null && statusMap.containsKey('missing')) { |
68 missingStatus = statusMap['missing']; | 52 missingStatus = statusMap['missing']; |
69 } | 53 } |
(...skipping 15 matching lines...) Expand all Loading... |
85 warningsMismatch = true; | 69 warningsMismatch = true; |
86 String line = expectedWarnings[lineNo]; | 70 String line = expectedWarnings[lineNo]; |
87 print('$uri [${lineNo+1}]: Missing static type warning.'); | 71 print('$uri [${lineNo+1}]: Missing static type warning.'); |
88 print(line); | 72 print(line); |
89 } | 73 } |
90 } | 74 } |
91 } | 75 } |
92 }); | 76 }); |
93 }).then((_) { | 77 }).then((_) { |
94 Expect.isFalse(warningsMismatch); | 78 Expect.isFalse(warningsMismatch); |
95 }); | 79 })); |
96 } | 80 } |
OLD | NEW |