Chromium Code Reviews| 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 |
| 11 const _SCRIPT_KEY = '_test_script'; | |
| 12 | |
| 11 void expectEquals(a, b) { | 13 void expectEquals(a, b) { |
| 12 if (a != b) { | 14 if (a != b) { |
| 13 throw 'Expected: $a\n' | 15 throw 'Expected: $a\n' |
| 14 ' Actual: $b'; | 16 ' Actual: $b'; |
| 15 } | 17 } |
| 16 } | 18 } |
| 17 | 19 |
| 18 void verify(String exePath, {String altPath}) { | 20 void verify(String exePath, {String altPath}) { |
| 19 var env = {'SCRIPT': 'yes'}; | 21 var env = {_SCRIPT_KEY: 'yes'}; |
| 20 if (altPath != null) { | 22 if (altPath != null) { |
| 21 env['PATH'] = altPath; | 23 env['PATH'] = altPath; |
| 22 } | 24 } |
| 23 | 25 |
| 24 var processResult = Process.runSync(exePath, [scriptPath], | 26 var processResult = Process.runSync(exePath, [scriptPath], |
| 25 includeParentEnvironment: false, runInShell: true, environment: env); | 27 includeParentEnvironment: false, runInShell: true, environment: env); |
| 26 | 28 |
| 27 if (processResult.exitCode != 0) { | 29 if (processResult.exitCode != 0) { |
| 28 throw 'Error with process\n' | 30 throw 'Error with process\n' |
| 29 '$scriptPath' | 31 '$scriptPath' |
| 30 'Exit code: ${processResult.exitCode}\n' | 32 'Exit code: ${processResult.exitCode}\n' |
| 31 ' STDOUT: ${processResult.stdout}\n' | 33 ' STDOUT: ${processResult.stdout}\n' |
| 32 ' STDERR: ${processResult.stderr}\n'; | 34 ' STDERR: ${processResult.stderr}\n'; |
| 33 } | 35 } |
| 34 | 36 |
| 35 var result = processResult.stdout.trim(); | 37 var result = processResult.stdout.trim(); |
| 36 expectEquals(Platform.executable, result); | 38 expectEquals(Platform.executable, result); |
| 37 } | 39 } |
| 38 | 40 |
| 39 void testDartExecShouldNotBeInCurrentDir() { | 41 void testDartExecShouldNotBeInCurrentDir() { |
| 40 var type = FileSystemEntity.typeSync(platformExeName); | 42 var type = FileSystemEntity.typeSync(platformExeName); |
| 41 expectEquals(FileSystemEntityType.NOT_FOUND, type); | 43 expectEquals(FileSystemEntityType.NOT_FOUND, type); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void testShouldFailOutsidePath() { | 46 void testShouldFailOutsidePath() { |
| 45 var threw = false; | 47 var threw = false; |
| 46 try { | 48 try { |
| 47 Process.runSync(platformExeName, [scriptPath], | 49 Process.runSync(platformExeName, [platformExeName], |
|
Søren Gjesse
2015/05/26 07:27:54
Why are you passing [platformExeName] here?
| |
| 48 includeParentEnvironment: false, environment: {'SCRIPT': 'yes'}); | 50 includeParentEnvironment: false, environment: {_SCRIPT_KEY: 'yes'}); |
| 49 } catch (_) { | 51 } catch (_) { |
| 50 threw = true; | 52 threw = true; |
| 51 } | 53 } |
| 52 | 54 |
| 53 expectEquals(true, threw); | 55 if (!threw) { |
| 56 throw 'Expected running the dart executable – "$platformExeName" without' | |
| 57 ' the parent environment or path to fail.'; | |
| 58 } | |
| 54 } | 59 } |
| 55 | 60 |
| 56 void testShouldSucceedWithSourcePlatformExecutable() { | 61 void testShouldSucceedWithSourcePlatformExecutable() { |
| 57 //print('*** Running normally'); | 62 //print('*** Running normally'); |
| 58 verify(Platform.executable); | 63 verify(Platform.executable); |
| 59 } | 64 } |
| 60 | 65 |
| 61 void testExeSymLinked(Directory dir) { | 66 void testExeSymLinked(Directory dir) { |
| 62 var dirUri = new Uri.directory(dir.path); | 67 var dirUri = new Uri.directory(dir.path); |
| 63 var link = new Link.fromUri(dirUri.resolve('dart_exe_link')); | 68 var link = new Link.fromUri(dirUri.resolve('dart_exe_link')); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 } | 129 } |
| 125 | 130 |
| 126 String get platformExeName { | 131 String get platformExeName { |
| 127 var raw = new Uri.file(Platform.executable); | 132 var raw = new Uri.file(Platform.executable); |
| 128 return raw.pathSegments.last; | 133 return raw.pathSegments.last; |
| 129 } | 134 } |
| 130 | 135 |
| 131 String get scriptPath => Platform.script.toFilePath(); | 136 String get scriptPath => Platform.script.toFilePath(); |
| 132 | 137 |
| 133 void main() { | 138 void main() { |
| 134 if (Platform.environment.containsKey('SCRIPT')) { | 139 if (Platform.environment.containsKey(_SCRIPT_KEY)) { |
| 135 print(Platform.executable); | 140 print(Platform.executable); |
| 136 return; | 141 return; |
| 137 } | 142 } |
| 138 | 143 |
| 139 testDartExecShouldNotBeInCurrentDir(); | 144 testDartExecShouldNotBeInCurrentDir(); |
| 140 testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok | 145 testShouldSucceedWithSourcePlatformExecutable(); /// 00: ok |
| 141 withTempDir(testExeSymLinked); /// 01: ok | 146 withTempDir(testExeSymLinked); /// 01: ok |
| 142 withTempDir(testExeDirSymLinked); /// 02: ok | 147 withTempDir(testExeDirSymLinked); /// 02: ok |
| 143 testPathToSDKDir(); /// 03: ok | 148 testPathToSDKDir(); /// 03: ok |
| 144 withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok | 149 withTempDir(testPathPointsToSymLinkedSDKPath); /// 04: ok |
| 145 withTempDir(testPathToDirWithExeSymLinked); /// 05: ok | 150 withTempDir(testPathToDirWithExeSymLinked); /// 05: ok |
| 146 testShouldFailOutsidePath(); /// 06: ok | 151 testShouldFailOutsidePath(); /// 06: ok |
| 147 } | 152 } |
| OLD | NEW |