Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: tests/standalone/io/platform_test.dart

Issue 1334353002: - Add getters for the current packageRoot or packageMap. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Updated documentation comment. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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() async {
13 asyncStart();
13 Expect.isTrue(Platform.numberOfProcessors > 0); 14 Expect.isTrue(Platform.numberOfProcessors > 0);
14 var os = Platform.operatingSystem; 15 var os = Platform.operatingSystem;
15 Expect.isTrue(os == "android" || os == "linux" || os == "macos" || 16 Expect.isTrue(os == "android" || os == "linux" || os == "macos" ||
16 os == "windows"); 17 os == "windows");
17 Expect.equals(Platform.isLinux, Platform.operatingSystem == "linux"); 18 Expect.equals(Platform.isLinux, Platform.operatingSystem == "linux");
18 Expect.equals(Platform.isMacOS, Platform.operatingSystem == "macos"); 19 Expect.equals(Platform.isMacOS, Platform.operatingSystem == "macos");
19 Expect.equals(Platform.isWindows, Platform.operatingSystem == "windows"); 20 Expect.equals(Platform.isWindows, Platform.operatingSystem == "windows");
20 Expect.equals(Platform.isAndroid, Platform.operatingSystem == "android"); 21 Expect.equals(Platform.isAndroid, Platform.operatingSystem == "android");
21 var sep = Platform.pathSeparator; 22 var sep = Platform.pathSeparator;
22 Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\')); 23 Expect.isTrue(sep == '/' || (os == 'windows' && sep == '\\'));
(...skipping 18 matching lines...) Expand all
41 Expect.equals(Platform.resolvedExecutable.substring(1, 3), ':\\'); 42 Expect.equals(Platform.resolvedExecutable.substring(1, 3), ':\\');
42 } 43 }
43 // Move directory to be sure script is correct. 44 // Move directory to be sure script is correct.
44 var oldDir = Directory.current; 45 var oldDir = Directory.current;
45 Directory.current = Directory.current.parent; 46 Directory.current = Directory.current.parent;
46 Expect.isTrue(Platform.script.path. 47 Expect.isTrue(Platform.script.path.
47 endsWith('tests/standalone/io/platform_test.dart')); 48 endsWith('tests/standalone/io/platform_test.dart'));
48 Expect.isTrue(Platform.script.toFilePath().startsWith(oldDir.path)); 49 Expect.isTrue(Platform.script.toFilePath().startsWith(oldDir.path));
49 // Restore dir. 50 // Restore dir.
50 Directory.current = oldDir; 51 Directory.current = oldDir;
51 Directory packageRoot = new Directory(Platform.packageRoot); 52 String platformPackageRoot = (await Platform.packageRoot).toFilePath();
Lasse Reichstein Nielsen 2015/09/22 09:48:25 . -> ?.
53 Directory packageRoot = new Directory(platformPackageRoot);
52 Expect.isTrue(packageRoot.existsSync()); 54 Expect.isTrue(packageRoot.existsSync());
53 Expect.isTrue(new Directory("${packageRoot.path}/expect").existsSync()); 55 Expect.isTrue(new Directory("${packageRoot.path}/expect").existsSync());
54 Expect.isTrue(Platform.executableArguments.any( 56 Expect.isTrue(Platform.executableArguments.any(
55 (arg) => arg.contains(Platform.packageRoot))); 57 (arg) {
58 if (!arg.startsWith("--package-root=")) {
59 return false;
60 }
61 var commandPackageRoot = arg.replaceFirst("--package-root=", "");
Lasse Reichstein Nielsen 2015/09/22 09:48:25 overkill :) var argPackageRoot = "--package-root=
62 return platformPackageRoot.endsWith(commandPackageRoot);
63 }));
64 asyncEnd();
56 } 65 }
57 66
58 void f(reply) { 67 f(reply) async {
59 reply.send({"Platform.executable": Platform.executable, 68 reply.send({"Platform.executable": Platform.executable,
60 "Platform.script": Platform.script, 69 "Platform.script": Platform.script,
61 "Platform.packageRoot": Platform.packageRoot, 70 "Platform.packageRoot": (await Platform.packageRoot).toString(),
62 "Platform.executableArguments": Platform.executableArguments}); 71 "Platform.executableArguments": Platform.executableArguments});
63 } 72 }
64 73
65 testIsolate() { 74 testIsolate() {
66 asyncStart(); 75 asyncStart();
67 ReceivePort port = new ReceivePort(); 76 ReceivePort port = new ReceivePort();
68 var remote = Isolate.spawn(f, port.sendPort); 77 var remote = Isolate.spawn(f, port.sendPort);
69 port.first.then((results) { 78 port.first.then((results) async {
70 Expect.equals(Platform.executable, results["Platform.executable"]); 79 Expect.equals(Platform.executable, results["Platform.executable"]);
71 80
72 Uri uri = results["Platform.script"]; 81 Uri uri = results["Platform.script"];
73 // SpawnFunction retains the script url of the parent which in this 82 // SpawnFunction retains the script url of the parent which in this
74 // case was a relative path. 83 // case was a relative path.
75 Expect.equals("file", uri.scheme); 84 Expect.equals("file", uri.scheme);
76 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart')); 85 Expect.isTrue(uri.path.endsWith('tests/standalone/io/platform_test.dart'));
77 Expect.equals(Platform.packageRoot, results["Platform.packageRoot"]); 86 var packageRoot = await Platform.packageRoot;
87 Expect.equals(packageRoot.toString(), results["Platform.packageRoot"]);
78 Expect.listEquals(Platform.executableArguments, 88 Expect.listEquals(Platform.executableArguments,
79 results["Platform.executableArguments"]); 89 results["Platform.executableArguments"]);
80 asyncEnd(); 90 asyncEnd();
81 }); 91 });
82 } 92 }
83 93
84 94
85 testVersion() { 95 testVersion() {
86 checkValidVersion(String version) { 96 checkValidVersion(String version) {
87 RegExp re = new RegExp(r'(\d+)\.(\d+)\.(\d+)(-dev\.([^\.]*)\.([^\.]*))?'); 97 RegExp re = new RegExp(r'(\d+)\.(\d+)\.(\d+)(-dev\.([^\.]*)\.([^\.]*))?');
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 Expect.throws(() => checkValidVersion('x.y.z')); 142 Expect.throws(() => checkValidVersion('x.y.z'));
133 } 143 }
134 144
135 main() { 145 main() {
136 // This tests assumes paths relative to dart main directory 146 // This tests assumes paths relative to dart main directory
137 Directory.current = Platform.script.resolve('../../..').toFilePath(); 147 Directory.current = Platform.script.resolve('../../..').toFilePath();
138 test(); 148 test();
139 testIsolate(); 149 testIsolate();
140 testVersion(); 150 testVersion();
141 } 151 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698