You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ju...@apache.org on 2019/05/25 00:10:44 UTC

[netbeans] branch master updated: [NETBEANS-2573] Pass files to test in env variable

This is an automated email from the ASF dual-hosted git repository.

junichi11 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new e00f562  [NETBEANS-2573] Pass files to test in env variable
     new b191e23  Merge pull request #1264 from tmysik/NETBEANS-2573
e00f562 is described below

commit e00f56272d9d0d1b814d2f8f1ba0ea784b4a683a
Author: Tomas Mysik <to...@gmail.com>
AuthorDate: Fri May 24 21:37:09 2019 +0200

    [NETBEANS-2573] Pass files to test in env variable
---
 php/php.phpunit/release/phpunit/NetBeansSuite.php  | 21 ++++--------
 .../modules/php/phpunit/commands/PhpUnit.java      | 40 ++++++++++++++++++----
 2 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/php/php.phpunit/release/phpunit/NetBeansSuite.php b/php/php.phpunit/release/phpunit/NetBeansSuite.php
index e2825f6..0613941 100644
--- a/php/php.phpunit/release/phpunit/NetBeansSuite.php
+++ b/php/php.phpunit/release/phpunit/NetBeansSuite.php
@@ -43,10 +43,10 @@ if (!class_exists('PHPUnit_Framework_TestSuite')) {
  */
 class NetBeansSuite extends PHPUnit_Framework_TestSuite {
     /**
-     * The name of the parameter followed by equals sign ("=") of the file or directory to be run by PHPUnit.
+     * The name of the environment variable containing the file or directory to be run by PHPUnit.
      * @see toRun()
      */
-    const RUN = "--run=";
+    const ENV_RUN = "NB_PHPUNIT_RUN";
 
     /**
      * Suite factory.
@@ -69,26 +69,19 @@ class NetBeansSuite extends PHPUnit_Framework_TestSuite {
     }
 
     /**
-     * Tries to find {@link #RUN) in CLI parameters and returns array of files to be runj by PHPUnit
-     * or throws Exception if no such parameter found or directory/file does not exist.
+     * Tries to find {@link #ENV_RUN) in environment variables and returns array of files to be run by PHPUnit
+     * or throws Exception if no such variable found or directory/file does not exist.
      *
      * @access private
      * @static
      *
      * @return array an array of files to be run by PHPUnit
-     * @see RUN
+     * @see ENV_RUN
      */
     private static function toRun() {
-        $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
-        $run = null;
-        foreach ($argv as $arg) {
-            if (preg_match("/^\"?".self::RUN."(.+?)\"?$/", $arg, $sub)) {
-                $run = $sub[1];
-                break;
-            }
-        }
+        $run = getenv(self::ENV_RUN);
         if ($run === null) {
-            throw new Exception(sprintf("No argument to run (%s) found.", self::RUN));
+            throw new Exception(sprintf("No environment variable to run (%s) found.", self::ENV_RUN));
         }
         $result = array();
         foreach (explode(";", $run) as $part) {
diff --git a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java
index 92f2f6c..a4902e1 100644
--- a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java
+++ b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/commands/PhpUnit.java
@@ -31,6 +31,7 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
+import java.util.Map;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.ExecutionException;
 import java.util.logging.Level;
@@ -117,7 +118,7 @@ public final class PhpUnit {
 
     // suite file
     private static final String SUITE_NAME = "NetBeansSuite"; // NOI18N
-    private static final String SUITE_RUN = "--run=%s"; // NOI18N
+    private static final String SUITE_RUN = "NB_PHPUNIT_RUN"; // NOI18N
     private static final String SUITE_PATH_DELIMITER = ";"; // NOI18N
     private static final String SUITE_REL_PATH = "phpunit/" + SUITE_NAME + ".php"; // NOI18N
 
@@ -243,7 +244,9 @@ public final class PhpUnit {
         if (workingDirectory != null) {
             phpUnit.workDir(workingDirectory);
         }
-        phpUnit.additionalParameters(getTestParams(phpModule, runInfo));
+        TestParams testParams = getTestParams(phpModule, runInfo);
+        phpUnit.additionalParameters(testParams.getParams());
+        phpUnit.environmentVariables(testParams.getEnvironmentVariables());
         ExecutionDescriptor descriptor = getTestDescriptor();
         try {
             if (runInfo.getSessionType() == TestRunInfo.SessionType.TEST) {
@@ -332,8 +335,9 @@ public final class PhpUnit {
         return params;
     }
 
-    private List<String> getTestParams(PhpModule phpModule, TestRunInfo runInfo) throws TestRunException {
+    private TestParams getTestParams(PhpModule phpModule, TestRunInfo runInfo) throws TestRunException {
         List<String> params = createParams(true);
+        Map<String, String> envVariables = Collections.emptyMap();
         params.add(JUNIT_LOG_PARAM);
         params.add(XML_LOG.getAbsolutePath());
         addBootstrap(phpModule, params);
@@ -403,11 +407,13 @@ public final class PhpUnit {
                 //params.add(SUITE_NAME)
                 params.add(getNbSuite().getAbsolutePath());
                 // #254276
-                params.add(PARAM_SEPARATOR);
-                params.add(String.format(SUITE_RUN, joinPaths(startFiles, SUITE_PATH_DELIMITER)));
+                //params.add(PARAM_SEPARATOR);
+                //params.add(String.format(SUITE_RUN, joinPaths(startFiles, SUITE_PATH_DELIMITER)));
+                // NETBEANS-2573
+                envVariables = Collections.singletonMap(SUITE_RUN, joinPaths(startFiles, SUITE_PATH_DELIMITER));
             }
         }
-        return params;
+        return new TestParams(params, envVariables);
     }
 
     private void addBootstrap(PhpModule phpModule, List<String> params) {
@@ -779,4 +785,26 @@ public final class PhpUnit {
 
     }
 
+    private static final class TestParams {
+
+        private final List<String> params;
+        private final Map<String, String> environmentVariables;
+
+        public TestParams(List<String> params, Map<String, String> environmentVariables) {
+            assert params != null;
+            assert environmentVariables != null;
+            this.params = params;
+            this.environmentVariables = environmentVariables;
+        }
+
+        public List<String> getParams() {
+            return params;
+        }
+
+        public Map<String, String> getEnvironmentVariables() {
+            return environmentVariables;
+        }
+
+    }
+
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists