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 // Process test program to test process communication. | 5 // Process test program to test process communication. |
6 | 6 |
7 library PlatformExecutableTest; | 7 library PlatformExecutableTest; |
8 | 8 |
9 import "dart:io"; | 9 import "dart:io"; |
10 | 10 |
(...skipping 26 matching lines...) Expand all Loading... |
37 var result = processResult.stdout.trim(); | 37 var result = processResult.stdout.trim(); |
38 expectEquals(Platform.executable, result); | 38 expectEquals(Platform.executable, result); |
39 } | 39 } |
40 | 40 |
41 void testDartExecShouldNotBeInCurrentDir() { | 41 void testDartExecShouldNotBeInCurrentDir() { |
42 var type = FileSystemEntity.typeSync(platformExeName); | 42 var type = FileSystemEntity.typeSync(platformExeName); |
43 expectEquals(FileSystemEntityType.NOT_FOUND, type); | 43 expectEquals(FileSystemEntityType.NOT_FOUND, type); |
44 } | 44 } |
45 | 45 |
46 void testShouldSucceedWithEmptyPathEnvironment() { | 46 void testShouldSucceedWithEmptyPathEnvironment() { |
47 var command = Platform.isWindows ? 'dir' : 'ls'; | 47 var command = Platform.isWindows ? 'cmd' : 'ls'; |
48 Process.runSync(command, [], | 48 Process.runSync(command, [], |
49 includeParentEnvironment: false, | 49 includeParentEnvironment: false, |
50 environment: {_SCRIPT_KEY: 'yes', 'PATH': ''}); | 50 environment: {_SCRIPT_KEY: 'yes', 'PATH': ''}); |
51 } | 51 } |
52 | 52 |
53 void testShouldSucceedWithSourcePlatformExecutable() { | 53 void testShouldSucceedWithSourcePlatformExecutable() { |
54 //print('*** Running normally'); | |
55 verify(Platform.executable); | 54 verify(Platform.executable); |
56 } | 55 } |
57 | 56 |
58 void testExeSymLinked(Directory dir) { | 57 void testExeSymLinked(Directory dir) { |
59 var dirUri = new Uri.directory(dir.path); | 58 var dirUri = new Uri.directory(dir.path); |
60 var link = new Link.fromUri(dirUri.resolve('dart_exe_link')); | 59 var link = new Link.fromUri(dirUri.resolve('dart_exe_link')); |
61 link.createSync(Platform.executable); | 60 link.createSync(Platform.executable); |
62 //print('*** Creating a sym-link to the executable'); | |
63 verify(link.path); | 61 verify(link.path); |
64 } | 62 } |
65 | 63 |
66 void testPathToDirWithExeSymLinked(Directory dir) { | 64 void testPathToDirWithExeSymLinked(Directory dir) { |
67 var dirUri = new Uri.directory(dir.path); | 65 var dirUri = new Uri.directory(dir.path); |
68 var link = new Link.fromUri(dirUri.resolve('dart_exe_link')); | 66 var link = new Link.fromUri(dirUri.resolve('dart_exe_link')); |
69 link.createSync(Platform.executable); | 67 link.createSync(Platform.executable); |
70 //print('*** Path to a directory that contains a sym-link to dart bin'); | |
71 verify('dart_exe_link', altPath: dir.path); | 68 verify('dart_exe_link', altPath: dir.path); |
72 } | 69 } |
73 | 70 |
74 /// Create a sym-link to the SDK directory and run 'dart' from that path | 71 /// Create a sym-link to the SDK directory and run 'dart' from that path |
75 void testExeDirSymLinked(Directory dir) { | 72 void testExeDirSymLinked(Directory dir) { |
76 var dirUri = new Uri.directory(dir.path); | 73 var dirUri = new Uri.directory(dir.path); |
77 | 74 |
78 var linkDirUri = dirUri.resolve('dart_bin_dir_link'); | 75 var linkDirUri = dirUri.resolve('dart_bin_dir_link'); |
79 var link = new Link.fromUri(linkDirUri); | 76 var link = new Link.fromUri(linkDirUri); |
80 | 77 |
81 var exeFile = new File(Platform.executable); | 78 var exeFile = new File(Platform.executable); |
82 | 79 |
83 link.createSync(exeFile.parent.path); | 80 link.createSync(exeFile.parent.path); |
84 | 81 |
85 var linkedBin = | 82 var linkedBin = |
86 new Uri.directory(linkDirUri.toFilePath()).resolve(platformExeName); | 83 new Uri.directory(linkDirUri.toFilePath()).resolve(platformExeName); |
87 | 84 |
88 //print('*** Running in a sym-linked directory'); | |
89 verify(linkedBin.toFilePath()); | 85 verify(linkedBin.toFilePath()); |
90 } | 86 } |
91 | 87 |
92 void testPathPointsToSymLinkedSDKPath(Directory dir) { | 88 void testPathPointsToSymLinkedSDKPath(Directory dir) { |
93 var dirUri = new Uri.directory(dir.path); | 89 var dirUri = new Uri.directory(dir.path); |
94 | 90 |
95 var linkDirUri = dirUri.resolve('dart_bin_dir_link'); | 91 var linkDirUri = dirUri.resolve('dart_bin_dir_link'); |
96 var link = new Link.fromUri(linkDirUri); | 92 var link = new Link.fromUri(linkDirUri); |
97 | 93 |
98 var exeFile = new File(Platform.executable); | 94 var exeFile = new File(Platform.executable); |
99 | 95 |
100 link.createSync(exeFile.parent.path); | 96 link.createSync(exeFile.parent.path); |
101 | 97 |
102 //print('*** Path points to a sym-linked SDK dir'); | |
103 verify(platformExeName, altPath: link.path); | 98 verify(platformExeName, altPath: link.path); |
104 } | 99 } |
105 | 100 |
106 void testPathToSDKDir() { | 101 void testPathToSDKDir() { |
107 var exeFile = new File(Platform.executable); | 102 var exeFile = new File(Platform.executable); |
108 var binDirPath = exeFile.parent.path; | 103 var binDirPath = exeFile.parent.path; |
109 | 104 |
110 //print('*** Running with PATH env set to environment - fixed in 16994 - thank
s!'); | |
111 verify(platformExeName, altPath: binDirPath); | 105 verify(platformExeName, altPath: binDirPath); |
112 } | 106 } |
113 | 107 |
114 void withTempDir(void test(Directory dir)) { | 108 void withTempDir(void test(Directory dir)) { |
115 var tempDir = Directory.systemTemp.createTempSync('dart.sdk.test.'); | 109 var tempDir = Directory.systemTemp.createTempSync('dart.sdk.test.'); |
116 try { | 110 try { |
117 test(tempDir); | 111 test(tempDir); |
118 } finally { | 112 } finally { |
119 tempDir.deleteSync(recursive: true); | 113 tempDir.deleteSync(recursive: true); |
120 } | 114 } |
121 } | 115 } |
122 | 116 |
123 String get platformExeName { | 117 String get platformExeName { |
124 var raw = new Uri.file(Platform.executable); | 118 var raw = new Uri.file(Platform.executable); |
125 return raw.pathSegments.last; | 119 return raw.pathSegments.last; |
126 } | 120 } |
127 | 121 |
128 String get scriptPath => Platform.script.toFilePath(); | 122 String get scriptPath => Platform.script.toFilePath(); |
129 | 123 |
130 void main() { | 124 void main() { |
131 if (Platform.environment.containsKey(_SCRIPT_KEY)) { | 125 if (Platform.environment.containsKey(_SCRIPT_KEY)) { |
132 print(Platform.executable); | 126 print(Platform.executable); |
133 return; | 127 return; |
134 } | 128 } |
135 | 129 |
136 testDartExecShouldNotBeInCurrentDir(); | 130 testDartExecShouldNotBeInCurrentDir(); |
137 testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok | 131 testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok |
138 withTempDir(testExeSymLinked); /// 01: ok | 132 // dart:io does not support linking to files in Windows. |
| 133 if (!Platform.isWindows) { |
| 134 withTempDir(testExeSymLinked); /// 01: ok |
| 135 } |
139 withTempDir(testExeDirSymLinked); /// 02: ok | 136 withTempDir(testExeDirSymLinked); /// 02: ok |
140 testPathToSDKDir(); /// 03: ok | 137 testPathToSDKDir(); /// 03: ok |
141 withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok | 138 withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok |
142 withTempDir(testPathToDirWithExeSymLinked); /// 05: ok | 139 // dart:io does not support linking to files in Windows. |
| 140 if (!Platform.isWindows) { |
| 141 withTempDir(testPathToDirWithExeSymLinked); /// 05: ok |
| 142 } |
143 testShouldSucceedWithEmptyPathEnvironment(); /// 06: ok | 143 testShouldSucceedWithEmptyPathEnvironment(); /// 06: ok |
144 } | 144 } |
OLD | NEW |