| 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 } |
| 111 }); | 112 }); |
| 112 process.stderr.transform(new StringDecoder()) | 113 process.stderr.transform(new StringDecoder()) |
| 113 .transform(new LineTransformer()).listen((line) { | 114 .transform(new LineTransformer()).listen((line) { |
| 114 }); | 115 }); |
| 115 process.exitCode.then((_) { }); | 116 process.exitCode.then((code) { |
| 117 Expect.equals(0, code, 'Launched dart executable exited with error.'); |
| 118 }); |
| 116 return completer.future; | 119 return completer.future; |
| 117 }); | 120 }); |
| 118 } | 121 } |
| 119 | 122 |
| 120 void requestExit() { | 123 void requestExit() { |
| 121 process.stdin.add([32]); | 124 process.stdin.add([32, 13, 10]); |
| 122 } | 125 } |
| 123 } | 126 } |
| 124 | 127 |
| 125 class IsolateListTester { | 128 class IsolateListTester { |
| 126 final Map isolateList; | 129 final Map isolateList; |
| 127 | 130 |
| 128 IsolateListTester(this.isolateList) { | 131 IsolateListTester(this.isolateList) { |
| 129 // The reply is an IsolateList. | 132 // The reply is an IsolateList. |
| 130 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.'); | 133 Expect.equals('IsolateList', isolateList['type'], 'Not an IsolateList.'); |
| 131 } | 134 } |
| 132 | 135 |
| 133 void checkIsolateCount(int n) { | 136 void checkIsolateCount(int n) { |
| 134 Expect.equals(n, isolateList['members'].length, 'Isolate count not $n'); | 137 Expect.equals(n, isolateList['members'].length, 'Isolate count not $n'); |
| 135 } | 138 } |
| 136 | 139 |
| 137 void checkIsolateIdExists(int id) { | 140 void checkIsolateIdExists(int id) { |
| 138 var exists = false; | 141 var exists = false; |
| 139 isolateList['members'].forEach((isolate) { | 142 isolateList['members'].forEach((isolate) { |
| 140 if (isolate['id'] == id) { | 143 if (isolate['id'] == id) { |
| 141 exists = true; | 144 exists = true; |
| 142 } | 145 } |
| 143 }); | 146 }); |
| 144 Expect.isTrue(exists, 'No isolate with id: $id'); | 147 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 145 } | 148 } |
| 146 | 149 |
| 147 void checkIsolateNameContains(String name) { | 150 int checkIsolateNameContains(String name) { |
| 148 var exists = false; | 151 var exists = false; |
| 152 int id; |
| 149 isolateList['members'].forEach((isolate) { | 153 isolateList['members'].forEach((isolate) { |
| 150 if (isolate['name'].contains(name)) { | 154 if (isolate['name'].contains(name)) { |
| 151 exists = true; | 155 exists = true; |
| 156 id = isolate['id']; |
| 152 } | 157 } |
| 153 }); | 158 }); |
| 154 Expect.isTrue(exists, 'No isolate with name: $name'); | 159 Expect.isTrue(exists, 'No isolate with name: $name'); |
| 160 return id; |
| 155 } | 161 } |
| 156 | 162 |
| 157 void checkIsolateNamePrefix(int id, String name) { | 163 void checkIsolateNamePrefix(int id, String name) { |
| 158 var exists = false; | 164 var exists = false; |
| 159 isolateList['members'].forEach((isolate) { | 165 isolateList['members'].forEach((isolate) { |
| 160 if (isolate['id'] == id) { | 166 if (isolate['id'] == id) { |
| 161 exists = true; | 167 exists = true; |
| 162 Expect.isTrue(isolate['name'].startsWith(name), | 168 Expect.isTrue(isolate['name'].startsWith(name), |
| 163 'Isolate $id does not have name prefix: $name' | 169 'Isolate $id does not have name prefix: $name' |
| 164 ' (was ${isolate['name']})'); | 170 ' (was ${isolate['name']})'); |
| 165 } | 171 } |
| 166 }); | 172 }); |
| 167 Expect.isTrue(exists, 'No isolate with id: $id'); | 173 Expect.isTrue(exists, 'No isolate with id: $id'); |
| 168 } | 174 } |
| 169 } | 175 } |
| OLD | NEW |