From f8b71928d2962e27bc48ca76549cd7605f647340 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Fri, 17 Apr 2015 10:18:21 +0800 Subject: [PATCH] MDL-49456 behat: Use proper dir separator to support different os --- admin/tool/behat/cli/run.php | 6 ++--- lib/behat/classes/behat_command.php | 34 +++++++++++++++++++---------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/admin/tool/behat/cli/run.php b/admin/tool/behat/cli/run.php index 0a5e0aab193..06630eab8f5 100644 --- a/admin/tool/behat/cli/run.php +++ b/admin/tool/behat/cli/run.php @@ -152,7 +152,7 @@ $extraopts = implode(' ', $extraopts); if (empty($parallelrun)) { $cwd = getcwd(); chdir(__DIR__); - $runtestscommand = '../../../../' . behat_command::get_behat_command(); + $runtestscommand = behat_command::get_behat_command(false, false, true); $runtestscommand .= ' --config ' . behat_config_manager::get_behat_cli_config_filepath(); $runtestscommand .= ' ' . $extraopts; echo "Running single behat site:" . PHP_EOL; @@ -195,11 +195,11 @@ for ($i = $options['fromrun']; $i <= $options['torun']; $i++) { // Options parameters to be added to each run. $myopts = !empty($options['replace']) ? str_replace($options['replace'], $i, $extraopts) : $extraopts; - $behatcommand = behat_command::get_behat_command(); + $behatcommand = behat_command::get_behat_command(false, false, true); $behatconfigpath = behat_config_manager::get_behat_cli_config_filepath($i); // Command to execute behat run. - $cmds[BEHAT_PARALLEL_SITE_NAME . $i] = '../../../../' . $behatcommand . ' --config ' . $behatconfigpath . " " . $myopts; + $cmds[BEHAT_PARALLEL_SITE_NAME . $i] = $behatcommand . ' --config ' . $behatconfigpath . " " . $myopts; echo "[" . BEHAT_PARALLEL_SITE_NAME . $i . "] " . $cmds[BEHAT_PARALLEL_SITE_NAME . $i] . PHP_EOL; } diff --git a/lib/behat/classes/behat_command.php b/lib/behat/classes/behat_command.php index d82f2dbedfc..9c0d6839388 100644 --- a/lib/behat/classes/behat_command.php +++ b/lib/behat/classes/behat_command.php @@ -86,26 +86,36 @@ class behat_command { * * @param bool $custombyterm If the provided command should depend on the terminal where it runs * @param bool $parallelrun If parallel run is installed. + * @param bool $absolutepath return command with absolute path. * @return string */ - public final static function get_behat_command($custombyterm = false, $parallerun = false) { + public final static function get_behat_command($custombyterm = false, $parallerun = false, $absolutepath = false) { $separator = DIRECTORY_SEPARATOR; - if (!$parallerun) { - $exec = 'behat'; + $exec = 'behat'; - // Cygwin uses linux-style directory separators. - if ($custombyterm && testing_is_cygwin()) { - $separator = '/'; + // Cygwin uses linux-style directory separators. + if ($custombyterm && testing_is_cygwin()) { + $separator = '/'; - // MinGW can not execute .bat scripts. - if (!testing_is_mingw()) { - $exec = 'behat.bat'; - } + // MinGW can not execute .bat scripts. + if (!testing_is_mingw()) { + $exec = 'behat.bat'; } - $command = 'vendor' . $separator . 'bin' . $separator . $exec; + } + + // If relative path then prefix relative path. + if ($absolutepath) { + $pathprefix = testing_cli_argument_path('/') . $separator; } else { - $command = 'php admin' . $separator . 'tool' . $separator . 'behat' . $separator . 'cli' . $separator . 'run.php'; + $pathprefix = ''; + } + + if (!$parallerun) { + $command = $pathprefix . 'vendor' . $separator . 'bin' . $separator . $exec; + } else { + $command = 'php ' . $pathprefix . 'admin' . $separator . 'tool' . $separator . 'behat' . $separator . 'cli' + . $separator . 'run.php'; } return $command; }