Example #1
0
        private int GetProcessTest(TestInfo testcase)
        {
            int exitCode        = -1;
            var argReplacements = new Dictionary <string, string>()
            {
                { "TEST_FILE", testcase.Path },
                { "TEST_FILE_DIR", Path.GetDirectoryName(testcase.Path) }
            };

            var wdReplacements = new Dictionary <string, string>()
            {
                { "ROOT", FindRoot() },
                { "TEST_FILE_DIR", Path.GetDirectoryName(testcase.Path) }
            };

            using (Process proc = new Process()) {
                proc.StartInfo.FileName  = Executable;
                proc.StartInfo.Arguments = ReplaceVariables(testcase.Options.Arguments, argReplacements);

                if (!string.IsNullOrEmpty(IRONPYTHONPATH))
                {
                    proc.StartInfo.EnvironmentVariables["IRONPYTHONPATH"] = IRONPYTHONPATH;
                }

                if (!string.IsNullOrEmpty(testcase.Options.WorkingDirectory))
                {
                    proc.StartInfo.WorkingDirectory = ReplaceVariables(testcase.Options.WorkingDirectory, wdReplacements);
                }

                proc.StartInfo.UseShellExecute       = false;
                proc.StartInfo.RedirectStandardError = proc.StartInfo.RedirectStandardOutput = testcase.Options.Redirect;
                proc.Start();

                if (testcase.Options.Redirect)
                {
                    AsyncStreamReader(proc.StandardOutput, data => NUnit.Framework.TestContext.Out.Write(data));
                    AsyncStreamReader(proc.StandardError, data => NUnit.Framework.TestContext.Error.Write(data));
                }

                if (!proc.WaitForExit(testcase.Options.Timeout))
                {
                    proc.Kill();
                    NUnit.Framework.TestContext.Error.WriteLine($"{testcase.Name} timed out after {testcase.Options.Timeout / 1000.0} seconds.");
                }
                exitCode = proc.ExitCode;
            }
            return(exitCode);

            void AsyncStreamReader(StreamReader reader, Action <string> handler)
            {
                byte[] buffer = new byte[4096];
                BeginReadAsync();

                void BeginReadAsync()
                {
                    reader.BaseStream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(ReadCallback), null);
                }

                void ReadCallback(IAsyncResult asyncResult)
                {
                    var bytesRead = reader.BaseStream.EndRead(asyncResult);

                    if (bytesRead > 0)
                    {
                        var data = reader.CurrentEncoding.GetString(buffer, 0, bytesRead);
                        handler?.Invoke(data);
                        BeginReadAsync();
                    }
                }
            }
        }
Example #2
0
 public int IronPythonTests(TestInfo testcase)
 {
     return(this.executor.RunTest(testcase));
 }
Example #3
0
 public override int Test(TestInfo testcase)
 {
     return(TestImpl(testcase));
 }
Example #4
0
 public abstract int Test(TestInfo testcase);