| 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 import "dart:io"; | 5 import "dart:io"; |
| 6 import "dart:convert"; | 6 import "dart:convert"; |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 process.stderr.drain(); | 53 process.stderr.drain(); |
| 54 | 54 |
| 55 var output = ""; | 55 var output = ""; |
| 56 process.stdout.transform(UTF8.decoder) | 56 process.stdout.transform(UTF8.decoder) |
| 57 .listen((str) { | 57 .listen((str) { |
| 58 output += str; | 58 output += str; |
| 59 if (output == 'ready\n') { | 59 if (output == 'ready\n') { |
| 60 process.kill(signal); | 60 process.kill(signal); |
| 61 } | 61 } |
| 62 }, onDone: () { | 62 }, onDone: () { |
| 63 Expect.equals('ready\ngot signal\n', output); | 63 Expect.equals('ready\n$signal\n', output); |
| 64 }); | 64 }); |
| 65 process.exitCode.then((exitCode) { | 65 process.exitCode.then((exitCode) { |
| 66 Expect.equals(0, exitCode); | 66 Expect.equals(0, exitCode); |
| 67 asyncEnd(); | 67 asyncEnd(); |
| 68 }); | 68 }); |
| 69 }); | 69 }); |
| 70 } | 70 } |
| 71 | 71 |
| 72 void testMultipleSignals(List<ProcessSignal> signals) { |
| 73 for (var signal in signals) { |
| 74 asyncStart(); |
| 75 Process.start(Platform.executable, |
| 76 [Platform.script.resolve('signal_test_script.dart').toFilePath()] |
| 77 ..addAll(signals.map((s) => s.toString()))) |
| 78 .then((process) { |
| 79 process.stdin.close(); |
| 80 process.stderr.drain(); |
| 81 |
| 82 var output = ""; |
| 83 process.stdout.transform(UTF8.decoder) |
| 84 .listen((str) { |
| 85 output += str; |
| 86 if (output == 'ready\n') { |
| 87 process.kill(signal); |
| 88 } |
| 89 }, onDone: () { |
| 90 Expect.equals('ready\n$signal\n', output); |
| 91 }); |
| 92 process.exitCode.then((exitCode) { |
| 93 Expect.equals(0, exitCode); |
| 94 asyncEnd(); |
| 95 }); |
| 96 }); |
| 97 } |
| 98 } |
| 99 |
| 72 | 100 |
| 73 void testListenCancel() { | 101 void testListenCancel() { |
| 74 for (int i = 0; i < 10; i++) { | 102 for (int i = 0; i < 10; i++) { |
| 75 ProcessSignal.SIGINT.watch().listen(null).cancel(); | 103 ProcessSignal.SIGINT.watch().listen(null).cancel(); |
| 76 } | 104 } |
| 77 } | 105 } |
| 78 | 106 |
| 79 void main() { | 107 void main() { |
| 80 testListenCancel(); | 108 testListenCancel(); |
| 81 if (Platform.isWindows) return; | 109 if (Platform.isWindows) return; |
| 82 testSignals(0, 0); | 110 testSignals(0, 0); |
| 83 testSignals(1, 0); | 111 testSignals(1, 0); |
| 84 testSignals(0, 1); | 112 testSignals(0, 1); |
| 85 testSignals(1, 1); | 113 testSignals(1, 1); |
| 86 testSignals(10, 10); | 114 testSignals(10, 10); |
| 87 testSignals(10, 1); | 115 testSignals(10, 1); |
| 88 testSignals(1, 10); | 116 testSignals(1, 10); |
| 89 testSignals(1, 0, 0, 1, true); | 117 testSignals(1, 0, 0, 1, true); |
| 90 testSignals(0, 1, 1, 0, true); | 118 testSignals(0, 1, 1, 0, true); |
| 91 | 119 |
| 92 testSignal(ProcessSignal.SIGHUP); | 120 testSignal(ProcessSignal.SIGHUP); |
| 93 testSignal(ProcessSignal.SIGINT); | 121 testSignal(ProcessSignal.SIGINT); |
| 94 testSignal(ProcessSignal.SIGTERM); | 122 testSignal(ProcessSignal.SIGTERM); |
| 95 testSignal(ProcessSignal.SIGUSR1); | 123 testSignal(ProcessSignal.SIGUSR1); |
| 96 testSignal(ProcessSignal.SIGUSR2); | 124 testSignal(ProcessSignal.SIGUSR2); |
| 97 testSignal(ProcessSignal.SIGWINCH); | 125 testSignal(ProcessSignal.SIGWINCH); |
| 126 |
| 127 testMultipleSignals([ |
| 128 ProcessSignal.SIGHUP, |
| 129 ProcessSignal.SIGINT, |
| 130 ProcessSignal.SIGTERM, |
| 131 ProcessSignal.SIGUSR1, |
| 132 ProcessSignal.SIGUSR2, |
| 133 ProcessSignal.SIGWINCH]); |
| 98 } | 134 } |
| OLD | NEW |