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

Side by Side Diff: pkg/analysis_server/test/analysis/notification_errors_test.dart

Issue 2545553007: Add support for generating lints when using the new driver (Closed)
Patch Set: fix some tests Created 4 years 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library test.analysis.notification_errors; 5 library test.analysis.notification_errors;
6 6
7 import 'package:analysis_server/plugin/protocol/protocol.dart'; 7 import 'package:analysis_server/plugin/protocol/protocol.dart';
8 import 'package:analysis_server/src/constants.dart'; 8 import 'package:analysis_server/src/constants.dart';
9 import 'package:analysis_server/src/context_manager.dart';
9 import 'package:analysis_server/src/domain_analysis.dart'; 10 import 'package:analysis_server/src/domain_analysis.dart';
11 import 'package:analyzer/src/dart/analysis/driver.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 12 import 'package:analyzer/src/generated/engine.dart';
11 import 'package:analyzer/src/services/lint.dart'; 13 import 'package:analyzer/src/services/lint.dart';
12 import 'package:linter/src/linter.dart'; 14 import 'package:linter/src/linter.dart';
13 import 'package:test/test.dart'; 15 import 'package:test/test.dart';
14 import 'package:test_reflective_loader/test_reflective_loader.dart'; 16 import 'package:test_reflective_loader/test_reflective_loader.dart';
15 17
16 import '../analysis_abstract.dart'; 18 import '../analysis_abstract.dart';
19 import '../mocks.dart';
17 20
18 main() { 21 main() {
19 defineReflectiveSuite(() { 22 defineReflectiveSuite(() {
20 defineReflectiveTests(NotificationErrorsTest); 23 defineReflectiveTests(NotificationErrorsTest);
24 defineReflectiveTests(NotificationErrorsTest_Driver);
21 }); 25 });
22 } 26 }
23 27
24 @reflectiveTest 28 @reflectiveTest
25 class NotificationErrorsTest extends AbstractAnalysisTest { 29 class AbstractNotificationErrorsTest extends AbstractAnalysisTest {
26 Map<String, List<AnalysisError>> filesErrors = {}; 30 Map<String, List<AnalysisError>> filesErrors = {};
27 31
28 void processNotification(Notification notification) { 32 void processNotification(Notification notification) {
29 if (notification.event == ANALYSIS_ERRORS) { 33 if (notification.event == ANALYSIS_ERRORS) {
30 var decoded = new AnalysisErrorsParams.fromNotification(notification); 34 var decoded = new AnalysisErrorsParams.fromNotification(notification);
31 filesErrors[decoded.file] = decoded.errors; 35 filesErrors[decoded.file] = decoded.errors;
32 } 36 }
33 } 37 }
34 38
35 @override 39 @override
36 void setUp() { 40 void setUp() {
37 super.setUp(); 41 super.setUp();
38 server.handlers = [ 42 server.handlers = [
39 new AnalysisDomainHandler(server), 43 new AnalysisDomainHandler(server),
40 ]; 44 ];
41 } 45 }
42 46
43 test_importError() async { 47 test_importError() async {
44 createProject(); 48 createProject();
45 49
46 addTestFile(''' 50 addTestFile('''
47 import 'does_not_exist.dart'; 51 import 'does_not_exist.dart';
48 '''); 52 ''');
49 await waitForTasksFinished(); 53 await waitForTasksFinished();
54 await pumpEventQueue();
50 List<AnalysisError> errors = filesErrors[testFile]; 55 List<AnalysisError> errors = filesErrors[testFile];
51 // Verify that we are generating only 1 error for the bad URI. 56 // Verify that we are generating only 1 error for the bad URI.
52 // https://github.com/dart-lang/sdk/issues/23754 57 // https://github.com/dart-lang/sdk/issues/23754
53 expect(errors, hasLength(1)); 58 expect(errors, hasLength(1));
54 AnalysisError error = errors[0]; 59 AnalysisError error = errors[0];
55 expect(error.severity, AnalysisErrorSeverity.ERROR); 60 expect(error.severity, AnalysisErrorSeverity.ERROR);
56 expect(error.type, AnalysisErrorType.COMPILE_TIME_ERROR); 61 expect(error.type, AnalysisErrorType.COMPILE_TIME_ERROR);
57 expect(error.message, startsWith("Target of URI doesn't exist")); 62 expect(error.message, startsWith("Target of URI doesn't exist"));
58 } 63 }
59 64
60 test_lintError() async { 65 test_lintError() async {
61 var camelCaseTypesLintName = 'camel_case_types'; 66 var camelCaseTypesLintName = 'camel_case_types';
62 67
63 addFile( 68 addFile(
64 '$projectPath/.analysis_options', 69 '$projectPath/.analysis_options',
65 ''' 70 '''
66 linter: 71 linter:
67 rules: 72 rules:
68 - $camelCaseTypesLintName 73 - $camelCaseTypesLintName
69 '''); 74 ''');
70 75
71 addTestFile('class a { }'); 76 addTestFile('class a { }');
72 77
73 Request request = 78 Request request =
74 new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0'); 79 new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0');
75 handleSuccessfulRequest(request); 80 handleSuccessfulRequest(request);
76 81
77 await waitForTasksFinished(); 82 await waitForTasksFinished();
78 AnalysisContext testContext = server.getContainingContext(testFile); 83 List<Linter> lints;
79 List<Linter> lints = getLints(testContext); 84 if (enableNewAnalysisDriver) {
85 AnalysisDriver testDriver = (server.contextManager as ContextManagerImpl)
86 .getContextInfoFor(resourceProvider.getFolder(projectPath))
87 .analysisDriver;
88 lints = testDriver.analysisOptions.lintRules;
89 } else {
90 AnalysisContext testContext = server.getContainingContext(testFile);
91 lints = getLints(testContext);
92 }
80 // Registry should only contain single lint rule. 93 // Registry should only contain single lint rule.
81 expect(lints, hasLength(1)); 94 expect(lints, hasLength(1));
82 LintRule lint = lints.first as LintRule; 95 LintRule lint = lints.first as LintRule;
83 expect(lint.name, camelCaseTypesLintName); 96 expect(lint.name, camelCaseTypesLintName);
84 // Verify lint error result. 97 // Verify lint error result.
85 List<AnalysisError> errors = filesErrors[testFile]; 98 List<AnalysisError> errors = filesErrors[testFile];
86 expect(errors, hasLength(1)); 99 expect(errors, hasLength(1));
87 AnalysisError error = errors[0]; 100 AnalysisError error = errors[0];
88 expect(error.location.file, '/project/bin/test.dart'); 101 expect(error.location.file, '/project/bin/test.dart');
89 expect(error.severity, AnalysisErrorSeverity.INFO); 102 expect(error.severity, AnalysisErrorSeverity.INFO);
(...skipping 12 matching lines...) Expand all
102 } 115 }
103 '''); 116 ''');
104 await waitForTasksFinished(); 117 await waitForTasksFinished();
105 expect(filesErrors[otherFile], isNull); 118 expect(filesErrors[otherFile], isNull);
106 } 119 }
107 120
108 test_ParserError() async { 121 test_ParserError() async {
109 createProject(); 122 createProject();
110 addTestFile('library lib'); 123 addTestFile('library lib');
111 await waitForTasksFinished(); 124 await waitForTasksFinished();
125 await pumpEventQueue();
112 List<AnalysisError> errors = filesErrors[testFile]; 126 List<AnalysisError> errors = filesErrors[testFile];
113 expect(errors, hasLength(1)); 127 expect(errors, hasLength(1));
114 AnalysisError error = errors[0]; 128 AnalysisError error = errors[0];
115 expect(error.location.file, '/project/bin/test.dart'); 129 expect(error.location.file, '/project/bin/test.dart');
116 expect(error.location.offset, isPositive); 130 expect(error.location.offset, isPositive);
117 expect(error.location.length, isNonNegative); 131 expect(error.location.length, isNonNegative);
118 expect(error.severity, AnalysisErrorSeverity.ERROR); 132 expect(error.severity, AnalysisErrorSeverity.ERROR);
119 expect(error.type, AnalysisErrorType.SYNTACTIC_ERROR); 133 expect(error.type, AnalysisErrorType.SYNTACTIC_ERROR);
120 expect(error.message, isNotNull); 134 expect(error.message, isNotNull);
121 } 135 }
122 136
123 test_StaticWarning() async { 137 test_StaticWarning() async {
124 createProject(); 138 createProject();
125 addTestFile(''' 139 addTestFile('''
126 main() { 140 main() {
127 print(UNKNOWN); 141 print(UNKNOWN);
128 } 142 }
129 '''); 143 ''');
130 await waitForTasksFinished(); 144 await waitForTasksFinished();
145 await pumpEventQueue();
131 List<AnalysisError> errors = filesErrors[testFile]; 146 List<AnalysisError> errors = filesErrors[testFile];
132 expect(errors, hasLength(1)); 147 expect(errors, hasLength(1));
133 AnalysisError error = errors[0]; 148 AnalysisError error = errors[0];
134 expect(error.severity, AnalysisErrorSeverity.WARNING); 149 expect(error.severity, AnalysisErrorSeverity.WARNING);
135 expect(error.type, AnalysisErrorType.STATIC_WARNING); 150 expect(error.type, AnalysisErrorType.STATIC_WARNING);
136 } 151 }
137 } 152 }
153
154 @reflectiveTest
155 class NotificationErrorsTest extends AbstractNotificationErrorsTest {}
156
157 @reflectiveTest
158 class NotificationErrorsTest_Driver extends AbstractNotificationErrorsTest {
159 @override
160 void setUp() {
161 enableNewAnalysisDriver = true;
162 generateSummaryFiles = true;
163 super.setUp();
164 }
165
166 @failingTest
167 @override
168 test_importError() {
169 // The overridden test is failing because we're getting an 'unused import'
170 // hint rather than a URI does not exist error.
171 return super.test_importError();
172 }
173 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/context_manager.dart ('k') | pkg/analysis_server/test/analysis_abstract.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698