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

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

Issue 2933943002: Convert more tests to the new driver (Closed)
Patch Set: Created 3 years, 6 months 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 import 'dart:async';
6
5 import 'package:analysis_server/protocol/protocol.dart'; 7 import 'package:analysis_server/protocol/protocol.dart';
6 import 'package:analysis_server/protocol/protocol_generated.dart'; 8 import 'package:analysis_server/protocol/protocol_generated.dart';
7 import 'package:analysis_server/src/constants.dart'; 9 import 'package:analysis_server/src/constants.dart';
8 import 'package:analyzer/src/generated/engine.dart';
9 import 'package:analyzer_plugin/protocol/protocol_common.dart'; 10 import 'package:analyzer_plugin/protocol/protocol_common.dart';
10 import 'package:test/test.dart'; 11 import 'package:test/test.dart';
11 import 'package:test_reflective_loader/test_reflective_loader.dart'; 12 import 'package:test_reflective_loader/test_reflective_loader.dart';
12 13
13 import '../analysis_abstract.dart'; 14 import '../analysis_abstract.dart';
14 15
15 main() { 16 main() {
16 defineReflectiveSuite(() { 17 defineReflectiveSuite(() {
17 defineReflectiveTests(ReanalyzeTest); 18 defineReflectiveTests(ReanalyzeTest);
18 }); 19 });
19 } 20 }
20 21
21 @reflectiveTest 22 @reflectiveTest
22 class ReanalyzeTest extends AbstractAnalysisTest { 23 class ReanalyzeTest extends AbstractAnalysisTest {
23 Map<String, List<AnalysisError>> filesErrors = {}; 24 Map<String, List<AnalysisError>> filesErrors = {};
24 25
25 @override 26 Completer _resultsAvailable = new Completer();
26 bool get enableNewAnalysisDriver => false;
27 27
28 @override 28 @override
29 void processNotification(Notification notification) { 29 void processNotification(Notification notification) {
30 if (notification.event == ANALYSIS_ERRORS) { 30 if (notification.event == ANALYSIS_ERRORS) {
31 var decoded = new AnalysisErrorsParams.fromNotification(notification); 31 var decoded = new AnalysisErrorsParams.fromNotification(notification);
32 filesErrors[decoded.file] = decoded.errors; 32 filesErrors[decoded.file] = decoded.errors;
33 _resultsAvailable.complete(null);
33 } 34 }
34 } 35 }
35 36
36 test_reanalyze() { 37 test_reanalyze() {
37 createProject(); 38 createProject();
38 List<AnalysisContext> contexts = server.analysisContexts.toList(); 39 Map drivers = server.driverMap;
39 expect(contexts, hasLength(1)); 40 expect(drivers, hasLength(1));
40 AnalysisContext oldContext = contexts[0];
41 // Reanalyze should cause a brand new context to be built.
42 Request request = new Request("0", ANALYSIS_REANALYZE); 41 Request request = new Request("0", ANALYSIS_REANALYZE);
43 handleSuccessfulRequest(request); 42 handleSuccessfulRequest(request);
44 contexts = server.analysisContexts.toList(); 43 drivers = server.driverMap;
45 expect(contexts, hasLength(1)); 44 expect(drivers, hasLength(1));
46 AnalysisContext newContext = contexts[0];
47 expect(newContext, isNot(same(oldContext)));
48 } 45 }
49 46
50 test_reanalyze_with_overlay() async { 47 test_reanalyze_with_overlay() async {
51 createProject(); 48 createProject();
52 resourceProvider.newFolder(testFolder); 49 resourceProvider.newFolder(testFolder);
53 resourceProvider.newFile(testFile, 'main() {}'); 50 resourceProvider.newFile(testFile, 'main() {}');
54 await waitForTasksFinished();
55 // Update the content with an overlay that contains a syntax error. 51 // Update the content with an overlay that contains a syntax error.
56 server.updateContent('1', {testFile: new AddContentOverlay('main() {')}); 52 server.updateContent('1', {testFile: new AddContentOverlay('main() {')});
57 await waitForTasksFinished(); 53 await _resultsAvailable.future;
58 // Verify that the syntax error was detected. 54 // Verify that the syntax error was detected.
59 { 55 {
60 List<AnalysisError> errors = filesErrors[testFile]; 56 List<AnalysisError> errors = filesErrors[testFile];
61 expect(errors, hasLength(1)); 57 expect(errors, hasLength(1));
62 } 58 }
63 // Remove testFile from filesErrors so that we'll notice when the file is 59 // Remove testFile from filesErrors so that we'll notice when the file is
64 // re-analyzed. 60 // re-analyzed.
65 filesErrors.remove(testFile); 61 filesErrors.remove(testFile);
66 // Reanalyze. 62 // Reanalyze.
63 _resultsAvailable = new Completer();
67 server.reanalyze(null); 64 server.reanalyze(null);
68 await waitForTasksFinished(); 65 await _resultsAvailable.future;
69 // The file should have been reanalyzed. 66 // The file should have been reanalyzed.
70 expect(filesErrors, contains(testFile)); 67 expect(filesErrors, contains(testFile));
71 // Verify that the syntax error is present (this indicates that the 68 // Verify that the syntax error is present (this indicates that the
72 // content introduced by the call to updateContent is still in effect). 69 // content introduced by the call to updateContent is still in effect).
73 { 70 {
74 List<AnalysisError> errors = filesErrors[testFile]; 71 List<AnalysisError> errors = filesErrors[testFile];
75 expect(errors, hasLength(1)); 72 expect(errors, hasLength(1));
76 } 73 }
77 } 74 }
78 75
79 test_sentToPlugins() async { 76 test_sentToPlugins() async {
80 createProject(); 77 createProject();
81 await waitForTasksFinished();
82 Request request = new Request("0", ANALYSIS_REANALYZE); 78 Request request = new Request("0", ANALYSIS_REANALYZE);
83 handleSuccessfulRequest(request); 79 handleSuccessfulRequest(request);
84 // verify 80 // verify
85 expect(pluginManager.broadcastedRequest, isNotNull); 81 expect(pluginManager.broadcastedRequest, isNotNull);
86 } 82 }
87 } 83 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698