Chromium Code Reviews| OLD | NEW |
|---|---|
| 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.integration.analysis; | 5 library test.integration.analysis; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 */ | 49 */ |
| 50 bool skipShutdown = false; | 50 bool skipShutdown = false; |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Data associated with the "server.connected" notification that was received | 53 * Data associated with the "server.connected" notification that was received |
| 54 * when the server started up. | 54 * when the server started up. |
| 55 */ | 55 */ |
| 56 var serverConnectedParams; | 56 var serverConnectedParams; |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * True if we are currently subscribed to [SERVER_STATUS] updates. | |
| 60 */ | |
| 61 bool _subscribedToServerStatus = false; | |
| 62 | |
| 63 /** | |
| 59 * Write a source file with the given absolute [pathname] and [contents]. | 64 * Write a source file with the given absolute [pathname] and [contents]. |
| 60 * | 65 * |
| 61 * If the file didn't previously exist, it is created. If it did, it is | 66 * If the file didn't previously exist, it is created. If it did, it is |
| 62 * overwritten. | 67 * overwritten. |
| 63 * | 68 * |
| 64 * Parent directories are created as necessary. | 69 * Parent directories are created as necessary. |
| 65 */ | 70 */ |
| 66 void writeFile(String pathname, String contents) { | 71 void writeFile(String pathname, String contents) { |
| 67 new Directory(dirname(pathname)).createSync(recursive: true); | 72 new Directory(dirname(pathname)).createSync(recursive: true); |
| 68 new File(pathname).writeAsStringSync(contents); | 73 new File(pathname).writeAsStringSync(contents); |
| 69 } | 74 } |
| 70 | 75 |
| 71 /** | 76 /** |
| 72 * Convert the given [relativePath] to an absolute path, by interpreting it | 77 * Convert the given [relativePath] to an absolute path, by interpreting it |
| 73 * relative to [sourceDirectory]. On Windows any forward slashes in | 78 * relative to [sourceDirectory]. On Windows any forward slashes in |
| 74 * [relativePath] are converted to backslashes. | 79 * [relativePath] are converted to backslashes. |
| 75 */ | 80 */ |
| 76 String sourcePath(String relativePath) { | 81 String sourcePath(String relativePath) { |
| 77 return join(sourceDirectory.path, relativePath.replaceAll('/', separator)); | 82 return join(sourceDirectory.path, relativePath.replaceAll('/', separator)); |
| 78 } | 83 } |
| 79 | 84 |
| 80 /** | 85 /** |
| 81 * Send the server an 'analysis.setAnalysisRoots' command directing it to | 86 * Send the server an 'analysis.setAnalysisRoots' command directing it to |
| 82 * analyze [sourceDirectory]. | 87 * analyze [sourceDirectory]. If [subscribeStatus] is true (the default), |
| 88 * then also enable [SERVER_STATUS] notifications so that [analysisFinished] | |
| 89 * can be used. | |
| 83 */ | 90 */ |
| 84 Future standardAnalysisRoot() { | 91 Future standardAnalysisSetup({bool subscribeStatus: true}) { |
| 85 return sendAnalysisSetAnalysisRoots([sourceDirectory.path], []); | 92 List<Future> futures = <Future>[]; |
| 93 if (subscribeStatus) { | |
| 94 futures.add(sendServerSetSubscriptions(['STATUS'])); | |
| 95 } | |
| 96 futures.add(sendAnalysisSetAnalysisRoots([sourceDirectory.path], [])); | |
| 97 return Future.wait(futures); | |
|
Brian Wilkerson
2014/08/09 15:33:16
Out of curiosity, is there any performance penalty
Paul Berry
2014/08/09 15:42:46
Looking at the implementation in sdk/lib/async/fut
| |
| 86 } | 98 } |
| 87 | 99 |
| 88 /** | 100 /** |
| 89 * Return a future which will complete when a 'server.status' notification is | 101 * Return a future which will complete when a 'server.status' notification is |
| 90 * received from the server with 'analyzing' set to false. | 102 * received from the server with 'analyzing' set to false. |
| 91 * | 103 * |
| 92 * The future will only be completed by 'server.status' notifications that are | 104 * The future will only be completed by 'server.status' notifications that are |
| 93 * received after this function call. So it is safe to use this getter | 105 * received after this function call. So it is safe to use this getter |
| 94 * multiple times in one test; each time it is used it will wait afresh for | 106 * multiple times in one test; each time it is used it will wait afresh for |
| 95 * analysis to finish. | 107 * analysis to finish. |
| 96 */ | 108 */ |
| 97 Future get analysisFinished { | 109 Future get analysisFinished { |
| 98 Completer completer = new Completer(); | 110 Completer completer = new Completer(); |
| 99 StreamSubscription subscription; | 111 StreamSubscription subscription; |
| 112 // This will only work if the caller has already subscribed to | |
| 113 // SERVER_STATUS (e.g. using sendServerSetSubscriptions(['STATUS'])) | |
| 114 expect(_subscribedToServerStatus, isTrue); | |
| 100 subscription = server.onNotification(SERVER_STATUS).listen((params) { | 115 subscription = server.onNotification(SERVER_STATUS).listen((params) { |
| 101 bool analysisComplete = false; | 116 bool analysisComplete = false; |
| 102 try { | 117 try { |
| 103 analysisComplete = !params['analysis']['analyzing']; | 118 analysisComplete = !params['analysis']['analyzing']; |
| 104 } catch (_) { | 119 } catch (_) { |
| 105 // Status message was mal-formed or missing optional parameters. That's | 120 // Status message was mal-formed or missing optional parameters. That's |
| 106 // fine, since we'll detect a mal-formed status message below. | 121 // fine, since we'll detect a mal-formed status message below. |
| 107 } | 122 } |
| 108 if (analysisComplete) { | 123 if (analysisComplete) { |
| 109 completer.complete(params); | 124 completer.complete(params); |
| 110 subscription.cancel(); | 125 subscription.cancel(); |
| 111 } | 126 } |
| 112 expect(params, isServerStatusParams); | 127 expect(params, isServerStatusParams); |
| 113 }); | 128 }); |
| 114 return completer.future; | 129 return completer.future; |
| 115 } | 130 } |
| 116 | 131 |
| 117 /** | 132 /** |
| 118 * Print out any messages exchanged with the server. If some messages have | 133 * Print out any messages exchanged with the server. If some messages have |
| 119 * already been exchanged with the server, they are printed out immediately. | 134 * already been exchanged with the server, they are printed out immediately. |
| 120 */ | 135 */ |
| 121 void debugStdio() { | 136 void debugStdio() { |
| 122 server.debugStdio(); | 137 server.debugStdio(); |
| 123 } | 138 } |
| 124 | 139 |
| 140 @override | |
| 141 Future sendServerSetSubscriptions(List<String> subscriptions, {bool | |
| 142 checkTypes: true}) { | |
| 143 _subscribedToServerStatus = subscriptions.contains('STATUS'); | |
| 144 return super.sendServerSetSubscriptions(subscriptions, checkTypes: | |
| 145 checkTypes); | |
| 146 } | |
| 147 | |
| 125 /** | 148 /** |
| 126 * The server is automatically started before every test, and a temporary | 149 * The server is automatically started before every test, and a temporary |
| 127 * [sourceDirectory] is created. | 150 * [sourceDirectory] is created. |
| 128 */ | 151 */ |
| 129 Future setUp() { | 152 Future setUp() { |
| 130 sourceDirectory = Directory.systemTemp.createTempSync('analysisServer'); | 153 sourceDirectory = Directory.systemTemp.createTempSync('analysisServer'); |
| 131 | 154 |
| 132 server.onNotification(ANALYSIS_ERRORS).listen((params) { | 155 server.onNotification(ANALYSIS_ERRORS).listen((params) { |
| 133 expect(params, isMap); | 156 expect(params, isMap); |
| 134 expect(params['file'], isString); | 157 expect(params['file'], isString); |
| (...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 */ | 713 */ |
| 691 void _recordStdio(String line) { | 714 void _recordStdio(String line) { |
| 692 double elapsedTime = _time.elapsedTicks / _time.frequency; | 715 double elapsedTime = _time.elapsedTicks / _time.frequency; |
| 693 line = "$elapsedTime: $line"; | 716 line = "$elapsedTime: $line"; |
| 694 if (_debuggingStdio) { | 717 if (_debuggingStdio) { |
| 695 print(line); | 718 print(line); |
| 696 } | 719 } |
| 697 _recordedStdio.add(line); | 720 _recordedStdio.add(line); |
| 698 } | 721 } |
| 699 } | 722 } |
| OLD | NEW |