MDL-43461 testing: Avoid switching to .bat files when running MinGW
authorDavid Monllao <davidm@moodle.com>
Wed, 8 Jan 2014 03:05:08 +0000 (11:05 +0800)
committerDavid Monllao <davidm@moodle.com>
Tue, 14 Jan 2014 05:11:07 +0000 (13:11 +0800)
MinGW can not execute .bat files (http://sourceforge.net/p/mingw/bugs/1902)
so we should not switch to .bat files when running MinGW.

lib/behat/classes/behat_command.php
lib/behat/classes/behat_config_manager.php
lib/phpunit/classes/hint_resultprinter.php
lib/testing/lib.php

index b70afaa..76a4d25 100644 (file)
@@ -82,8 +82,12 @@ class behat_command {
 
         // Cygwin uses linux-style directory separators.
         if ($custombyterm && testing_is_cygwin()) {
-            $exec = 'behat.bat';
             $separator = '/';
+
+            // MinGW can not execute .bat scripts.
+            if (!testing_is_mingw()) {
+                $exec = 'behat.bat';
+            }
         }
         return 'vendor' . $separator . 'bin' . $separator . $exec;
     }
index 5c05312..7da36b9 100644 (file)
@@ -159,7 +159,7 @@ class behat_config_manager {
     public static function get_steps_list_config_filepath() {
         global $USER;
 
-        // We don't cygwin-it as it is called using exec().
+        // We don't cygwin-it as it is called using exec() which uses cmd.exe.
         $userdir = behat_command::get_behat_dir() . '/users/' . $USER->id;
         make_writable_directory($userdir);
 
index a04b326..2d5dfe7 100644 (file)
@@ -108,7 +108,9 @@ class Hint_ResultPrinter extends PHPUnit_TextUI_ResultPrinter {
             $executable = 'phpunit';
             if (testing_is_cygwin()) {
                 $file = str_replace('\\', '/', $file);
-                $executable = 'phpunit.bat';
+                if (!testing_is_mingw()) {
+                    $executable = 'phpunit.bat';
+                }
             }
         }
 
index c67a1a9..13c8466 100644 (file)
@@ -97,6 +97,30 @@ function testing_is_cygwin() {
     }
 }
 
+/**
+ * Returns whether a mingw CLI is running.
+ *
+ * MinGW sets $_SERVER['TERM'] to cygwin, but it
+ * can not run .bat files; this function may be useful
+ * when we need to output proposed commands to users
+ * using Windows CLI interfaces.
+ *
+ * @link http://sourceforge.net/p/mingw/bugs/1902
+ * @return bool
+ */
+function testing_is_mingw() {
+
+    if (!testing_is_cygwin()) {
+        return false;
+    }
+
+    if (!empty($_SERVER['MSYSTEM'])) {
+        return true;
+    }
+
+    return false;
+}
+
 /**
  * Mark empty dataroot to be used for testing.
  * @param string $dataroot  The dataroot directory