| 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 library vmservice_test_helper; | 5 library vmservice_test_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io'; | 8 import 'dart:io'; |
| 9 import 'dart:json' as JSON; | 9 import 'dart:json' as JSON; |
| 10 import 'dart:utf' as UTF; | 10 import 'dart:utf' as UTF; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 var dartScript = Platform.script; | 80 var dartScript = Platform.script; |
| 81 var splitPoint = dartScript.lastIndexOf(Platform.pathSeparator); | 81 var splitPoint = dartScript.lastIndexOf(Platform.pathSeparator); |
| 82 var scriptDirectory = dartScript.substring(0, splitPoint); | 82 var scriptDirectory = dartScript.substring(0, splitPoint); |
| 83 return scriptDirectory + Platform.pathSeparator + script; | 83 return scriptDirectory + Platform.pathSeparator + script; |
| 84 } | 84 } |
| 85 | 85 |
| 86 Future<int> launch() { | 86 Future<int> launch() { |
| 87 String dartExecutable = Platform.executable; | 87 String dartExecutable = Platform.executable; |
| 88 return Process.start(dartExecutable, | 88 return Process.start(dartExecutable, |
| 89 ['--enable-vm-service:0', scriptPath]).then((p) { | 89 ['--enable-vm-service:0', scriptPath]).then((p) { |
| 90 |
| 90 Completer completer = new Completer(); | 91 Completer completer = new Completer(); |
| 91 process = p; | 92 process = p; |
| 92 var portNumber; | 93 var portNumber; |
| 93 var blank; | 94 var blank; |
| 94 var first = true; | 95 var first = true; |
| 95 process.stdout.transform(new StringDecoder()) | 96 process.stdout.transform(new StringDecoder()) |
| 96 .transform(new LineTransformer()).listen((line) { | 97 .transform(new LineTransformer()).listen((line) { |
| 97 if (line.startsWith('VmService listening on port ')) { | 98 if (line.startsWith('VmService listening on port ')) { |
| 98 RegExp portExp = new RegExp(r"\d+"); | 99 RegExp portExp = new RegExp(r"\d+"); |
| 99 var port = portExp.stringMatch(line); | 100 var port = portExp.stringMatch(line); |
| 100 portNumber = int.parse(port); | 101 portNumber = int.parse(port); |
| 101 } | 102 } |
| 102 if (line == '') { | 103 if (line == '') { |
| 103 // Received blank line. | 104 // Received blank line. |
| 104 blank = true; | 105 blank = true; |
| 105 } | 106 } |
| 106 if (portNumber != null && blank == true && first == true) { | 107 if (portNumber != null && blank == true && first == true) { |
| 107 completer.complete(portNumber); | 108 completer.complete(portNumber); |
| 108 // Stop repeat completions. | 109 // Stop repeat completions. |
| 109 first = false; | 110 first = false; |
| 110 } | 111 } |
| 112 print(line); |
| 111 }); | 113 }); |
| 112 process.stderr.transform(new StringDecoder()) | 114 process.stderr.transform(new StringDecoder()) |
| 113 .transform(new LineTransformer()).listen((line) { | 115 .transform(new LineTransformer()).listen((line) { |
| 116 print(line); |
| 114 }); | 117 }); |
| 115 process.exitCode.then((_) { }); | 118 process.exitCode.then((code) { |
| 119 Expect.equals(0, code, 'Launched dart executable exited with error.'); |
| 120 }); |
| 116 return completer.future; | 121 return completer.future; |
| 117 }); | 122 }); |
| 118 } | 123 } |
| 119 | 124 |
| 120 void requestExit() { | 125 void requestExit() { |
| 121 process.stdin.add([32]); | 126 process.stdin.add([32, 13, 10]); |
| 122 } | 127 } |
| 123 } | 128 } |
| 124 | 129 |
| 125 class IsolateListTester { | 130 class IsolateListTester { |
| 126 final Map isolateList; | 131 final Map isolateList; |
| 127 | 132 |
| 128 IsolateListTester(this.isolateList) { | 133 IsolateListTester(this.isolateList) { |
| 129 // The reply is an IsolateList. | 134 // The reply is an IsolateList. |
| 130 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.'); | 135 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.'); |
| 131 } | 136 } |
| 132 | 137 |
| 133 void checkIsolateCount(int n) { | 138 void checkIsolateCount(int n) { |
| 134 Expect.equals(n, isolateList['members'].length, 'Isolate count not $n'); | 139 Expect.equals(n, isolateList['members'].length, 'Isolate count not $n'); |
| 135 } | 140 } |
| 136 | 141 |
| 137 void checkIsolateIdExists(int id) { | 142 void checkIsolateIdExists(int id) { |
| 138 var exists = false; | 143 var exists = false; |
| 139 isolateList['members'].forEach((isolate) { | 144 isolateList['members'].forEach((isolate) { |
| 140 if (isolate['id'] == id) { | 145 if (isolate['id'] == id) { |
| 141 exists = true; | 146 exists = true; |
| 142 } | 147 } |
| 143 }); | 148 }); |
| 144 Expect.isTrue(exists, 'No isolate with id: $id'); | 149 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 145 } | 150 } |
| 146 | 151 |
| 147 void checkIsolateNameContains(String name) { | 152 int checkIsolateNameContains(String name) { |
| 148 var exists = false; | 153 var exists = false; |
| 154 int id; |
| 149 isolateList['members'].forEach((isolate) { | 155 isolateList['members'].forEach((isolate) { |
| 150 if (isolate['name'].contains(name)) { | 156 if (isolate['name'].contains(name)) { |
| 151 exists = true; | 157 exists = true; |
| 158 id = isolate['id']; |
| 152 } | 159 } |
| 153 }); | 160 }); |
| 154 Expect.isTrue(exists, 'No isolate with name: $name'); | 161 Expect.isTrue(exists, 'No isolate with name: $name'); |
| 162 return id; |
| 155 } | 163 } |
| 156 | 164 |
| 157 void checkIsolateNamePrefix(int id, String name) { | 165 void checkIsolateNamePrefix(int id, String name) { |
| 158 var exists = false; | 166 var exists = false; |
| 159 isolateList['members'].forEach((isolate) { | 167 isolateList['members'].forEach((isolate) { |
| 160 if (isolate['id'] == id) { | 168 if (isolate['id'] == id) { |
| 161 exists = true; | 169 exists = true; |
| 162 Expect.isTrue(isolate['name'].startsWith(name), | 170 Expect.isTrue(isolate['name'].startsWith(name), |
| 163 'Isolate $id does not have name prefix: $name' | 171 'Isolate $id does not have name prefix: $name' |
| 164 ' (was ${isolate['name']})'); | 172 ' (was ${isolate['name']})'); |
| 165 } | 173 } |
| 166 }); | 174 }); |
| 167 Expect.isTrue(exists, 'No isolate with id: $id'); | 175 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 168 } | 176 } |
| 169 } | 177 } |
| OLD | NEW |