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

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

Issue 1478513002: Use async/await in all analysis domain tests. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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/domain_analysis.dart'; 9 import 'package:analysis_server/src/domain_analysis.dart';
10 import 'package:analyzer/src/generated/engine.dart'; 10 import 'package:analyzer/src/generated/engine.dart';
(...skipping 30 matching lines...) Expand all
41 server.handlers = [new AnalysisDomainHandler(server),]; 41 server.handlers = [new AnalysisDomainHandler(server),];
42 wasTaskModelEnabled = AnalysisEngine.instance.useTaskModel; 42 wasTaskModelEnabled = AnalysisEngine.instance.useTaskModel;
43 } 43 }
44 44
45 @override 45 @override
46 void tearDown() { 46 void tearDown() {
47 AnalysisEngine.instance.useTaskModel = wasTaskModelEnabled; 47 AnalysisEngine.instance.useTaskModel = wasTaskModelEnabled;
48 super.tearDown(); 48 super.tearDown();
49 } 49 }
50 50
51 test_importError() { 51 test_importError() async {
52 createProject(); 52 createProject();
53 53
54 addTestFile(''' 54 addTestFile('''
55 import 'does_not_exist.dart'; 55 import 'does_not_exist.dart';
56 '''); 56 ''');
57 return waitForTasksFinished().then((_) { 57 await waitForTasksFinished();
58 List<AnalysisError> errors = filesErrors[testFile]; 58 List<AnalysisError> errors = filesErrors[testFile];
59 // Verify that we are generating only 1 error for the bad URI. 59 // Verify that we are generating only 1 error for the bad URI.
60 // https://github.com/dart-lang/sdk/issues/23754 60 // https://github.com/dart-lang/sdk/issues/23754
61 expect(errors, hasLength(1)); 61 expect(errors, hasLength(1));
62 AnalysisError error = errors[0]; 62 AnalysisError error = errors[0];
63 expect(error.severity, AnalysisErrorSeverity.ERROR); 63 expect(error.severity, AnalysisErrorSeverity.ERROR);
64 expect(error.type, AnalysisErrorType.COMPILE_TIME_ERROR); 64 expect(error.type, AnalysisErrorType.COMPILE_TIME_ERROR);
65 expect(error.message, startsWith('Target of URI does not exist')); 65 expect(error.message, startsWith('Target of URI does not exist'));
66 });
67 } 66 }
68 67
69 test_lintError() { 68 test_lintError() async {
70 // Requires task model. 69 // Requires task model.
71 AnalysisEngine.instance.useTaskModel = true; 70 AnalysisEngine.instance.useTaskModel = true;
72 71
73 var camelCaseTypesLintName = 'camel_case_types'; 72 var camelCaseTypesLintName = 'camel_case_types';
74 73
75 addFile( 74 addFile(
76 '$projectPath/.analysis_options', 75 '$projectPath/.analysis_options',
77 ''' 76 '''
78 linter: 77 linter:
79 rules: 78 rules:
80 - $camelCaseTypesLintName 79 - $camelCaseTypesLintName
81 '''); 80 ''');
82 81
83 addTestFile('class a { }'); 82 addTestFile('class a { }');
84 83
85 Request request = 84 Request request =
86 new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0'); 85 new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0');
87 handleSuccessfulRequest(request); 86 handleSuccessfulRequest(request);
88 87
89 return waitForTasksFinished().then((_) { 88 await waitForTasksFinished();
90 AnalysisContext testContext = server.getContainingContext(testFile); 89 AnalysisContext testContext = server.getContainingContext(testFile);
91 List<Linter> lints = getLints(testContext); 90 List<Linter> lints = getLints(testContext);
92 // Registry should only contain single lint rule. 91 // Registry should only contain single lint rule.
93 expect(lints, hasLength(1)); 92 expect(lints, hasLength(1));
94 LintRule lint = lints.first as LintRule; 93 LintRule lint = lints.first as LintRule;
95 expect(lint.name, camelCaseTypesLintName); 94 expect(lint.name, camelCaseTypesLintName);
96 // Verify lint error result. 95 // Verify lint error result.
97 List<AnalysisError> errors = filesErrors[testFile]; 96 List<AnalysisError> errors = filesErrors[testFile];
98 expect(errors, hasLength(1)); 97 expect(errors, hasLength(1));
99 AnalysisError error = errors[0]; 98 AnalysisError error = errors[0];
100 expect(error.location.file, '/project/bin/test.dart'); 99 expect(error.location.file, '/project/bin/test.dart');
101 expect(error.severity, AnalysisErrorSeverity.INFO); 100 expect(error.severity, AnalysisErrorSeverity.INFO);
102 expect(error.type, AnalysisErrorType.LINT); 101 expect(error.type, AnalysisErrorType.LINT);
103 expect(error.message, lint.description); 102 expect(error.message, lint.description);
104 });
105 } 103 }
106 104
107 test_notInAnalysisRoot() { 105 test_notInAnalysisRoot() async {
108 createProject(); 106 createProject();
109 String otherFile = '/other.dart'; 107 String otherFile = '/other.dart';
110 addFile(otherFile, 'UnknownType V;'); 108 addFile(otherFile, 'UnknownType V;');
111 addTestFile(''' 109 addTestFile('''
112 import '/other.dart'; 110 import '/other.dart';
113
114 main() { 111 main() {
115 print(V); 112 print(V);
116 } 113 }
117 '''); 114 ''');
118 return waitForTasksFinished().then((_) { 115 await waitForTasksFinished();
119 expect(filesErrors[otherFile], isNull); 116 expect(filesErrors[otherFile], isNull);
120 });
121 } 117 }
122 118
123 test_ParserError() { 119 test_ParserError() async {
124 createProject(); 120 createProject();
125 addTestFile('library lib'); 121 addTestFile('library lib');
126 return waitForTasksFinished().then((_) { 122 await waitForTasksFinished();
127 List<AnalysisError> errors = filesErrors[testFile]; 123 List<AnalysisError> errors = filesErrors[testFile];
128 expect(errors, hasLength(1)); 124 expect(errors, hasLength(1));
129 AnalysisError error = errors[0]; 125 AnalysisError error = errors[0];
130 expect(error.location.file, '/project/bin/test.dart'); 126 expect(error.location.file, '/project/bin/test.dart');
131 expect(error.location.offset, isPositive); 127 expect(error.location.offset, isPositive);
132 expect(error.location.length, isNonNegative); 128 expect(error.location.length, isNonNegative);
133 expect(error.severity, AnalysisErrorSeverity.ERROR); 129 expect(error.severity, AnalysisErrorSeverity.ERROR);
134 expect(error.type, AnalysisErrorType.SYNTACTIC_ERROR); 130 expect(error.type, AnalysisErrorType.SYNTACTIC_ERROR);
135 expect(error.message, isNotNull); 131 expect(error.message, isNotNull);
136 });
137 } 132 }
138 133
139 test_StaticWarning() { 134 test_StaticWarning() async {
140 createProject(); 135 createProject();
141 addTestFile(''' 136 addTestFile('''
142 main() { 137 main() {
143 print(UNKNOWN); 138 print(UNKNOWN);
144 } 139 }
145 '''); 140 ''');
146 return waitForTasksFinished().then((_) { 141 await waitForTasksFinished();
147 List<AnalysisError> errors = filesErrors[testFile]; 142 List<AnalysisError> errors = filesErrors[testFile];
148 expect(errors, hasLength(1)); 143 expect(errors, hasLength(1));
149 AnalysisError error = errors[0]; 144 AnalysisError error = errors[0];
150 expect(error.severity, AnalysisErrorSeverity.WARNING); 145 expect(error.severity, AnalysisErrorSeverity.WARNING);
151 expect(error.type, AnalysisErrorType.STATIC_WARNING); 146 expect(error.type, AnalysisErrorType.STATIC_WARNING);
152 });
153 } 147 }
154 } 148 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698