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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/standalone/io/platform_executable_test.dart
diff --git a/tests/standalone/io/platform_executable_test.dart b/tests/standalone/io/platform_executable_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..c9825060c896b14c5e97c56ca012bbbb1d88a67a
--- /dev/null
+++ b/tests/standalone/io/platform_executable_test.dart
@@ -0,0 +1,147 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// Process test program to test process communication.
+
+library PlatformExecutableTest;
+
+import "dart:io";
+
+void expectEquals(a, b) {
+ if (a != b) {
+ throw 'Expected: $a\n'
+ ' Actual: $b';
+ }
+}
+
+void verify(String exePath, {String altPath}) {
+ var env = {'SCRIPT': 'yes'};
+ if (altPath != null) {
+ env['PATH'] = altPath;
+ }
+
+ var processResult = Process.runSync(exePath, [scriptPath],
+ includeParentEnvironment: false, runInShell: true, environment: env);
+
+ if (processResult.exitCode != 0) {
+ throw 'Error with process\n'
+ '$scriptPath'
+ 'Exit code: ${processResult.exitCode}\n'
+ ' STDOUT: ${processResult.stdout}\n'
+ ' STDERR: ${processResult.stderr}\n';
+ }
+
+ var result = processResult.stdout.trim();
+ expectEquals(Platform.executable, result);
+}
+
+void testDartExecShouldNotBeInCurrentDir() {
+ var type = FileSystemEntity.typeSync(platformExeName);
+ expectEquals(FileSystemEntityType.NOT_FOUND, type);
+}
+
+void testShouldFailOutsidePath() {
+ var threw = false;
+ try {
+ Process.runSync(platformExeName, [scriptPath],
+ includeParentEnvironment: false, environment: {'SCRIPT': 'yes'});
+ } catch (_) {
+ threw = true;
+ }
+
+ expectEquals(true, threw);
+}
+
+void testShouldSucceedWithSourcePlatformExecutable() {
+ //print('*** Running normally');
+ verify(Platform.executable);
+}
+
+void testExeSymLinked(Directory dir) {
+ var dirUri = new Uri.directory(dir.path);
+ var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
+ link.createSync(Platform.executable);
+ //print('*** Creating a sym-link to the executable');
+ verify(link.path);
+}
+
+void testPathToDirWithExeSymLinked(Directory dir) {
+ var dirUri = new Uri.directory(dir.path);
+ var link = new Link.fromUri(dirUri.resolve('dart_exe_link'));
+ link.createSync(Platform.executable);
+ //print('*** Path to a directory that contains a sym-link to dart bin');
+ verify('dart_exe_link', altPath: dir.path);
+}
+
+/// Create a sym-link to the SDK directory and run 'dart' from that path
+void testExeDirSymLinked(Directory dir) {
+ var dirUri = new Uri.directory(dir.path);
+
+ var linkDirUri = dirUri.resolve('dart_bin_dir_link');
+ var link = new Link.fromUri(linkDirUri);
+
+ var exeFile = new File(Platform.executable);
+
+ link.createSync(exeFile.parent.path);
+
+ var linkedBin =
+ new Uri.directory(linkDirUri.toFilePath()).resolve(platformExeName);
+
+ //print('*** Running in a sym-linked directory');
+ verify(linkedBin.toFilePath());
+}
+
+void testPathPointsToSymLinkedSDKPath(Directory dir) {
+ var dirUri = new Uri.directory(dir.path);
+
+ var linkDirUri = dirUri.resolve('dart_bin_dir_link');
+ var link = new Link.fromUri(linkDirUri);
+
+ var exeFile = new File(Platform.executable);
+
+ link.createSync(exeFile.parent.path);
+
+ //print('*** Path points to a sym-linked SDK dir');
+ verify(platformExeName, altPath: link.path);
+}
+
+void testPathToSDKDir() {
+ var exeFile = new File(Platform.executable);
+ var binDirPath = exeFile.parent.path;
+
+ //print('*** Running with PATH env set to environment - fixed in 16994 - thanks!');
+ verify(platformExeName, altPath: binDirPath);
+}
+
+void withTempDir(void test(Directory dir)) {
+ var tempDir = Directory.systemTemp.createTempSync('dart.sdk.test.');
+ try {
+ test(tempDir);
+ } finally {
+ tempDir.deleteSync(recursive: true);
+ }
+}
+
+String get platformExeName {
+ var raw = new Uri.file(Platform.executable);
+ return raw.pathSegments.last;
+}
+
+String get scriptPath => Platform.script.toString();
+
+void main() {
+ if (Platform.environment.containsKey('SCRIPT')) {
+ print(Platform.executable);
+ return;
+ }
+
+ testDartExecShouldNotBeInCurrentDir();
+ testShouldFailOutsidePath();
+ testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok
+ withTempDir(testExeSymLinked); /// 01: ok
+ withTempDir(testExeDirSymLinked); /// 02: ok
+ testPathToSDKDir(); /// 03: ok
+ withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok
+ withTempDir(testPathToDirWithExeSymLinked); /// 05: ok
+}
« 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