| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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:async"; | 5 import "dart:async"; |
| 6 import "dart:io"; | 6 import "dart:io"; |
| 7 import "dart:isolate"; | 7 import "dart:isolate"; |
| 8 | 8 |
| 9 import "package:async_helper/async_helper.dart"; | 9 import "package:async_helper/async_helper.dart"; |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 Expect.isTrue(Platform.executable.contains('dart')); | 27 Expect.isTrue(Platform.executable.contains('dart')); |
| 28 Expect.isTrue(Platform.script.replaceAll('\\', '/'). | 28 Expect.isTrue(Platform.script.replaceAll('\\', '/'). |
| 29 endsWith('tests/standalone/io/platform_test.dart')); | 29 endsWith('tests/standalone/io/platform_test.dart')); |
| 30 Directory packageRoot = new Directory(Platform.packageRoot); | 30 Directory packageRoot = new Directory(Platform.packageRoot); |
| 31 Expect.isTrue(packageRoot.existsSync()); | 31 Expect.isTrue(packageRoot.existsSync()); |
| 32 Expect.isTrue(new Directory("${packageRoot.path}/expect").existsSync()); | 32 Expect.isTrue(new Directory("${packageRoot.path}/expect").existsSync()); |
| 33 Expect.isTrue(Platform.executableArguments.any( | 33 Expect.isTrue(Platform.executableArguments.any( |
| 34 (arg) => arg.contains(Platform.packageRoot))); | 34 (arg) => arg.contains(Platform.packageRoot))); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void f() { | 37 void f(reply) { |
| 38 port.receive((msg, reply) { | 38 reply.send({"Platform.executable": Platform.executable, |
| 39 if (msg == "Platform.executable") { | 39 "Platform.script": Platform.script, |
| 40 reply.send(Platform.executable); | 40 "Platform.packageRoot": Platform.packageRoot, |
| 41 } | 41 "Platform.executableArguments": Platform.executableArguments}); |
| 42 if (msg == "Platform.script") { | |
| 43 reply.send(Platform.script); | |
| 44 } | |
| 45 if (msg == "Platform.packageRoot") { | |
| 46 reply.send(Platform.packageRoot); | |
| 47 } | |
| 48 if (msg == "Platform.executableArguments") { | |
| 49 reply.send(Platform.executableArguments); | |
| 50 } | |
| 51 if (msg == "close") { | |
| 52 reply.send("closed"); | |
| 53 port.close(); | |
| 54 } | |
| 55 }); | |
| 56 } | 42 } |
| 57 | 43 |
| 58 testIsolate() { | 44 testIsolate() { |
| 59 asyncStart(); | 45 asyncStart(); |
| 60 var sendPort = spawnFunction(f); | 46 ReceivePort port = new ReceivePort(); |
| 61 Future.wait([sendPort.call("Platform.executable"), | 47 var remote = Isolate.spawn(f, port.sendPort); |
| 62 sendPort.call("Platform.script"), | 48 port.first.then((results) { |
| 63 sendPort.call("Platform.packageRoot"), | 49 Expect.equals(Platform.executable, results["Platform.executable"]); |
| 64 sendPort.call("Platform.executableArguments")]) | 50 |
| 65 .then((results) { | 51 Uri uri = Uri.parse(results["Platform.script"]); |
| 66 Expect.equals(Platform.executable, results[0]); | |
| 67 Uri uri = Uri.parse(results[1]); | |
| 68 // SpawnFunction retains the script url of the parent which in this | 52 // SpawnFunction retains the script url of the parent which in this |
| 69 // case was a relative path. | 53 // case was a relative path. |
| 70 Expect.equals("", uri.scheme); | 54 Expect.equals("", uri.scheme); |
| 71 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart')); | 55 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart')); |
| 72 Expect.equals(Platform.packageRoot, results[2]); | 56 Expect.equals(Platform.packageRoot, results["Platform.packageRoot"]); |
| 73 Expect.listEquals(Platform.executableArguments, results[3]); | 57 Expect.listEquals(Platform.executableArguments, |
| 74 sendPort.call("close").then((_) => asyncEnd()); | 58 results["Platform.executableArguments"]); |
| 59 asyncEnd(); |
| 75 }); | 60 }); |
| 76 } | 61 } |
| 77 | 62 |
| 78 main() { | 63 main() { |
| 79 test(); | 64 test(); |
| 80 testIsolate(); | 65 testIsolate(); |
| 81 } | 66 } |
| OLD | NEW |