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