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

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

Issue 1147413005: TEMPORARY - Validate fix for 16994 with some caveats (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4 //
5 // Process test program to test process communication.
6
7 library PlatformExecutableTest;
8
9 import "dart:io";
10
11 void expectEquals(a, b) {
12 if (a != b) {
13 throw 'Expected: $a\n'
14 ' Actual: $b';
15 }
16 }
17
18 void verify(String exePath, {String altPath}) {
19 var env = {'SCRIPT': 'yes'};
20 if (altPath != null) {
21 env['PATH'] = altPath;
22 }
23
24 var processResult = Process.runSync(exePath, [scriptPath],
25 includeParentEnvironment: false, runInShell: true, environment: env);
26
27 if (processResult.exitCode != 0) {
28 throw 'Error with process\n'
29 '$scriptPath'
30 'Exit code: ${processResult.exitCode}\n'
31 ' STDOUT: ${processResult.stdout}\n'
32 ' STDERR: ${processResult.stderr}\n';
33 }
34
35 var result = processResult.stdout.trim();
36 expectEquals(Platform.executable, result);
37 }
38
39 void testDartExecShouldNotBeInCurrentDir() {
40 var type = FileSystemEntity.typeSync(platformExeName);
41 expectEquals(FileSystemEntityType.NOT_FOUND, type);
42 }
43
44 void testShouldFailOutsidePath() {
45 var threw = false;
46 try {
47 Process.runSync(platformExeName, [scriptPath],
48 includeParentEnvironment: false, environment: {'SCRIPT': 'yes'});
49 } catch (_) {
50 threw = true;
51 }
52
53 expectEquals(true, threw);
54 }
55
56 void testShouldSucceedWithSourcePlatformExecutable() {
57 //print('*** Running normally');
58 verify(Platform.executable);
59 }
60
61 void testExeSymLinked(Directory dir) {
62 var dirUri = new Uri.directory(dir.path);
63 var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
64 link.createSync(Platform.executable);
65 //print('*** Creating a sym-link to the executable');
66 verify(link.path);
67 }
68
69 void testPathToDirWithExeSymLinked(Directory dir) {
70 var dirUri = new Uri.directory(dir.path);
71 var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
72 link.createSync(Platform.executable);
73 //print('*** Path to a directory that contains a sym-link to dart bin');
74 verify('dart_exe_link', altPath: dir.path);
75 }
76
77 /// Create a sym-link to the SDK directory and run 'dart' from that path
78 void testExeDirSymLinked(Directory dir) {
79 var dirUri = new Uri.directory(dir.path);
80
81 var linkDirUri = dirUri.resolve('dart_bin_dir_link');
82 var link = new Link.fromUri(linkDirUri);
83
84 var exeFile = new File(Platform.executable);
85
86 link.createSync(exeFile.parent.path);
87
88 var linkedBin =
89 new Uri.directory(linkDirUri.toFilePath()).resolve(platformExeName);
90
91 //print('*** Running in a sym-linked directory');
92 verify(linkedBin.toFilePath());
93 }
94
95 void testPathPointsToSymLinkedSDKPath(Directory dir) {
96 var dirUri = new Uri.directory(dir.path);
97
98 var linkDirUri = dirUri.resolve('dart_bin_dir_link');
99 var link = new Link.fromUri(linkDirUri);
100
101 var exeFile = new File(Platform.executable);
102
103 link.createSync(exeFile.parent.path);
104
105 //print('*** Path points to a sym-linked SDK dir');
106 verify(platformExeName, altPath: link.path);
107 }
108
109 void testPathToSDKDir() {
110 var exeFile = new File(Platform.executable);
111 var binDirPath = exeFile.parent.path;
112
113 //print('*** Running with PATH env set to environment - fixed in 16994 - thank s!');
114 verify(platformExeName, altPath: binDirPath);
115 }
116
117 void withTempDir(void test(Directory dir)) {
118 var tempDir = Directory.systemTemp.createTempSync('dart.sdk.test.');
119 try {
120 test(tempDir);
121 } finally {
122 tempDir.deleteSync(recursive: true);
123 }
124 }
125
126 String get platformExeName {
127 var raw = new Uri.file(Platform.executable);
128 return raw.pathSegments.last;
129 }
130
131 String get scriptPath => Platform.script.toString();
132
133 void main() {
134 if (Platform.environment.containsKey('SCRIPT')) {
135 print(Platform.executable);
136 return;
137 }
138
139 testDartExecShouldNotBeInCurrentDir();
140 testShouldFailOutsidePath();
141 testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok
142 withTempDir(testExeSymLinked); /// 01: ok
143 withTempDir(testExeDirSymLinked); /// 02: ok
144 testPathToSDKDir(); /// 03: ok
145 withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok
146 withTempDir(testPathToDirWithExeSymLinked); /// 05: ok
147 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698