| 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 test_helper; | 5 library test_helper; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 first = false; | 54 first = false; |
| 55 print('** Signaled to run test queries on $portNumber'); | 55 print('** Signaled to run test queries on $portNumber'); |
| 56 } | 56 } |
| 57 print(line); | 57 print(line); |
| 58 }); | 58 }); |
| 59 process.stderr.transform(UTF8.decoder) | 59 process.stderr.transform(UTF8.decoder) |
| 60 .transform(new LineSplitter()).listen((line) { | 60 .transform(new LineSplitter()).listen((line) { |
| 61 print(line); | 61 print(line); |
| 62 }); | 62 }); |
| 63 process.exitCode.then((exitCode) { | 63 process.exitCode.then((exitCode) { |
| 64 expect(exitCode, equals(0)); | 64 print("** Process exited"); |
| 65 }); | 65 }); |
| 66 return completer.future; | 66 return completer.future; |
| 67 }); | 67 }); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void requestExit() { | 70 void requestExit() { |
| 71 print('** Requesting script to exit.'); | 71 print('** Killing script'); |
| 72 process.stdin.add([32, 13, 10]); | 72 process.kill(); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 typedef Future IsolateTest(Isolate isolate); | 76 typedef Future IsolateTest(Isolate isolate); |
| 77 typedef Future VMTest(VM vm); | 77 typedef Future VMTest(VM vm); |
| 78 | 78 |
| 79 /// Runs [tests] in sequence, each of which should take an [Isolate] and | 79 /// Runs [tests] in sequence, each of which should take an [Isolate] and |
| 80 /// return a [Future]. Code for setting up state can run before and/or | 80 /// return a [Future]. Code for setting up state can run before and/or |
| 81 /// concurrently with the tests. Uses [mainArgs] to determine whether | 81 /// concurrently with the tests. Uses [mainArgs] to determine whether |
| 82 /// to run tests or testee in this invokation of the script. | 82 /// to run tests or testee in this invokation of the script. |
| 83 void runIsolateTests(List<String> mainArgs, | 83 void runIsolateTests(List<String> mainArgs, |
| 84 List<IsolateTest> tests, | 84 List<IsolateTest> tests, |
| 85 {void testeeBefore(), | 85 {void testeeBefore(), |
| 86 void testeeConcurrent(), | 86 void testeeConcurrent(), |
| 87 bool pause_on_exit}) { | 87 bool pause_on_exit}) { |
| 88 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { | 88 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { |
| 89 if (testeeBefore != null) { | 89 if (testeeBefore != null) { |
| 90 testeeBefore(); | 90 testeeBefore(); |
| 91 } | 91 } |
| 92 print(''); // Print blank line to signal that we are ready. | 92 print(''); // Print blank line to signal that we are ready. |
| 93 if (testeeConcurrent != null) { | 93 if (testeeConcurrent != null) { |
| 94 testeeConcurrent(); | 94 testeeConcurrent(); |
| 95 } | 95 } |
| 96 // Wait until signaled from spawning test. | 96 // Wait around for the process to be killed. |
| 97 stdin.first.then((_) => exit(0)); | 97 stdin.first.then((_) => exit(0)); |
| 98 } else { | 98 } else { |
| 99 var process = new _TestLauncher(); | 99 var process = new _TestLauncher(); |
| 100 process.launch(pause_on_exit).then((port) { | 100 process.launch(pause_on_exit).then((port) { |
| 101 String addr = 'ws://localhost:$port/ws'; | 101 String addr = 'ws://localhost:$port/ws'; |
| 102 var testIndex = 0; | 102 var testIndex = 0; |
| 103 var totalTests = tests.length - 1; | 103 var totalTests = tests.length - 1; |
| 104 var name = Platform.script.pathSegments.last; | 104 var name = Platform.script.pathSegments.last; |
| 105 new WebSocketVM(new WebSocketVMTarget(addr)).load() | 105 new WebSocketVM(new WebSocketVMTarget(addr)).load() |
| 106 .then((VM vm) => vm.isolates.first.load()) | 106 .then((VM vm) => vm.isolates.first.load()) |
| 107 .then((Isolate isolate) => Future.forEach(tests, (test) { | 107 .then((Isolate isolate) => Future.forEach(tests, (test) { |
| 108 print('Running $name [$testIndex/$totalTests]'); | 108 print('Running $name [$testIndex/$totalTests]'); |
| 109 testIndex++; | 109 testIndex++; |
| 110 return test(isolate); | 110 return test(isolate); |
| 111 })).then((_) => exit(0)); | 111 })).then((_) => process.requestExit()); |
| 112 }); | 112 }); |
| 113 } | 113 } |
| 114 } | 114 } |
| 115 | 115 |
| 116 | 116 |
| 117 // Cancel the subscription and complete the completer when finished processing | 117 // Cancel the subscription and complete the completer when finished processing |
| 118 // events. | 118 // events. |
| 119 typedef void ServiceEventHandler(ServiceEvent event, | 119 typedef void ServiceEventHandler(ServiceEvent event, |
| 120 StreamSubscription subscription, | 120 StreamSubscription subscription, |
| 121 Completer completer); | 121 Completer completer); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 140 Future testeeConcurrent(), | 140 Future testeeConcurrent(), |
| 141 bool pause_on_exit}) async { | 141 bool pause_on_exit}) async { |
| 142 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { | 142 if (mainArgs.contains(_TESTEE_MODE_FLAG)) { |
| 143 if (testeeBefore != null) { | 143 if (testeeBefore != null) { |
| 144 await testeeBefore(); | 144 await testeeBefore(); |
| 145 } | 145 } |
| 146 print(''); // Print blank line to signal that we are ready. | 146 print(''); // Print blank line to signal that we are ready. |
| 147 if (testeeConcurrent != null) { | 147 if (testeeConcurrent != null) { |
| 148 await testeeConcurrent(); | 148 await testeeConcurrent(); |
| 149 } | 149 } |
| 150 // Wait until signaled from spawning test. | 150 // Wait around for the process to be killed. |
| 151 stdin.first.then((_) => exit(0)); | 151 stdin.first.then((_) => exit(0)); |
| 152 } else { | 152 } else { |
| 153 var process = new _TestLauncher(); | 153 var process = new _TestLauncher(); |
| 154 process.launch(pause_on_exit).then((port) async { | 154 process.launch(pause_on_exit).then((port) async { |
| 155 String addr = 'ws://localhost:$port/ws'; | 155 String addr = 'ws://localhost:$port/ws'; |
| 156 var testIndex = 0; | 156 var testIndex = 0; |
| 157 var totalTests = tests.length - 1; | 157 var totalTests = tests.length - 1; |
| 158 var name = Platform.script.pathSegments.last; | 158 var name = Platform.script.pathSegments.last; |
| 159 new WebSocketVM(new WebSocketVMTarget(addr)).load() | 159 new WebSocketVM(new WebSocketVMTarget(addr)).load() |
| 160 .then((VM vm) => Future.forEach(tests, (test) { | 160 .then((VM vm) => Future.forEach(tests, (test) { |
| 161 print('Running $name [$testIndex/$totalTests]'); | 161 print('Running $name [$testIndex/$totalTests]'); |
| 162 testIndex++; | 162 testIndex++; |
| 163 return test(vm); | 163 return test(vm); |
| 164 })).then((_) => exit(0)); | 164 })).then((_) => process.requestExit()); |
| 165 }); | 165 }); |
| 166 } | 166 } |
| 167 } | 167 } |
| OLD | NEW |