[Monodevelop-patches-list] r2363 - in trunk/MonoDevelop: Extras Extras/NUnit Extras/NUnit/Commands Extras/NUnit/Gui Extras/NUnit/Services Unused build/data/resources/icons
John Luke <jluke@cfl.rr.com>
jluke at mono-cvs.ximian.com
Wed Mar 16 19:41:19 EST 2005
Author: jluke
Date: 2005-03-16 19:41:19 -0500 (Wed, 16 Mar 2005)
New Revision: 2363
Added:
trunk/MonoDevelop/Extras/NUnit/
trunk/MonoDevelop/Extras/NUnit/AssemblyInfo.cs
trunk/MonoDevelop/Extras/NUnit/ChangeLog
trunk/MonoDevelop/Extras/NUnit/Commands/
trunk/MonoDevelop/Extras/NUnit/Commands/NUnitCommands.cs
trunk/MonoDevelop/Extras/NUnit/Gui/
trunk/MonoDevelop/Extras/NUnit/Gui/CircleImage.cs
trunk/MonoDevelop/Extras/NUnit/Gui/ResultsView.cs
trunk/MonoDevelop/Extras/NUnit/Gui/TestPad.cs
trunk/MonoDevelop/Extras/NUnit/Makefile
trunk/MonoDevelop/Extras/NUnit/MonoDevelopNUnit.addin.xml
trunk/MonoDevelop/Extras/NUnit/README
trunk/MonoDevelop/Extras/NUnit/Services/
trunk/MonoDevelop/Extras/NUnit/Services/NUnitService.cs
trunk/MonoDevelop/Extras/NUnit/TODO
trunk/MonoDevelop/build/data/resources/icons/Nunit.Failed
trunk/MonoDevelop/build/data/resources/icons/Nunit.None
trunk/MonoDevelop/build/data/resources/icons/Nunit.NotRun
trunk/MonoDevelop/build/data/resources/icons/Nunit.Success
Removed:
trunk/MonoDevelop/Unused/Nunit/
trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Green.png
trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.None.png
trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Red.png
trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Yellow.png
Log:
begin to redo the nunit stuff so it will work
Added: trunk/MonoDevelop/Extras/NUnit/AssemblyInfo.cs
===================================================================
Added: trunk/MonoDevelop/Extras/NUnit/ChangeLog
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/ChangeLog 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/ChangeLog 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,3 @@
+2005-03-16 John Luke <john.luke at gmail.com>
+
+ * Redo the nunit addin based on gnunit
Added: trunk/MonoDevelop/Extras/NUnit/Commands/NUnitCommands.cs
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/Commands/NUnitCommands.cs 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/Commands/NUnitCommands.cs 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,38 @@
+using System;
+using System.IO;
+using Gtk;
+
+using MonoDevelop.Core.Services;
+using MonoDevelop.Services;
+using MonoDevelop.Gui.Widgets;
+using MonoDevelop.Core.AddIns.Codons;
+
+namespace MonoDevelop.Commands
+{
+ public class NUnitLoadAssembly : AbstractMenuCommand
+ {
+ public override void Run ()
+ {
+ NUnitService nunitService = (NUnitService) ServiceManager.GetService (typeof (NUnitService));
+
+ using (FileSelector fs = new FileSelector ("Load test assembly")) {
+ //fs.DefaultPath = Path.Combine (Environment.GetEnvironmentVariable ("HOME"), "Projects");
+
+ if (fs.Run () == (int) Gtk.ResponseType.Ok)
+ {
+ nunitService.LoadAssembly (fs.Filename);
+ }
+
+ fs.Hide ();
+ }
+ }
+ }
+
+ public class NUnitRunTests : AbstractMenuCommand
+ {
+ public override void Run ()
+ {
+ Console.WriteLine ("Not implemented");
+ }
+ }
+}
Added: trunk/MonoDevelop/Extras/NUnit/Gui/CircleImage.cs
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/Gui/CircleImage.cs 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/Gui/CircleImage.cs 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,48 @@
+using System;
+using Gdk;
+
+using MonoDevelop.Gui;
+using MonoDevelop.Services;
+using MonoDevelop.Core.Services;
+
+namespace MonoDevelop.NUnit
+{
+ static class CircleImage
+ {
+ static Pixbuf none, failure, success, notrun;
+ static ResourceService res = ServiceManager.GetService (typeof (ResourceService)) as ResourceService;
+
+ internal static Pixbuf Failure {
+ get {
+ if (failure == null)
+ failure = res.GetIcon (Stock.NunitFailed);
+ return failure;
+ }
+ }
+
+ internal static Pixbuf None {
+ get {
+ if (none == null)
+ none = res.GetIcon (Stock.NunitNone);
+ return none;
+ }
+ }
+
+ internal static Pixbuf NotRun {
+ get {
+ if (notrun == null)
+ notrun = res.GetIcon (Stock.NunitNotRun);
+ return notrun;
+ }
+ }
+
+ internal static Pixbuf Success {
+ get {
+ if (success == null)
+ success = res.GetIcon (Stock.NunitSuccess);
+ return success;
+ }
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Extras/NUnit/Gui/ResultsView.cs
===================================================================
Added: trunk/MonoDevelop/Extras/NUnit/Gui/TestPad.cs
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/Gui/TestPad.cs 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/Gui/TestPad.cs 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,181 @@
+using System;
+using System.Collections;
+using System.Reflection;
+using Gtk;
+
+using MonoDevelop.Core.Services;
+using MonoDevelop.Services;
+using MonoDevelop.Gui;
+
+using NUnit.Framework;
+using NUnit.Core;
+
+namespace MonoDevelop.NUnit
+{
+ public class TestPad : AbstractPadContent
+ {
+ string assemblyName;
+ ScrolledWindow sw;
+ TreeView view;
+ TreeStore store;
+ Hashtable iters;
+ TestSuite rootTestSuite;
+ NUnitService nunitService;
+
+ int currentTest, totalTests;
+
+ public TestPad () : base ("NUnit")
+ {
+ sw = new ScrolledWindow ();
+ CreateView ();
+ sw.Add (view);
+ sw.ShowAll ();
+
+ // color, name
+ store = new TreeStore (typeof (Gdk.Pixbuf), typeof (string));
+
+ nunitService = ServiceManager.GetService (typeof (NUnitService)) as NUnitService;
+
+ // register events
+ nunitService.AssemblyLoaded += OnAssemblyLoaded;
+ nunitService.TestFinishedEvent += OnTestFinished;
+ }
+
+ public override Widget Control {
+ get { return sw; }
+ }
+
+ void CreateView ()
+ {
+ view = new TreeView ();
+ view.HeadersVisible = false;
+
+ CellRendererPixbuf pr = new CellRendererPixbuf ();
+ CellRendererText tr = new CellRendererText ();
+ TreeViewColumn column = new TreeViewColumn ();
+ column.PackStart (pr, false);
+ column.AddAttribute (pr, "pixbuf", 0);
+ column.PackStart (tr, false);
+ column.AddAttribute (tr, "text", 1);
+ view.AppendColumn (column);
+
+ view.RowActivated += OnRowActivated;
+ }
+
+ TreeIter AddFixture (TreeIter parent, string fullname)
+ {
+ string [] parts = fullname.Split ('.');
+ string index = String.Empty;
+
+ foreach (string s in parts)
+ {
+ if (index.Length == 0)
+ index = s;
+ else
+ index += String.Format (".{0}", s);
+
+ if (iters.ContainsKey (index)) {
+ parent = (TreeIter) iters [index];
+ continue;
+ }
+
+ parent = store.AppendValues (parent, CircleImage.None, s);
+ iters[index] = parent;
+ }
+
+ return parent;
+ }
+
+ void AddTestSuite (TreeIter parent, TestSuite suite)
+ {
+ TreeIter next;
+ foreach (Test t in suite.Tests)
+ {
+ next = AddFixture (parent, t.FullName);
+ while (GLib.MainContext.Iteration ());
+
+ if (t.IsSuite)
+ AddTestSuite (next, (TestSuite) t);
+ // FIXME: else fixture addevent
+ }
+ }
+
+ void OnAssemblyLoaded (object sender, EventArgs a)
+ {
+ GLib.Idle.Add (new GLib.IdleHandler (Populate));
+ }
+
+ void OnRowActivated (object sender, RowActivatedArgs a)
+ {
+ RunTestAtPath (a.Path);
+ }
+
+ void OnTestFinished (object sender, TestEventArgs a)
+ {
+ SetIconFromResult (a.Result);
+ }
+
+ bool Populate ()
+ {
+ Assembly test = nunitService.TestAssembly;
+ store.Clear ();
+ assemblyName = test.FullName;
+ TreeIter root = store.AppendValues (CircleImage.None, assemblyName);
+ iters = new Hashtable ();
+ iters[assemblyName] = root;
+
+ rootTestSuite = nunitService.GetTestSuite (assemblyName);
+
+ currentTest = 0;
+ totalTests = rootTestSuite.CountTestCases ();
+ AddTestSuite (root, rootTestSuite);
+ //OnFinishedLoad
+
+ view.Model = store;
+ return false;
+ }
+
+ void RunTestAtPath (TreePath path)
+ {
+ nunitService.RunTest (GetTestFromPath (path.ToString (), null));
+ }
+
+ Test GetTestFromPath (string path, Test t)
+ {
+ string [] parts = path.Split (':');
+ if (t == null) {
+ if (parts.Length > 1)
+ return GetTestFromPath (String.Join (":", parts, 1, parts.Length - 1), rootTestSuite);
+
+ return rootTestSuite;
+ }
+
+ Test ret;
+ if (parts.Length == 1) {
+ ret = (Test) t.Tests [Int32.Parse (path)];
+ return ret;
+ }
+
+ ret = (Test) t.Tests [Int32.Parse (parts [0])];
+ return GetTestFromPath (String.Join (":", parts, 1, parts.Length - 1), ret);
+ }
+
+ void SetIconFromResult (TestResult result)
+ {
+ string fullname = result.Test.FullName;
+
+ if (iters.ContainsKey (fullname)) {
+ TreeIter iter = (TreeIter) iters [fullname];
+ if (!result.Executed)
+ store.SetValue (iter, 0, CircleImage.NotRun);
+ else if (result.IsFailure)
+ store.SetValue (iter, 0, CircleImage.Failure);
+ else if (result.IsSuccess)
+ store.SetValue (iter, 0, CircleImage.Success);
+ else
+ store.SetValue (iter, 0, CircleImage.None);
+ }
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Extras/NUnit/Makefile
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/Makefile 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/Makefile 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,35 @@
+
+CSC = mcs
+ASSEMBLY_NAME = MonoDevelop.NUnit.dll
+ASSEMBLY = ../../build/AddIns/NUnit/$(ASSEMBLY_NAME)
+ADDIN = MonoDevelopNUnit.addin.xml
+
+DLLS = -r:nunit.framework.dll \
+ -r:nunit.core.dll \
+ -r:../../build/bin/MonoDevelop.Core.dll \
+ -r:../../build/bin/MonoDevelop.Base.dll \
+ -r:../../build/bin/MonoDevelop.Gui.Widgets.dll \
+ -pkg:gtk-sharp-2.0
+
+FILES = \
+AssemblyInfo.cs \
+Commands/NUnitCommands.cs \
+Gui/CircleImage.cs \
+Gui/TestPad.cs \
+Gui/ResultsView.cs \
+Services/NUnitService.cs
+
+all: $(ASSEMBLY)
+
+../../build/AddIns/NUnit/$(ADDIN): $(ADDIN)
+ mkdir -p ../../build/AddIns/NUnit
+ cp $(ADDIN) ../../build/AddIns/NUnit/$(ADDIN)
+
+$(ASSEMBLY): $(FILES) ../../build/AddIns/NUnit/$(ADDIN)
+ mkdir -p ../../build/AddIns/NUnit
+ $(CSC) $(DLLS) $(FILES) -out:$@ -target:library
+
+clean:
+ rm -f $(ASSEMBLY) $(ASSEMBLY).mdb
+ rm -f ../../build/AddIns/NUnit/$(ADDIN)
+
Added: trunk/MonoDevelop/Extras/NUnit/MonoDevelopNUnit.addin.xml
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/MonoDevelopNUnit.addin.xml 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/MonoDevelopNUnit.addin.xml 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,38 @@
+<AddIn name = "MonoDevelop NUnit"
+ author = "John Luke"
+ copyright = "GPL"
+ url = "http://monodevelop.com"
+ description = "NUnit testing tool"
+ version = "0.6">
+
+ <Runtime>
+ <Import assembly="MonoDevelop.NUnit.dll" />
+ </Runtime>
+
+ <Extension path="/Workspace/Services">
+ <Class id = "NUnitService"
+ class = "MonoDevelop.Services.NUnitService" />
+ </Extension>
+
+ <Extension path = "/SharpDevelop/Workbench/Pads">
+ <Pad id = "MonoDevelop.NUnit.TestPad" class = "MonoDevelop.NUnit.TestPad" />
+ </Extension>
+
+ <Extension path = "/SharpDevelop/Workbench/Contexts/Edit">
+ <ContextPad id = "MonoDevelop.NUnit.TestPad" />
+ </Extension>
+
+ <Extension path = "/SharpDevelop/Workbench/MainMenu/Tools">
+ <MenuItem id = "NUnitMenu" _label = "NUnit">
+ <MenuItem id = "LoadTestAssembly"
+ _label = "Load test assembly"
+ shortcut = ""
+ class = "MonoDevelop.Commands.NUnitLoadAssembly" />
+ <MenuItem id = "NUnitRunTests"
+ _label = "Run tests"
+ shortcut = ""
+ class = "MonoDevelop.Commands.NUnitRunTests" />
+ </MenuItem>
+ </Extension>
+
+</AddIn>
Added: trunk/MonoDevelop/Extras/NUnit/README
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/README 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/README 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,3 @@
+This is a port of Gonzalo's gnunit
+from mono cvs, so he deserves the copyright, credit, etc
+
Added: trunk/MonoDevelop/Extras/NUnit/Services/NUnitService.cs
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/Services/NUnitService.cs 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/Services/NUnitService.cs 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,129 @@
+using System;
+using System.IO;
+using System.Reflection;
+
+using NUnit.Core;
+using MonoDevelop.Core.Services;
+
+namespace MonoDevelop.Services
+{
+ public class NUnitService : AbstractService, EventListener
+ {
+ Assembly asm;
+
+ public event EventHandler AssemblyLoaded;
+ public event EventHandler FixtureLoadError;
+ public event EventHandler RunFinishedEvent;
+ public event EventHandler RunStartedEvent;
+ public event TestEventHandler SuiteFinishedEvent;
+ public event TestEventHandler SuiteStartedEvent;
+ public event TestEventHandler TestFinishedEvent;
+ public event TestEventHandler TestStartedEvent;
+ public event EventHandler UnhandledExceptionEvent;
+
+ public NUnitService ()
+ {
+ }
+
+ public Assembly TestAssembly {
+ get { return asm; }
+ }
+
+ public TestSuite GetTestSuite (string assemblyName)
+ {
+ ResolveEventHandler reh = new ResolveEventHandler (TryLoad);
+ AppDomain.CurrentDomain.AssemblyResolve += reh;
+
+ TestSuite suite = null;
+ try {
+ suite = new TestSuiteBuilder ().Build (assemblyName);
+ }
+ catch (Exception e) {
+ if (FixtureLoadError != null)
+ FixtureLoadError (this, EventArgs.Empty);
+ // FixtureLoadError (this, new FixtureLoadErrorArgs (assemblyName, e));
+ }
+ finally {
+ AppDomain.CurrentDomain.AssemblyResolve -= reh;
+ }
+ return suite;
+ }
+
+ public void LoadAssembly (string path)
+ {
+ if (path == null)
+ throw new ArgumentNullException ("path");
+ if (!File.Exists (path))
+ throw new Exception ("assembly could not be found: " + path);
+
+ asm = Assembly.LoadFrom (path);
+ if (AssemblyLoaded != null)
+ AssemblyLoaded (this, EventArgs.Empty);
+ }
+
+ public void RunFinished (Exception exception)
+ {
+ if (RunFinishedEvent != null)
+ RunFinishedEvent (this, EventArgs.Empty);
+ }
+
+ public void RunFinished (TestResult[] results)
+ {
+ if (RunFinishedEvent != null)
+ RunFinishedEvent (this, EventArgs.Empty);
+ }
+
+ public void RunStarted (Test[] tests)
+ {
+ if (RunStartedEvent != null)
+ RunStartedEvent (this, EventArgs.Empty);
+ }
+
+ public void RunTest (Test test)
+ {
+ test.Run (this);
+ }
+
+ public void SuiteFinished (TestSuiteResult result)
+ {
+ if (SuiteFinishedEvent != null)
+ SuiteFinishedEvent (this, new TestEventArgs (TestAction.SuiteFinished, result));
+ }
+
+ public void SuiteStarted (TestSuite suite)
+ {
+ if (SuiteStartedEvent != null)
+ SuiteStartedEvent (this, new TestEventArgs (TestAction.SuiteStarting, suite));
+ }
+
+ public void TestFinished (TestCaseResult result)
+ {
+ if (TestFinishedEvent != null)
+ TestFinishedEvent (this, new TestEventArgs (TestAction.TestFinished, result));
+ }
+
+ public void TestStarted (TestCase test)
+ {
+ if (TestStartedEvent != null)
+ TestStartedEvent (this, new TestEventArgs (TestAction.TestStarting, test));
+ }
+
+ Assembly TryLoad (object sender, ResolveEventArgs a)
+ {
+ try {
+ // NUnit2 uses Assembly.Load on the filename without extension.
+ // This is done just to allow loading from a full path name.
+ return Assembly.LoadFrom (asm.FullName);
+ }
+ catch { }
+ return null;
+ }
+
+ public void UnhandledException (Exception exception)
+ {
+ if (UnhandledExceptionEvent != null)
+ UnhandledExceptionEvent (this, EventArgs.Empty);
+ }
+ }
+}
+
Added: trunk/MonoDevelop/Extras/NUnit/TODO
===================================================================
--- trunk/MonoDevelop/Extras/NUnit/TODO 2005-03-16 19:54:37 UTC (rev 2362)
+++ trunk/MonoDevelop/Extras/NUnit/TODO 2005-03-17 00:41:19 UTC (rev 2363)
@@ -0,0 +1,11 @@
+load assembly/run context menus
+
+viewing results
+save the results to xml
+hook up progress/status
+
+what about the other tabs
+(gnunit had 4)
+
+integrate testing with projects
+
Deleted: trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Green.png
===================================================================
(Binary files differ)
Deleted: trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.None.png
===================================================================
(Binary files differ)
Deleted: trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Red.png
===================================================================
(Binary files differ)
Deleted: trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Yellow.png
===================================================================
(Binary files differ)
Copied: trunk/MonoDevelop/build/data/resources/icons/Nunit.Failed (from rev 2360, trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Red.png)
Copied: trunk/MonoDevelop/build/data/resources/icons/Nunit.None (from rev 2360, trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.None.png)
Copied: trunk/MonoDevelop/build/data/resources/icons/Nunit.NotRun (from rev 2360, trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Yellow.png)
Copied: trunk/MonoDevelop/build/data/resources/icons/Nunit.Success (from rev 2360, trunk/MonoDevelop/build/data/resources/icons/MonoDevelop.Nunit.Green.png)
More information about the Monodevelop-patches-list
mailing list