Ejemplo n.º 1
0
        public string Run(IEnumerable <TestCase> tests, string coveragePath)
        {
            string ouputFile = "";

            try {
                DetachFromSillyManagedProcess(_app, _debugMode);

                var env = InitializeEnvironment(tests);
                ouputFile = GetJunitXmlFile();
                var arguments = GetArguments(tests, ouputFile, coveragePath, _projectSettings);

                var testRedirector = new TestRedirector(_frameworkHandle);

                using (var proc = ProcessOutput.Run(
                           _projectSettings.InterpreterPath,
                           arguments,
                           _projectSettings.WorkingDirectory,
                           env,
                           visible: false,
                           testRedirector,
                           quoteArgs: true,
                           elevate: false,
                           System.Text.Encoding.UTF8,
                           System.Text.Encoding.UTF8
                           )) {
                    LogInfo("cd " + _projectSettings.WorkingDirectory);
                    LogInfo("set " + _projectSettings.PathEnv + "=" + env[_projectSettings.PathEnv]);
                    LogInfo(proc.Arguments);

                    if (!proc.ExitCode.HasValue)
                    {
                        try {
                            if (_debugMode != PythonDebugMode.None)
                            {
                                AttachDebugger(_app, proc, _debugMode, _debugSecret, _debugPort);
                            }

                            proc.Wait();
                        } catch (COMException ex) {
                            Error(Strings.Test_ErrorConnecting);
                            DebugError(ex.ToString());
                            try {
                                proc.Kill();
                            } catch (InvalidOperationException) {
                                // Process has already exited
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Error(e.ToString());
            }

            return(ouputFile);
        }
Ejemplo n.º 2
0
        private void RunInternal(IEnumerable <TestCase> tests, string coveragePath, ManualResetEvent cancelRequested)
        {
            try {
                DetachFromSillyManagedProcess(_app, _debugMode);

                var env            = InitializeEnvironment(tests);
                var arguments      = GetArguments(tests, coveragePath);
                var testRedirector = new TestRedirector(_frameworkHandle);

                using (var proc = ProcessOutput.Run(
                           _projectSettings.InterpreterPath,
                           arguments,
                           _projectSettings.WorkingDirectory,
                           env,
                           visible: false,
                           testRedirector,
                           quoteArgs: true,
                           elevate: false,
                           System.Text.Encoding.UTF8,
                           System.Text.Encoding.UTF8
                           )) {
                    LogInfo("cd " + _projectSettings.WorkingDirectory);
                    LogInfo("set " + _projectSettings.PathEnv + "=" + env[_projectSettings.PathEnv]);
                    LogInfo(proc.Arguments);

                    if (!proc.ExitCode.HasValue)
                    {
                        try {
                            if (_debugMode != PythonDebugMode.None)
                            {
                                AttachDebugger(_app, proc, _debugMode, _debugSecret, _debugPort);
                            }

                            var handles = new WaitHandle[] { cancelRequested, proc.WaitHandle };
                            if (proc.WaitHandle != null)
                            {
                                switch (WaitHandle.WaitAny(handles))
                                {
                                case 0:
                                    // We've been cancelled
                                    try {
                                        proc.Kill();
                                    } catch (InvalidOperationException) {
                                        // Process has already exited
                                    }
                                    break;

                                case 1:
                                    break;
                                }
                            }
                        } catch (COMException ex) {
                            Error(Strings.Test_ErrorConnecting);
                            DebugError(ex.ToString());
                            try {
                                proc.Kill();
                            } catch (InvalidOperationException) {
                                // Process has already exited
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Error(e.ToString());
            }
        }