| 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"; |
| 11 | 11 |
| 12 test() { | 12 test() { |
| 13 Expect.isTrue(Platform.numberOfProcessors > 0); | 13 Expect.isTrue(Platform.numberOfProcessors > 0); |
| 14 var os = Platform.operatingSystem; | 14 var os = Platform.operatingSystem; |
| 15 Expect.isTrue(os == "android" || os == "linux" || os == "macos" || | 15 Expect.isTrue(os == "android" || os == "linux" || os == "macos" || |
| 16 os == "windows"); | 16 os == "windows"); |
| 17 Expect.equals(Platform.isLinux, Platform.operatingSystem == "linux"); | 17 Expect.equals(Platform.isLinux, Platform.operatingSystem == "linux"); |
| 18 Expect.equals(Platform.isMacOS, Platform.operatingSystem == "macos"); | 18 Expect.equals(Platform.isMacOS, Platform.operatingSystem == "macos"); |
| 19 Expect.equals(Platform.isWindows, Platform.operatingSystem == "windows"); | 19 Expect.equals(Platform.isWindows, Platform.operatingSystem == "windows"); |
| 20 Expect.equals(Platform.isAndroid, Platform.operatingSystem == "android"); | 20 Expect.equals(Platform.isAndroid, Platform.operatingSystem == "android"); |
| 21 var sep = Platform.pathSeparator; | 21 var sep = Platform.pathSeparator; |
| 22 Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\')); | 22 Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\')); |
| 23 var hostname = Platform.localHostname; | 23 var hostname = Platform.localHostname; |
| 24 Expect.isTrue(hostname is String && hostname != ""); | 24 Expect.isTrue(hostname is String && hostname != ""); |
| 25 var environment = Platform.environment; | 25 var environment = Platform.environment; |
| 26 Expect.isTrue(environment is Map<String, String>); | 26 Expect.isTrue(environment is Map<String, String>); |
| 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.path. |
| 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(reply) { | 37 void f(reply) { |
| 38 reply.send({"Platform.executable": Platform.executable, | 38 reply.send({"Platform.executable": Platform.executable, |
| 39 "Platform.script": Platform.script, | 39 "Platform.script": Platform.script, |
| 40 "Platform.packageRoot": Platform.packageRoot, | 40 "Platform.packageRoot": Platform.packageRoot, |
| 41 "Platform.executableArguments": Platform.executableArguments}); | 41 "Platform.executableArguments": Platform.executableArguments}); |
| 42 } | 42 } |
| 43 | 43 |
| 44 testIsolate() { | 44 testIsolate() { |
| 45 asyncStart(); | 45 asyncStart(); |
| 46 ReceivePort port = new ReceivePort(); | 46 ReceivePort port = new ReceivePort(); |
| 47 var remote = Isolate.spawn(f, port.sendPort); | 47 var remote = Isolate.spawn(f, port.sendPort); |
| 48 port.first.then((results) { | 48 port.first.then((results) { |
| 49 Expect.equals(Platform.executable, results["Platform.executable"]); | 49 Expect.equals(Platform.executable, results["Platform.executable"]); |
| 50 | 50 |
| 51 Uri uri = new Uri.file(results["Platform.script"]); | 51 Uri uri = results["Platform.script"]; |
| 52 // SpawnFunction retains the script url of the parent which in this | 52 // SpawnFunction retains the script url of the parent which in this |
| 53 // case was a relative path. | 53 // case was a relative path. |
| 54 Expect.equals("file", uri.scheme); | 54 Expect.equals("file", uri.scheme); |
| 55 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart')); | 55 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart')); |
| 56 Expect.equals(Platform.packageRoot, results["Platform.packageRoot"]); | 56 Expect.equals(Platform.packageRoot, results["Platform.packageRoot"]); |
| 57 Expect.listEquals(Platform.executableArguments, | 57 Expect.listEquals(Platform.executableArguments, |
| 58 results["Platform.executableArguments"]); | 58 results["Platform.executableArguments"]); |
| 59 asyncEnd(); | 59 asyncEnd(); |
| 60 }); | 60 }); |
| 61 } | 61 } |
| 62 | 62 |
| 63 main() { | 63 main() { |
| 64 test(); | 64 test(); |
| 65 testIsolate(); | 65 testIsolate(); |
| 66 } | 66 } |
| OLD | NEW |