From df9e43f7604d0abedbbcf8bbcca86e5986f56398 Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sat, 23 Mar 2024 16:40:00 +0100 Subject: [PATCH] Move tests from ProcessResolveTest --- .../lang/unittest/CommandLineTest.class.php | 53 +++++++- .../unittest/ProcessResolveTest.class.php | 127 ------------------ 2 files changed, 52 insertions(+), 128 deletions(-) delete mode 100755 src/test/php/lang/unittest/ProcessResolveTest.class.php diff --git a/src/test/php/lang/unittest/CommandLineTest.class.php b/src/test/php/lang/unittest/CommandLineTest.class.php index b142e28b7..b7679209e 100755 --- a/src/test/php/lang/unittest/CommandLineTest.class.php +++ b/src/test/php/lang/unittest/CommandLineTest.class.php @@ -1,7 +1,8 @@ parse($cmd) ); } + + #[Test, Values(eval: 'CommandLine::values()')] + public function resolve_non_existant($impl) { + Assert::false($impl->resolve('@non-existant@')->valid()); + } + + #[Test, Values(eval: 'CommandLine::values()')] + public function resolve_empty($impl) { + Assert::false($impl->resolve('')->valid()); + } + + #[Test] + public function resolve_path_on_unix() { + Assert::false(CommandLine::$UNIX->resolve('/')->valid()); + } + + #[Test, Runtime(os: 'Linux|Darwin')] + public function resolve_ls_on_unix() { + Assert::true(is_executable(CommandLine::$UNIX->resolve('ls')->current())); + } + + #[Test, Runtime(os: 'Linux|Darwin')] + public function resolve_absolute_on_unix() { + Assert::true(is_executable(CommandLine::$UNIX->resolve('/bin/ls')->current())); + } + + #[Test] + public function resolve_path_on_win() { + Assert::false(CommandLine::$WINDOWS->resolve('\\')->valid()); + } + + #[Test, Runtime(os: '^Win')] + public function resolve_explorer_on_win() { + Assert::true(is_executable(CommandLine::$WINDOWS->resolve('explorer')->current())); + } + + #[Test, Runtime(os: '^Win')] + public function resolve_with_extension_on_win() { + Assert::true(is_executable(CommandLine::$WINDOWS->resolve('explorer.exe')->current())); + } + + #[Test, Runtime(os: '^Win')] + public function resolve_absolute_on_win() { + Assert::true(is_executable(CommandLine::$UNIX->resolve(getenv('WINDIR').'\\explorer.exe')->current())); + } + + #[Test, Runtime(os: '^Win')] + public function resolve_quoted_on_win() { + Assert::true(is_executable(CommandLine::$WINDOWS->resolve('"explorer"')->current())); + } } \ No newline at end of file diff --git a/src/test/php/lang/unittest/ProcessResolveTest.class.php b/src/test/php/lang/unittest/ProcessResolveTest.class.php deleted file mode 100755 index b69633554..000000000 --- a/src/test/php/lang/unittest/ProcessResolveTest.class.php +++ /dev/null @@ -1,127 +0,0 @@ -origDir= getcwd(); - } - - #[After] - public function tearDown() { - chdir($this->origDir); - } - - /** - * Replaces backslashes in the specified path by the new separator. If $skipDrive is set - * to TRUE, the leading drive letter definition (e.g. 'C:') is removed from the new path. - * - * @param string $path - * @param string $newSeparator - * @param bool $skipDrive - * @return string - */ - private function replaceBackslashSeparator($path, $newSeparator, $skipDrive) { - $parts= explode('\\', $path); - if (preg_match('/[a-z]:/i', $parts[0]) != 0 && $skipDrive) array_shift($parts); - return implode($newSeparator, $parts); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveFullyQualifiedWithDriverLetter() { - Assert::true(is_executable(Process::resolve(getenv('WINDIR').'\\EXPLORER.EXE'))); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveFullyQualifiedWithDriverLetterWithoutExtension() { - Assert::true(is_executable(Process::resolve(getenv('WINDIR').'\\EXPLORER'))); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveFullyQualifiedWithBackSlash() { - $path= '\\'.$this->replaceBackslashSeparator(getenv('WINDIR').'\\EXPLORER.EXE', '\\', TRUE); - chdir('C:'); - Assert::true(is_executable(Process::resolve($path))); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveFullyQualifiedWithSlash() { - $path= '/'.$this->replaceBackslashSeparator(getenv('WINDIR').'\\EXPLORER.EXE', '/', TRUE); - chdir('C:'); - Assert::true(is_executable(Process::resolve($path))); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveFullyQualifiedWithoutExtension() { - $path='\\'.$this->replaceBackslashSeparator(getenv('WINDIR').'\\EXPLORER', '\\', TRUE); - chdir('C:'); - Assert::true(is_executable(Process::resolve($path))); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveCommandInPath() { - Assert::true(is_executable(Process::resolve('explorer.exe'))); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveCommandInPathWithoutExtension() { - Assert::true(is_executable(Process::resolve('explorer'))); - } - - #[Test, Expect(IOException::class)] - public function resolveSlashDirectory() { - Process::resolve('/'); - } - - #[Test, Runtime(os: 'WIN'), Expect(IOException::class)] - public function resolveBackslashDirectory() { - Process::resolve('\\'); - } - - #[Test, Expect(IOException::class)] - public function resolveEmpty() { - Process::resolve(''); - } - - #[Test, Expect(IOException::class)] - public function resolveNonExistant() { - Process::resolve('@@non-existant@@'); - } - - #[Test, Expect(IOException::class)] - public function resolveNonExistantFullyQualified() { - Process::resolve('/@@non-existant@@'); - } - - #[Test, Runtime(os: 'ANDROID')] - public function resolveFullyQualifiedOnAndroid() { - $fq= getenv('ANDROID_ROOT').'/framework/core.jar'; - Assert::equals($fq, Process::resolve($fq)); - } - - #[Test, Runtime(os: '^(?!WIN|ANDROID)')] - public function resolveFullyQualifiedOnPosix() { - Assert::true(in_array(Process::resolve('/bin/ls'), ['/usr/bin/ls', '/bin/ls'])); - } - - #[Test, Values(['"ls"', "'ls'"]), Runtime(os: '^(?!WIN|ANDROID)')] - public function resolveQuotedOnPosix($command) { - Assert::true(in_array(Process::resolve($command), ['/usr/bin/ls', '/bin/ls'])); - } - - #[Test, Runtime(os: 'WIN')] - public function resolveQuotedOnWindows() { - Assert::true(is_executable(Process::resolve('"explorer"'))); - } - - #[Test, Runtime(os: '^(?!WIN|ANDROID)')] - public function resolve() { - Assert::true(in_array(Process::resolve('ls'), ['/usr/bin/ls', '/bin/ls'])); - } -} \ No newline at end of file