public virtual ProcessAsyncOperation Execute(ExecutionCommand command, OperationConsole console) { ProcessExecutionCommand cmd = (ProcessExecutionCommand)command; IDictionary <string, string> vars; if (defaultEnvironmentVariables != null && defaultEnvironmentVariables.Count > 0) { if (cmd.EnvironmentVariables.Count == 0) { vars = defaultEnvironmentVariables; } else { // Merge the variables. vars = new Dictionary <string, string> (defaultEnvironmentVariables); foreach (KeyValuePair <string, string> evar in cmd.EnvironmentVariables) { vars [evar.Key] = evar.Value; } } } else { vars = cmd.EnvironmentVariables; } return(Runtime.ProcessService.StartConsoleProcess(cmd.Command, cmd.Arguments, cmd.WorkingDirectory, console, vars)); }
UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext) { var outFile = Path.GetTempFileName (); LocalConsole cons = new LocalConsole (); try { MonoDevelop.NUnit.External.TcpTestListener tcpListener = null; LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null); if (!string.IsNullOrEmpty (cmd.Arguments)) cmd.Arguments += " "; cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath; bool automaticUpdates = cmd.Command != null && (cmd.Command.Contains ("GuiUnit") || (cmd.Command.Contains ("mdtool.exe") && cmd.Arguments.Contains ("run-md-tests"))); if (!string.IsNullOrEmpty(pathName)) cmd.Arguments += " -run=" + test.TestId; if (automaticUpdates) { tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName); cmd.Arguments += " -port=" + tcpListener.Port; } // Note that we always dispose the tcp listener as we don't want it listening // forever if the test runner does not try to connect to it using (tcpListener) { using (var p = testContext.ExecutionContext.Execute (cmd, cons)) { testContext.Monitor.CancelRequested += p.Cancel; if (testContext.Monitor.IsCancelRequested) p.Cancel (); p.WaitForCompleted (); testContext.Monitor.CancelRequested -= p.Cancel; } if (new FileInfo (outFile).Length == 0) throw new Exception ("Command failed"); } // mdtool.exe does not necessarily guarantee we get automatic updates. It just guarantees // that if guiunit is being used then it will give us updates. If you have a regular test // assembly compiled against nunit.framework.dll if (automaticUpdates && tcpListener.HasReceivedConnection) { if (testName != null) return localMonitor.SingleTestResult; return test.GetLastResult (); } XDocument doc = XDocument.Load (outFile); if (doc.Root != null) { var root = doc.Root.Elements ("test-suite").FirstOrDefault (); if (root != null) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } bool macunitStyle = doc.Root.Element ("environment") != null && doc.Root.Element ("environment").Attribute ("macunit-version") != null; var result = ReportXmlResult (localMonitor, root, "", macunitStyle); if (testName != null) result = localMonitor.SingleTestResult; return result; } } throw new Exception ("Test results could not be parsed."); } catch (Exception ex) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } testContext.Monitor.ReportRuntimeError ("Test execution failed.\n" + ot + "\n" + et, ex); return UnitTestResult.CreateIgnored ("Test execution failed"); } finally { File.Delete (outFile); cons.Dispose (); } }
private static ExecutionCommand CreateExecutionCommand(HaxeProject project, HaxeProjectConfiguration configuration) { string hxmlPath = Path.GetFullPath (project.TargetHXMLFile); if (!File.Exists (hxmlPath)) { hxmlPath = Path.Combine (project.BaseDirectory, project.TargetHXMLFile); } string hxml = File.ReadAllText (hxmlPath); hxml = hxml.Replace (Environment.NewLine, " "); string[] hxmlArgs = hxml.Split (' '); List<string> platforms = new List<string> (); List<string> platformOutputs = new List<string> (); bool addNext = false; bool nextIsMain = false; string main = ""; foreach (string hxmlArg in hxmlArgs) { if (addNext) { if (!hxmlArg.StartsWith ("-")) { if (nextIsMain) { main = hxmlArg; nextIsMain = false; } else { platformOutputs.Add (hxmlArg); } } else { if (!nextIsMain) { platforms.RemoveAt (platforms.Count - 1); } } } addNext = true; switch (hxmlArg) { case "-cpp": platforms.Add ("cpp"); break; case "-swf": case "-swf9": platforms.Add ("flash"); break; case "-js": platforms.Add ("js"); break; case "-neko": platforms.Add ("neko"); break; case "-php": platforms.Add ("php"); break; case "-main": nextIsMain = true; break; default: addNext = false; break; } } int i = 0; //for (int i = 0; i < platforms.Count; i++) //{ string platform = platforms[i]; string output = platformOutputs[i]; if (platform == "cpp" || platform == "neko") { if (platform == "cpp") { output = Path.Combine (output, main); if (configuration.DebugMode) { output += "-debug"; } } if (!File.Exists (Path.GetFullPath (output))) { output = Path.Combine (project.BaseDirectory, output); } string exe = ""; string args = ""; if (platform == "cpp") { exe = output; } else { exe = "neko"; args = "\"" + output + "\""; } NativeExecutionCommand cmd = new NativeExecutionCommand (exe); cmd.Arguments = args; cmd.WorkingDirectory = Path.GetDirectoryName (output); if (configuration.DebugMode) { cmd.EnvironmentVariables.Add ("HXCPP_DEBUG_HOST", "gdb"); cmd.EnvironmentVariables.Add ("HXCPP_DEBUG", "1"); } //cmd.WorkingDirectory = project.BaseDirectory.FullPath; //MonoDevelop.Ide.MessageService.ShowMessage (cmd.Command); //MonoDevelop.Ide.MessageService.ShowMessage (cmd.Arguments); //MonoDevelop.Ide.MessageService.ShowMessage (cmd.WorkingDirectory); return cmd; } else if (platform == "flash" || platform == "js") { if (!File.Exists (Path.GetFullPath (output))) { output = Path.Combine (project.BaseDirectory, output); } if (platform == "js") { output = Path.Combine (Path.GetDirectoryName (output), "index.html"); } //string target = output; switch (Environment.OSVersion.Platform) { case PlatformID.MacOSX: //target = "open \"" + output + "\""; break; case PlatformID.Unix: //target = "xdg-open \"" + output + "\""; break; } ProcessExecutionCommand cmd = new ProcessExecutionCommand (); cmd.Command = output; return cmd; } //} return null; }
UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext) { var outFile = Path.GetTempFileName (); LocalConsole cons = new LocalConsole (); try { LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null); if (!string.IsNullOrEmpty (cmd.Arguments)) cmd.Arguments += " "; cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath; bool automaticUpdates = cmd.Command.Contains ("GuiUnit") || (cmd.Command.Contains ("mdtool.exe") && cmd.Arguments.Contains ("run-md-tests")); if (!string.IsNullOrEmpty (testName)) cmd.Arguments += " -run=" + suiteName + "." + testName; else if (!string.IsNullOrEmpty (suiteName)) cmd.Arguments += " -run=" + suiteName; if (automaticUpdates) { var tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor); cmd.Arguments += " -port=" + tcpListener.Port; } var p = testContext.ExecutionContext.Execute (cmd, cons); testContext.Monitor.CancelRequested += p.Cancel; if (testContext.Monitor.IsCancelRequested) p.Cancel (); p.WaitForCompleted (); if (new FileInfo (outFile).Length == 0) throw new Exception ("Command failed"); XDocument doc = XDocument.Load (outFile); if (doc.Root != null) { if (automaticUpdates) { DispatchService.GuiDispatch (delegate { testContext.ResultsPad.InitializeTestRun (test); }); } var root = doc.Root.Elements ("test-suite").FirstOrDefault (); if (root != null) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } bool macunitStyle = doc.Root.Element ("environment") != null && doc.Root.Element ("environment").Attribute ("macunit-version") != null; return ReportXmlResult (localMonitor, root, "", macunitStyle); } } throw new Exception ("Test results could not be parsed."); } catch (Exception ex) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } testContext.Monitor.ReportRuntimeError ("Test execution failed.\n" + ot + "\n" + et, ex); return UnitTestResult.CreateIgnored ("Test execution failed"); } finally { File.Delete (outFile); } }
UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test, string suiteName, string pathName, string testName, TestContext testContext) { var outFile = Path.GetTempFileName (); LocalConsole cons = new LocalConsole (); try { if (!string.IsNullOrEmpty (cmd.Arguments)) cmd.Arguments += " "; cmd.Arguments += "\"-xml=" + outFile + "\" " + AssemblyPath; if (!string.IsNullOrEmpty (testName)) cmd.Arguments += " -run=" + suiteName + "." + testName; else if (!string.IsNullOrEmpty (suiteName)) cmd.Arguments += " -run=" + suiteName; var p = testContext.ExecutionContext.Execute (cmd, cons); testContext.Monitor.CancelRequested += p.Cancel; if (testContext.Monitor.IsCancelRequested) p.Cancel (); p.WaitForCompleted (); if (new FileInfo (outFile).Length == 0) throw new Exception ("Command failed"); LocalTestMonitor localMonitor = new LocalTestMonitor (testContext, test, suiteName, testName != null); XDocument doc = XDocument.Load (outFile); if (doc.Root != null) { var root = doc.Root.Elements ("test-suite").FirstOrDefault (); if (root != null) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } return ReportXmlResult (localMonitor, root, ""); } } throw new Exception ("Test results could not be parsed."); } catch (Exception ex) { cons.SetDone (); var ot = cons.Out.ReadToEnd (); var et = cons.Error.ReadToEnd (); testContext.Monitor.WriteGlobalLog (ot); if (!string.IsNullOrEmpty (et)) { testContext.Monitor.WriteGlobalLog ("ERROR:\n"); testContext.Monitor.WriteGlobalLog (et); } testContext.Monitor.ReportRuntimeError ("Test execution failed.\n" + ot + "\n" + et, ex); return UnitTestResult.CreateIgnored ("Test execution failed"); } finally { File.Delete (outFile); } }