[mono/monodevelop] [3 commits] d6abdaf8: [NUnit] Don't assume that automatic updates always work

"Alan McGovern ([email protected])" <[email protected]>
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000141ebe7c26c-72971248-d165-4230-bf76-cee301d1ba2b-000000@email.amazonses.com>
   Branch: refs/heads/license-sync
     Home: https://github.com/mono/monodevelop
  Compare: https://github.com/mono/monodevelop/compare/eabd362a9e02...5dc5a343f517

   Commit: d6abdaf8b053737306fc948fca6ba1d8c9975834
   Author: Alan McGovern <[email protected]> (alanmcgovern)
     Date: 2013-10-24 19:15:23 GMT
      URL: https://github.com/mono/monodevelop/commit/d6abdaf8b053737306fc948fca6ba1d8c9975834

[NUnit] Don't assume that automatic updates always work

Only guiunit can give automatic updates, regardless of whether mdtool
is used or not. As such, even if we think automatic updates might
work we should protect against the case where they do not by loading
up the xml file at the end if automatic updates have not been received.

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=15477

Changed paths:
  M main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
  M main/src/addins/NUnit/Services/TcpTestListener.cs

Modified: main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
===================================================================
@@ -465,6 +465,7 @@ UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test,
 			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))
@@ -477,20 +478,28 @@ UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test,
 				else if (!string.IsNullOrEmpty (suiteName))
 					cmd.Arguments += " -run=" + suiteName;
 				if (automaticUpdates) {
-					var tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName);
+					tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName);
 					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");
+				// 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) {
+					var p = testContext.ExecutionContext.Execute (cmd, cons);
 
-				if (automaticUpdates) {
+					testContext.Monitor.CancelRequested += p.Cancel;
+					if (testContext.Monitor.IsCancelRequested)
+						p.Cancel ();
+					p.WaitForCompleted ();
+					
+					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 ();

Modified: main/src/addins/NUnit/Services/TcpTestListener.cs
===================================================================
@@ -38,11 +38,15 @@
 
 namespace MonoDevelop.NUnit.External
 {
-	class TcpTestListener
+	class TcpTestListener : IDisposable
 	{
 		string testSuiteName;
 		string rootTestName;
 
+		public bool HasReceivedConnection {
+			get; private set;
+		}
+
 		List<Tuple<string,UnitTestResult>> suiteStack = new List<Tuple<string, UnitTestResult>> ();
 		IRemoteEventListener listener;
 
@@ -120,6 +124,11 @@ public TcpTestListener (IRemoteEventListener listener, string suiteName)
 			});
 		}
 
+		public void Dispose ()
+		{
+			TcpListener.Stop ();
+		}
+
 		void UpdateTestSuiteStatus (string name, bool isTest)
 		{
 			if (testSuiteName.Length > 0)

   Commit: 750c8d610165b106dee8ba109fe505867b3388f0
   Author: alan <[email protected]> 
Committer: Alan McGovern <[email protected]> (alanmcgovern)
     Date: 2013-10-24 19:15:30 GMT
      URL: https://github.com/mono/monodevelop/commit/750c8d610165b106dee8ba109fe505867b3388f0

[NUnit] Use the pathname

The pathname is the correct thing to use, not the suitename
and testname.

The pathname handles tests subclassing other tests in the correct manner

Changed paths:
  M main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs

Modified: main/src/addins/NUnit/Services/NUnitAssemblyTestSuite.cs
===================================================================
@@ -472,11 +472,9 @@ UnitTestResult RunWithConsoleRunner (ProcessExecutionCommand cmd, UnitTest test,
 					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;
+				bool automaticUpdates = cmd.Command.Contains ("GuiUnit") || (cmd.Command.Contains ("mdtool.exe") && cmd.Arguments.Contains ("run-md-tests"));
+				if (!string.IsNullOrEmpty(pathName))
+					cmd.Arguments += " -run=" + pathName;
 				if (automaticUpdates) {
 					tcpListener = new MonoDevelop.NUnit.External.TcpTestListener (localMonitor, suiteName);
 					cmd.Arguments += " -port=" + tcpListener.Port;

   Commit: 5dc5a343f5171b3aaab39195f5a9bf1d64ccdcf9
   Author: Alan McGovern <[email protected]> (alanmcgovern)
     Date: 2013-10-24 19:15:48 GMT
      URL: https://github.com/mono/monodevelop/commit/5dc5a343f5171b3aaab39195f5a9bf1d64ccdcf9

[NUnit] GuiUnit as a project reference now works

I figured out a way to get the output filename for GuiUnit.exe
so i can now give that as the custom command when no other custom
command is supplied.

This means that both a direct binary reference on guiunit.exe and
also a project reference on it's csproj both result in your test
assembly being run using guiunit.exe

Changed paths:
  M main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs

Modified: main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs
===================================================================
@@ -64,7 +64,7 @@ public NUnitProjectTestSuite (DotNetProject project): base (project.Name, projec
 		public static NUnitProjectTestSuite CreateTest (DotNetProject project)
 		{
 			foreach (var p in project.References)
-				if (p.Reference.IndexOf ("GuiUnit") != -1 || p.Reference.IndexOf ("nunit.framework") != -1 || p.Reference.IndexOf ("nunit.core") != -1)
+				if (p.Reference.IndexOf ("GuiUnit", StringComparison.OrdinalIgnoreCase) != -1 || p.Reference.IndexOf ("nunit.framework") != -1 || p.Reference.IndexOf ("nunit.core") != -1)
 					return new NUnitProjectTestSuite (project);
 			return null;
 		}
@@ -134,10 +134,17 @@ public override void GetCustomConsoleRunner (out string command, out string args
 			command = r != null ? project.BaseDirectory.Combine (r.ToString ()).ToString () : null;
 			args = (string)project.ExtendedProperties ["TestRunnerArgs"];
 			if (command == null && args == null) {
-				var guiUnit = project.References.FirstOrDefault (pref => pref.ReferenceType == ReferenceType.Assembly && Path.GetFileName (pref.Reference) == "GuiUnit.exe");
+				var guiUnit = project.References.FirstOrDefault (pref => pref.ReferenceType == ReferenceType.Assembly && StringComparer.OrdinalIgnoreCase.Equals (Path.GetFileName (pref.Reference), "GuiUnit.exe"));
 				if (guiUnit != null) {
 					command = guiUnit.Reference;
 				}
+
+				var projectReference = project.References.FirstOrDefault (pref => pref.ReferenceType == ReferenceType.Project && pref.Reference.StartsWith ("GuiUnit", StringComparison.OrdinalIgnoreCase));
+				if (IdeApp.IsInitialized && command == null && projectReference != null) {
+					var guiUnitProject = IdeApp.Workspace.GetAllProjects ().First (f => f.Name == projectReference.Reference);
+					if (guiUnitProject != null)
+						command = guiUnitProject.GetOutputFileName (IdeApp.Workspace.ActiveConfiguration);
+				}
 			}
 		}
 


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.