[Mono-devel-list] Patch to use ExpectedException inTestXmlTextWriterTests

Martin Willemoes Hansen mwh at sysrq.dk
Thu Jul 3 10:29:07 EDT 2003


On Thu, 2003-07-03 at 15:34, Gert Driesen wrote:
> I would prefer to have it added to NUnit itself, not to the copy of the
> NUnit code base in mono cvs ...
> 
> I've submitted a feature request for this, but I'm not sure how active the
> NUnit developer community is right now ...

Ive patched our local NUnit copy to include a Message for the
ExpectedExceptionAttribute, could you forward the patch to the NUnit
folks, maybe they can use it.

Unfortunatly I do not know the NUnit srces that well, there is probably
a cleaner way to do what I do in my patch ...


-- 
Martin Willemoes Hansen

--------------------------------------------------------
E-Mail	mwh at sysrq.dk	Website	mwh.sysrq.dk
IRC     MWH, freenode.net	
--------------------------------------------------------               

-------------- next part --------------
? .makefrag
? .makefrag-exe
? .response
? .response-exe
? framework.diff
? library-deps.stamp
Index: ExpectedExceptionAttribute.cs
===================================================================
RCS file: /cvs/public/mcs/nunit20/framework/ExpectedExceptionAttribute.cs,v
retrieving revision 1.1
diff -u -r1.1 ExpectedExceptionAttribute.cs
--- ExpectedExceptionAttribute.cs	9 Dec 2002 14:39:22 -0000	1.1
+++ ExpectedExceptionAttribute.cs	3 Jul 2003 14:40:34 -0000
@@ -39,10 +39,26 @@
 	public sealed class ExpectedExceptionAttribute : Attribute
 	{
 		private Type expectedException;
+		private string message;
 
 		public ExpectedExceptionAttribute(Type exceptionType)
 		{
 			expectedException = exceptionType;
+		}
+
+		public ExpectedExceptionAttribute(Type exceptionType, string message)
+		{
+			expectedException = exceptionType;
+			this.message = message;
+		}
+
+		public string Message {
+			get { 
+				if (message == null)
+					return string.Empty;
+
+				return message; 
+			}
 		}
 
 		public Type ExceptionType 
Index: ExpectedExceptionTestCase.cs
===================================================================
RCS file: /cvs/public/mcs/nunit20/framework/ExpectedExceptionTestCase.cs,v
retrieving revision 1.1
diff -u -r1.1 ExpectedExceptionTestCase.cs
--- ExpectedExceptionTestCase.cs	9 Dec 2002 14:39:22 -0000	1.1
+++ ExpectedExceptionTestCase.cs	3 Jul 2003 14:40:34 -0000
@@ -54,7 +54,12 @@
 			}
 			else
 			{
-				string message = "Expected: " + expectedException.Name + " but was " + exception.GetType().Name;
+				Type exceptionAttr = typeof(NUnit.Framework.ExpectedExceptionAttribute);
+				NUnit.Framework.ExpectedExceptionAttribute attr = (NUnit.Framework.ExpectedExceptionAttribute)
+					Method.GetCustomAttributes(exceptionAttr, false) [0];
+
+				string message = "Expected: " + expectedException.Name + " but was " + exception.GetType().Name +
+					         "Message: " + attr.Message;
 				testResult.Failure(message, exception.StackTrace);
 			}
 
Index: TemplateTestCase.cs
===================================================================
RCS file: /cvs/public/mcs/nunit20/framework/TemplateTestCase.cs,v
retrieving revision 1.1
diff -u -r1.1 TemplateTestCase.cs
--- TemplateTestCase.cs	9 Dec 2002 14:39:22 -0000	1.1
+++ TemplateTestCase.cs	3 Jul 2003 14:40:34 -0000
@@ -46,6 +46,10 @@
 			this.method = method;
 		}
 
+		public MethodInfo Method {
+			get { return method; }
+		}
+
 		public override void Run(TestCaseResult testResult)
 		{
 			if(ShouldRun)


More information about the Mono-devel-list mailing list