From d606bee9ce3c6146fd872466f0157c31df2b829d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0koda?= Date: Tue, 3 Jul 2012 17:57:27 +0200 Subject: [PATCH] MDL-34147 use cygwin style paths in phpunit hints --- admin/tool/phpunit/cli/util.php | 2 +- lib/phpunit/bootstraplib.php | 17 ++++++++++++++++- lib/phpunit/classes/hint_resultprinter.php | 8 +++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/admin/tool/phpunit/cli/util.php b/admin/tool/phpunit/cli/util.php index 1a8cea7ab44..2986d6497ad 100644 --- a/admin/tool/phpunit/cli/util.php +++ b/admin/tool/phpunit/cli/util.php @@ -123,7 +123,7 @@ Options: -h, --help Print out this help Example: -\$/usr/bin/php lib/phpunit/tool.php --install +\$ php ".phpunit_bootstrap_cli_argument_path('/admin/tool/phpunit/cli/util.php')." --install "; echo $help; exit(0); diff --git a/lib/phpunit/bootstraplib.php b/lib/phpunit/bootstraplib.php index d28de8d0f6b..bc74dc9684a 100644 --- a/lib/phpunit/bootstraplib.php +++ b/lib/phpunit/bootstraplib.php @@ -101,7 +101,11 @@ function phpunit_bootstrap_cli_argument_path($moodlepath) { $path = realpath($CFG->dirroot.$moodlepath); if (strpos($path, $cwd) === 0) { - return substr($path, strlen($cwd)); + $path = substr($path, strlen($cwd)); + } + + if (phpunit_bootstrap_is_cygwin()) { + $path = str_replace('\\', '/', $path); } return $path; @@ -140,3 +144,14 @@ function phpunit_boostrap_fix_file_permissions($file) { return true; } + +/** + * Find out if running under Cygwin on Windows. + * @return bool + */ +function phpunit_bootstrap_is_cygwin() { + if (empty($_SERVER['SHELL']) or empty($_SERVER['OS'])) { + return false; + } + return ($_SERVER['OS'] === 'Windows_NT' and $_SERVER['SHELL'] === '/bin/bash'); +} diff --git a/lib/phpunit/classes/hint_resultprinter.php b/lib/phpunit/classes/hint_resultprinter.php index 638b4d0b112..9e468110bc0 100644 --- a/lib/phpunit/classes/hint_resultprinter.php +++ b/lib/phpunit/classes/hint_resultprinter.php @@ -74,6 +74,12 @@ class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter { $file = substr($file, strlen($cwd)+1); } - $this->write("\nTo re-run:\n phpunit $testName $file\n"); + $executable = 'phpunit'; + if (phpunit_bootstrap_is_cygwin()) { + $file = str_replace('\\', '/', $file); + $executable = 'phpunit.bat'; + } + + $this->write("\nTo re-run:\n $executable $testName $file\n"); } }