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

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

Issue 1160513002: 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 | « tests/standalone/io/platform_executable_script.dart ('k') | 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 import "package:expect/expect.dart";
12
13 const CLIENT_SCRIPT = "platform_executable_script.dart";
14
15 void verify(String exePath, {String altPath}) {
16 var env = {};
17 if (altPath != null) {
18 env['PATH'] = altPath;
19 }
20
21 var processResult = Process.runSync(exePath, [scriptPath],
22 includeParentEnvironment: false, runInShell: true, environment: env);
23
24 var result = processResult.stdout.trim();
25 Expect.equals(Platform.executable, result);
26 }
27
28 void testDartExecShouldNotBeInCurrentDir() {
29 var type = FileSystemEntity.typeSync(platformExeName);
30 Expect.equals(FileSystemEntityType.NOT_FOUND, type);
31 }
32
33 void testShouldFailOutsidePath() {
34 Expect.throws(() => Process.runSync(platformExeName, [scriptPath],
35 includeParentEnvironment: false));
36 }
37
38 void testShouldSucceedWithSourcePlatformExecutable() {
39 print('*** Running normally');
Søren Gjesse 2015/05/26 15:29:59 Remove debug print?
40 verify(Platform.executable);
41 }
42
43 void testExeSymLinked(Directory dir) {
44 var dirUri = new Uri.directory(dir.path);
45 var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
46 link.createSync(Platform.executable);
47 print('*** Creating a sym-link to the executable');
48 verify(link.path);
49 }
50
51 void testPathToDirWithExeSymLinked(Directory dir) {
52 var dirUri = new Uri.directory(dir.path);
53 var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
54 link.createSync(Platform.executable);
55 print('*** Path to a directory that contains a sym-link to dart bin');
56 verify('dart_exe_link', altPath: dir.path);
57 }
58
59 /// Create a sym-link to the SDK directory and run 'dart' from that path
60 void testExeDirSymLinked(Directory dir) {
61 var dirUri = new Uri.directory(dir.path);
62
63 var linkDirUri = dirUri.resolve('dart_bin_dir_link');
64 var link = new Link.fromUri(linkDirUri);
65
66 var exeFile = new File(Platform.executable);
67
68 link.createSync(exeFile.parent.path);
69
70 var linkedBin =
71 new Uri.directory(linkDirUri.toFilePath()).resolve(platformExeName);
72
73 print('*** Running in a sym-linked directory');
74 verify(linkedBin.toFilePath());
75 }
76
77 void testPathPointsToSymLinkedSDKPath(Directory dir) {
78 var dirUri = new Uri.directory(dir.path);
79
80 var linkDirUri = dirUri.resolve('dart_bin_dir_link');
81 var link = new Link.fromUri(linkDirUri);
82
83 var exeFile = new File(Platform.executable);
84
85 link.createSync(exeFile.parent.path);
86
87 print('*** Path points to a sym-linked SDK dir');
88 verify(platformExeName, altPath: link.path);
89 }
90
91 void testPathToSDKDir() {
92 var exeFile = new File(Platform.executable);
93 var binDirPath = exeFile.parent.path;
94
95 print('*** Running with PATH env set to environment - fixed in 16994 - thanks! ');
96 verify(platformExeName, altPath: binDirPath);
97 }
98
99 void withTempDir(void test(Directory dir)) {
100 var tempDir = Directory.systemTemp.createTempSync('dart.sdk.test.');
101 try {
102 test(tempDir);
103 } finally {
104 tempDir.deleteSync(recursive: true);
105 }
106 }
107
108 String get platformExeName {
109 var raw = new Uri.file(Platform.executable);
110 return raw.pathSegments.last;
111 }
112
113 String get scriptPath => Platform.script.resolve(CLIENT_SCRIPT).toString();
114
115 void main() {
116 testDartExecShouldNotBeInCurrentDir();
117 testShouldFailOutsidePath();
118 testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok
119 withTempDir(testExeSymLinked); /// 01: ok
120 withTempDir(testExeDirSymLinked); /// 02: ok
121 testPathToSDKDir(); /// 03: ok
122 withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok
123 withTempDir(testPathToDirWithExeSymLinked); /// 05: ok
124 }
OLDNEW
« no previous file with comments | « tests/standalone/io/platform_executable_script.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698