Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Baulig <martin@novell.com>2002-02-27 12:38:21 +0300
committerMartin Baulig <martin@novell.com>2002-02-27 12:38:21 +0300
commit7f0542b133e5f1eee15f337e0263c14406091a7e (patch)
tree66b127d66c5356f2e6c8b5036846273cad41536a
parent9f187b5dd0b323582e2aec7c7f17f7a1cd4ba07b (diff)
Importing NUnit 1.11.NUNIT_1_11
svn path=/branches/NUNIT/mcs/; revision=2713
-rw-r--r--mcs/nunit/src/NUnitConsole/AssemblyInfo.cs8
-rw-r--r--mcs/nunit/src/NUnitConsole/NUnitConsoleMain.cs65
-rw-r--r--mcs/nunit/src/NUnitConsole/TestRunner.cs481
-rw-r--r--mcs/nunit/src/NUnitCore/ActiveTestSuite.cs188
-rw-r--r--mcs/nunit/src/NUnitCore/AssemblyInfo.cs6
-rw-r--r--mcs/nunit/src/NUnitCore/Assertion.cs380
-rw-r--r--mcs/nunit/src/NUnitCore/AssertionFailedError.cs38
-rw-r--r--mcs/nunit/src/NUnitCore/BaseTestRunner.cs584
-rw-r--r--mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs32
-rw-r--r--mcs/nunit/src/NUnitCore/ExceptionTestCase.cs98
-rw-r--r--mcs/nunit/src/NUnitCore/IProtectable.cs23
-rw-r--r--mcs/nunit/src/NUnitCore/ITest.cs30
-rw-r--r--mcs/nunit/src/NUnitCore/ITestCollector.cs29
-rw-r--r--mcs/nunit/src/NUnitCore/ITestListener.cs135
-rw-r--r--mcs/nunit/src/NUnitCore/ITestSuiteLoader.cs30
-rw-r--r--mcs/nunit/src/NUnitCore/LoadingTestCollector.cs113
-rw-r--r--mcs/nunit/src/NUnitCore/NUnitException.cs71
-rw-r--r--mcs/nunit/src/NUnitCore/ReflectionUtils.cs154
-rw-r--r--mcs/nunit/src/NUnitCore/ReloadingTestSuiteLoader.cs55
-rw-r--r--mcs/nunit/src/NUnitCore/StandardTestSuiteLoader.cs80
-rw-r--r--mcs/nunit/src/NUnitCore/TestCase.cs421
-rw-r--r--mcs/nunit/src/NUnitCore/TestCaseClassLoader.cs58
-rw-r--r--mcs/nunit/src/NUnitCore/TestDecorator.cs125
-rw-r--r--mcs/nunit/src/NUnitCore/TestFailure.cs87
-rw-r--r--mcs/nunit/src/NUnitCore/TestResult.cs420
-rw-r--r--mcs/nunit/src/NUnitCore/TestSetup.cs122
-rw-r--r--mcs/nunit/src/NUnitCore/TestSuite.cs528
-rw-r--r--mcs/nunit/src/NUnitCore/Version.cs33
28 files changed, 2373 insertions, 2021 deletions
diff --git a/mcs/nunit/src/NUnitConsole/AssemblyInfo.cs b/mcs/nunit/src/NUnitConsole/AssemblyInfo.cs
index 066fd632d58..be984e5c039 100644
--- a/mcs/nunit/src/NUnitConsole/AssemblyInfo.cs
+++ b/mcs/nunit/src/NUnitConsole/AssemblyInfo.cs
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly:AssemblyVersion("1.10.*")]
+[assembly:AssemblyVersion("1.11.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
@@ -50,6 +50,6 @@ using System.Runtime.CompilerServices;
// (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
// documentation for more information on this.
//
-//[assembly: AssemblyDelaySign(false)]
-//[assembly: AssemblyKeyFile(@"..\..\..\..\NUnit.key")]
-//[assembly: AssemblyKeyName("")]
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile(@"..\..\..\..\NUnit.key")]
+[assembly: AssemblyKeyName("")]
diff --git a/mcs/nunit/src/NUnitConsole/NUnitConsoleMain.cs b/mcs/nunit/src/NUnitConsole/NUnitConsoleMain.cs
index 179742eb10b..cf6091319d3 100644
--- a/mcs/nunit/src/NUnitConsole/NUnitConsoleMain.cs
+++ b/mcs/nunit/src/NUnitConsole/NUnitConsoleMain.cs
@@ -1,30 +1,35 @@
-namespace NUnit {
-
- using System;
- using System.Collections;
-
- using NUnit.Framework;
- using NUnit.Runner;
- using NUnit.TextUI;
- /// <summary>
- ///
- /// </summary>
- public class Top {
- /// <summary>
- ///
- /// </summary>
- /// <param name="args"></param>
- public static void Main(string[] args) {
- TestRunner aTestRunner = new NUnit.TextUI.TestRunner();
- try {
- TestResult r = aTestRunner.Start(args);
- if (!r.WasSuccessful)
- Environment.Exit(1);
- Environment.Exit(0);
- } catch(Exception e) {
- Console.Error.WriteLine(e.Message);
- Environment.Exit(2);
- }
- }
- }
-}
+namespace NUnit
+{
+ using System;
+ using System.Collections;
+ using NUnit.Framework;
+ using NUnit.Runner;
+ using NUnit.TextUI;
+
+ /// <summary>
+ ///
+ /// </summary>
+ public class Top
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="args"></param>
+ public static void Main(string[] args)
+ {
+ TestRunner aTestRunner = new NUnit.TextUI.TestRunner();
+ try
+ {
+ TestResult r = aTestRunner.Start(args);
+ if (!r.WasSuccessful)
+ Environment.Exit(1);
+ Environment.Exit(0);
+ }
+ catch(Exception e)
+ {
+ Console.Error.WriteLine(e.Message);
+ Environment.Exit(2);
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitConsole/TestRunner.cs b/mcs/nunit/src/NUnitConsole/TestRunner.cs
index d773b0b31b3..77493e48866 100644
--- a/mcs/nunit/src/NUnitConsole/TestRunner.cs
+++ b/mcs/nunit/src/NUnitConsole/TestRunner.cs
@@ -1,238 +1,277 @@
-namespace NUnit.TextUI {
+namespace NUnit.TextUI
+{
+ using System;
+ using System.IO;
+ using System.Reflection;
+ using NUnit.Framework;
+ using NUnit.Runner;
- using System;
- using System.IO;
- using System.Reflection;
+ /// <summary>A command line based tool to run tests.</summary><remarks>
+ /// <code>
+ /// C:\NUnitConsole.exe /t [/wait] TestCaseClass
+ /// </code>
+ /// TestRunner expects the name of a TestCase class as argument.
+ /// If this class defines a static <c>Suite</c> property it
+ /// will be invoked and the returned test is run. Otherwise all
+ /// the methods starting with "Test" having no arguments are run.
+ ///
+ /// When the wait command line argument is given TestRunner
+ /// waits until the users types RETURN.
+ ///
+ /// TestRunner prints a trace as the tests are executed followed by a
+ /// summary at the end.</remarks>
+ public class TestRunner : BaseTestRunner
+ {
+ int fColumn = 0;
+ TextWriter fWriter = Console.Out;
- using NUnit.Framework;
- using NUnit.Runner;
+ /// <summary>
+ /// Constructs a TestRunner.
+ /// </summary>
+ public TestRunner() {}
- /// <summary>A command line based tool to run tests.</summary><remarks>
- /// <code>
- /// C:\NUnitConsole.exe /t [/wait] TestCaseClass
- /// </code>
- /// TestRunner expects the name of a TestCase class as argument.
- /// If this class defines a static <c>Suite</c> property it
- /// will be invoked and the returned test is run. Otherwise all
- /// the methods starting with "Test" having no arguments are run.
- ///
- /// When the wait command line argument is given TestRunner
- /// waits until the users types RETURN.
- ///
- /// TestRunner prints a trace as the tests are executed followed by a
- /// summary at the end.</remarks>
- public class TestRunner: BaseTestRunner {
- int fColumn = 0;
- TextWriter fWriter = Console.Out;
+ /// <summary>
+ /// Constructs a TestRunner using the given stream for all the output
+ /// </summary>
+ public TestRunner(TextWriter writer) : this()
+ {
+ if (writer != null)
+ {
+ fWriter= writer;
+ }
+ else
+ {
+ throw new ArgumentNullException("writer");
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="t"></param>
+ public override void AddError(ITest test, Exception t)
+ {
+ lock(this)
+ this.Writer.Write("E");
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="t"></param>
+ public override void AddFailure(ITest test, AssertionFailedError t)
+ {
+ lock (this)
+ this.Writer.Write("F");
+ }
- /// <summary>
- /// Constructs a TestRunner.
- /// </summary>
- public TestRunner() {
- }
+ /// <summary>Creates the TestResult to be used for the test run.</summary>
+ protected TestResult CreateTestResult()
+ {
+ return new TestResult();
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="suite"></param>
+ /// <param name="wait"></param>
+ /// <returns></returns>
+ protected TestResult DoRun(ITest suite, bool wait)
+ {
+ TestResult result= CreateTestResult();
+ result.AddListener(this);
+ long startTime= System.DateTime.Now.Ticks;
+ suite.Run(result);
+ long endTime= System.DateTime.Now.Ticks;
+ long runTime= (endTime-startTime) / 10000;
+ Writer.WriteLine();
+ Writer.WriteLine("Time: "+ElapsedTimeAsString(runTime));
+ Print(result);
- /// <summary>
- /// Constructs a TestRunner using the given stream for all the output
- /// </summary>
- public TestRunner(TextWriter writer) : this() {
- if (writer == null)
- throw new ArgumentException("Writer can't be null");
- fWriter= writer;
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="test"></param>
-/// <param name="t"></param>
- public override void AddError(ITest test, Exception t) {
- lock(this)
- Writer.Write("E");
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="test"></param>
-/// <param name="t"></param>
- public override void AddFailure(ITest test, AssertionFailedError t) {
- lock (this)
- Writer.Write("F");
- }
-
- /// <summary>Creates the TestResult to be used for the test run.</summary>
- protected TestResult CreateTestResult() {
- return new TestResult();
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="suite"></param>
-/// <param name="wait"></param>
-/// <returns></returns>
- protected TestResult DoRun(ITest suite, bool wait) {
- TestResult result= CreateTestResult();
- result.AddListener(this);
- long startTime= System.DateTime.Now.Ticks;
- suite.Run(result);
- long endTime= System.DateTime.Now.Ticks;
- long runTime= (endTime-startTime) / 10000;
- Writer.WriteLine();
- Writer.WriteLine("Time: "+ElapsedTimeAsString(runTime));
- Print(result);
-
- Writer.WriteLine();
+ Writer.WriteLine();
- if (wait) {
- Writer.WriteLine("<RETURN> to continue");
- try {
- Console.ReadLine();
- }
- catch(Exception) {
- }
- }
- return result;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
+ if (wait)
+ {
+ Writer.WriteLine("<RETURN> to continue");
+ try
+ {
+ Console.ReadLine();
+ }
+ catch(Exception)
+ {
+ }
+ }
+ return result;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
- public override void EndTest(ITest test) {
- }
-/// <summary>
-///
-/// </summary>
-/// <returns></returns>
- public override ITestSuiteLoader GetLoader() {
- return new StandardTestSuiteLoader();
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="result"></param>
- public void Print(TestResult result) {
- lock(this) {
- PrintErrors(result);
- PrintFailures(result);
- PrintHeader(result);
- }
- }
+ public override void EndTest(ITest test)
+ {
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public override ITestLoader GetLoader()
+ {
+ return new StandardLoader();
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="result"></param>
+ public void Print(TestResult result)
+ {
+ lock(this)
+ {
+ PrintErrors(result);
+ PrintFailures(result);
+ PrintHeader(result);
+ }
+ }
- /// <summary>Prints the errors to the standard output.</summary>
- public void PrintErrors(TestResult result) {
- if (result.ErrorCount != 0) {
- if (result.ErrorCount == 1)
- Writer.WriteLine("There was "+result.ErrorCount+" error:");
- else
- Writer.WriteLine("There were "+result.ErrorCount+" errors:");
+ /// <summary>Prints the errors to the standard output.</summary>
+ public void PrintErrors(TestResult result)
+ {
+ if (result.ErrorCount != 0)
+ {
+ if (result.ErrorCount == 1)
+ Writer.WriteLine("There was "+result.ErrorCount+" error:");
+ else
+ Writer.WriteLine("There were "+result.ErrorCount+" errors:");
- int i= 1;
- foreach (TestFailure failure in result.Errors) {
- Writer.WriteLine(i++ + ") "+failure+"("+failure.ThrownException.GetType().ToString()+")");
- Writer.Write(GetFilteredTrace(failure.ThrownException));
- }
- }
- }
+ int i= 1;
+ foreach (TestFailure failure in result.Errors)
+ {
+ Writer.WriteLine(i++ + ") "+failure+"("+failure.ThrownException.GetType().ToString()+")");
+ Writer.Write(GetFilteredTrace(failure.ThrownException));
+ }
+ }
+ }
- /// <summary>Prints failures to the standard output.</summary>
- public void PrintFailures(TestResult result) {
- if (result.FailureCount != 0) {
- if (result.FailureCount == 1)
- Writer.WriteLine("There was " + result.FailureCount + " failure:");
- else
- Writer.WriteLine("There were " + result.FailureCount + " failures:");
- int i = 1;
- foreach (TestFailure failure in result.Failures) {
- Writer.Write(i++ + ") " + failure.FailedTest);
- Exception t= failure.ThrownException;
- if (t.Message != "")
- Writer.WriteLine(" \"" + Truncate(t.Message) + "\"");
- else {
- Writer.WriteLine();
- Writer.Write(GetFilteredTrace(failure.ThrownException));
- }
- }
- }
- }
+ /// <summary>Prints failures to the standard output.</summary>
+ public void PrintFailures(TestResult result)
+ {
+ if (result.FailureCount != 0)
+ {
+ if (result.FailureCount == 1)
+ Writer.WriteLine("There was " + result.FailureCount + " failure:");
+ else
+ Writer.WriteLine("There were " + result.FailureCount + " failures:");
+ int i = 1;
+ foreach (TestFailure failure in result.Failures)
+ {
+ Writer.Write(i++ + ") " + failure.FailedTest);
+ Exception t= failure.ThrownException;
+ if (t.Message != "")
+ Writer.WriteLine(" \"" + Truncate(t.Message) + "\"");
+ else
+ {
+ Writer.WriteLine();
+ Writer.Write(GetFilteredTrace(failure.ThrownException));
+ }
+ }
+ }
+ }
- /// <summary>Prints the header of the report.</summary>
- public void PrintHeader(TestResult result) {
- if (result.WasSuccessful) {
- Writer.WriteLine();
- Writer.Write("OK");
- Writer.WriteLine (" (" + result.RunCount + " tests)");
+ /// <summary>Prints the header of the report.</summary>
+ public void PrintHeader(TestResult result)
+ {
+ if (result.WasSuccessful)
+ {
+ Writer.WriteLine();
+ Writer.Write("OK");
+ Writer.WriteLine (" (" + result.RunCount + " tests)");
- } else {
- Writer.WriteLine();
- Writer.WriteLine("FAILURES!!!");
- Writer.WriteLine("Tests Run: "+result.RunCount+
- ", Failures: "+result.FailureCount+
- ", Errors: "+result.ErrorCount);
- }
- }
+ }
+ else
+ {
+ Writer.WriteLine();
+ Writer.WriteLine("FAILURES!!!");
+ Writer.WriteLine("Tests Run: "+result.RunCount+
+ ", Failures: "+result.FailureCount+
+ ", Errors: "+result.ErrorCount);
+ }
+ }
- /// <summary>Runs a Suite extracted from a TestCase subclass.</summary>
- static public void Run(Type testClass) {
- Run(new TestSuite(testClass));
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="suite"></param>
- static public void Run(ITest suite) {
- TestRunner aTestRunner= new TestRunner();
- aTestRunner.DoRun(suite, false);
- }
+ /// <summary>Runs a Suite extracted from a TestCase subclass.</summary>
+ static public void Run(Type testClass)
+ {
+ Run(new TestSuite(testClass));
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="suite"></param>
+ static public void Run(ITest suite)
+ {
+ TestRunner aTestRunner= new TestRunner();
+ aTestRunner.DoRun(suite, false);
+ }
- /// <summary>Runs a single test and waits until the user
- /// types RETURN.</summary>
- static public void RunAndWait(ITest suite) {
- TestRunner aTestRunner= new TestRunner();
- aTestRunner.DoRun(suite, true);
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="message"></param>
- protected override void RunFailed(string message) {
- Console.Error.WriteLine(message);
- Environment.ExitCode = 1;
- throw new ApplicationException(message);
- }
+ /// <summary>Runs a single test and waits until the user
+ /// types RETURN.</summary>
+ static public void RunAndWait(ITest suite)
+ {
+ TestRunner aTestRunner= new TestRunner();
+ aTestRunner.DoRun(suite, true);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ protected override void RunFailed(string message)
+ {
+ Console.Error.WriteLine(message);
+ Environment.ExitCode = 1;
+ throw new ApplicationException(message);
+ }
- /// <summary>Starts a test run. Analyzes the command line arguments
- /// and runs the given test suite.</summary>
- public TestResult Start(string[] args) {
- bool wait = false;
- string testCase = ProcessArguments(args, ref wait);
- if (testCase.Equals(""))
- throw new ApplicationException("Usage: NUnitConsole.exe [/wait] testCaseName, where\n"
- + "name is the name of the TestCase class");
+ /// <summary>Starts a test run. Analyzes the command line arguments
+ /// and runs the given test suite.</summary>
+ public TestResult Start(string[] args)
+ {
+ bool wait = false;
+ string testCase = ProcessArguments(args, ref wait);
+ if (testCase.Equals(""))
+ throw new ApplicationException("Usage: NUnitConsole.exe [/wait] testCaseName, where\n"
+ + "name is the name of the TestCase class");
- try {
- ITest suite = GetTest(testCase);
- return DoRun(suite, wait);
- } catch (Exception e) {
- throw new ApplicationException("Could not create and run test suite.", e);
- }
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="test"></param>
- public override void StartTest(ITest test) {
- lock (this) {
- Writer.Write(".");
- if (fColumn++ >= 40) {
- Writer.WriteLine();
- fColumn = 0;
- }
- }
- }
-/// <summary>
-///
-/// </summary>
- protected TextWriter Writer {
- get { return fWriter; }
- }
- }
+ try
+ {
+ ITest suite = GetTest(testCase);
+ return DoRun(suite, wait);
+ }
+ catch (Exception e)
+ {
+ throw new ApplicationException("Could not create and run test suite.", e);
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ public override void StartTest(ITest test)
+ {
+ lock (this)
+ {
+ Writer.Write(".");
+ if (fColumn++ >= 40)
+ {
+ Writer.WriteLine();
+ fColumn = 0;
+ }
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ protected TextWriter Writer
+ {
+ get { return fWriter; }
+ }
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/ActiveTestSuite.cs b/mcs/nunit/src/NUnitCore/ActiveTestSuite.cs
index 605911d233c..cdba3b0ed9b 100644
--- a/mcs/nunit/src/NUnitCore/ActiveTestSuite.cs
+++ b/mcs/nunit/src/NUnitCore/ActiveTestSuite.cs
@@ -1,93 +1,113 @@
-namespace NUnit.Extensions {
-
- using System;
- using System.Threading;
+namespace NUnit.Extensions
+{
+ using System;
+ using System.Threading;
+ using NUnit.Framework;
- using NUnit.Framework;
-
- /// <summary>A TestSuite for active Tests. It runs each
- /// test in a separate thread and until all
- /// threads have terminated.
- /// -- Aarhus Radisson Scandinavian Center 11th floor</summary>
- public class ActiveTestSuite: TestSuite {
- private int fActiveTestDeathCount;
/// <summary>
- ///
+ /// A TestSuite for active Tests. It runs each test in a
+ /// separate thread and until all threads have terminated.
+ /// -- Aarhus Radisson Scandinavian Center 11th floor
/// </summary>
- /// <param name="result"></param>
- public override void Run(TestResult result) {
- fActiveTestDeathCount= 0;
- base.Run(result);
- WaitUntilFinished();
- }
- /// <summary>
- ///
- /// </summary>
- public class ThreadLittleHelper {
- private ITest fTest;
- private TestResult fResult;
- private ActiveTestSuite fSuite;
+ public class ActiveTestSuite: TestSuite
+ {
+ private int fActiveTestDeathCount;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="result"></param>
+ public override void Run(TestResult result)
+ {
+ fActiveTestDeathCount= 0;
+ base.Run(result);
+ WaitUntilFinished();
+ }
/// <summary>
///
/// </summary>
/// <param name="test"></param>
/// <param name="result"></param>
- /// <param name="suite"></param>
- public ThreadLittleHelper(ITest test, TestResult result,
- ActiveTestSuite suite) {
- fSuite = suite;
- fTest = test;
- fResult = result;
- }
- /// <summary>
- ///
- /// </summary>
- public void Run() {
- try {
- fSuite.BaseRunTest(fTest, fResult);
- } finally {
- fSuite.RunFinished(fTest);
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- /// <param name="result"></param>
- public void BaseRunTest(ITest test, TestResult result) {
- base.RunTest(test, result);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- /// <param name="result"></param>
- public override void RunTest(ITest test, TestResult result) {
- ThreadLittleHelper tlh = new ThreadLittleHelper(test, result, this);
- Thread t = new Thread(new ThreadStart(tlh.Run));
- t.Start();
- }
- void WaitUntilFinished() {
- lock(this) {
- while (fActiveTestDeathCount < TestCount) {
- try {
- Monitor.Wait(this);
- } catch (ThreadInterruptedException) {
- return; // TBD
- }
- }
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- public void RunFinished(ITest test) {
- lock(this) {
- fActiveTestDeathCount++;
- Monitor.PulseAll(this);
- }
- }
- }
+ public void BaseRunTest(ITest test, TestResult result)
+ {
+ base.RunTest(test, result);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="result"></param>
+ public override void RunTest(ITest test, TestResult result)
+ {
+ ThreadLittleHelper tlh = new ThreadLittleHelper(test, result, this);
+ Thread t = new Thread(new ThreadStart(tlh.Run));
+ t.Start();
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ public void RunFinished(ITest test)
+ {
+ lock(this)
+ {
+ fActiveTestDeathCount++;
+ Monitor.PulseAll(this);
+ }
+ }
+ private void WaitUntilFinished()
+ {
+ lock(this)
+ {
+ while (fActiveTestDeathCount < TestCount)
+ {
+ try
+ {
+ Monitor.Wait(this);
+ }
+ catch (ThreadInterruptedException)
+ {
+ return; // TBD
+ }
+ }
+ }
+ }
+ #region Nested Classes
+ /// <summary>
+ ///
+ /// </summary>
+ public class ThreadLittleHelper
+ {
+ private ITest fTest;
+ private TestResult fResult;
+ private ActiveTestSuite fSuite;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="result"></param>
+ /// <param name="suite"></param>
+ public ThreadLittleHelper(ITest test, TestResult result,
+ ActiveTestSuite suite)
+ {
+ fSuite = suite;
+ fTest = test;
+ fResult = result;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ public void Run()
+ {
+ try
+ {
+ fSuite.BaseRunTest(fTest, fResult);
+ }
+ finally
+ {
+ fSuite.RunFinished(fTest);
+ }
+ }
+ }
+ #endregion
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/AssemblyInfo.cs b/mcs/nunit/src/NUnitCore/AssemblyInfo.cs
index a07e95f9736..6f48173a95a 100644
--- a/mcs/nunit/src/NUnitCore/AssemblyInfo.cs
+++ b/mcs/nunit/src/NUnitCore/AssemblyInfo.cs
@@ -30,7 +30,7 @@ using System.Runtime.CompilerServices;
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly:AssemblyVersion("1.10.*")]
+[assembly:AssemblyVersion("1.11.*")]
//
// In order to sign your assembly you must specify a key to use. Refer to the
@@ -51,5 +51,5 @@ using System.Runtime.CompilerServices;
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
-//[assembly: AssemblyKeyFile(@"..\..\..\..\NUnit.key")]
-[assembly: AssemblyKeyName("")]
+[assembly: AssemblyKeyFile(@"..\..\..\..\NUnit.key")]
+[assembly: AssemblyKeyName("")] \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/Assertion.cs b/mcs/nunit/src/NUnitCore/Assertion.cs
index cc626daa47b..f9dbff90457 100644
--- a/mcs/nunit/src/NUnitCore/Assertion.cs
+++ b/mcs/nunit/src/NUnitCore/Assertion.cs
@@ -1,204 +1,184 @@
-namespace NUnit.Framework {
+namespace NUnit.Framework
+{
+ using System;
- using System;
+ /// <summary>A set of Assert methods.</summary>
+ public class Assertion : MarshalByRefObject
+ {
- /// <summary>A set of Assert methods.</summary>
- public class Assertion {
+ /// <summary>
+ /// Protect constructor since it is a static only class
+ /// </summary>
+ protected Assertion():base(){}
+ /// <summary>
+ /// Asserts that a condition is true. If it isn't it throws
+ /// an <see cref="AssertionFailedError"/>.
+ /// </summary>
+ /// <param name="message">The message to display is the condition
+ /// is false</param>
+ /// <param name="condition">The evaluated condition</param>
+ static public void Assert(string message, bool condition)
+ {
+ if (!condition)
+ Assertion.Fail(message);
+ }
+
+ /// <summary>
+ /// Asserts that a condition is true. If it isn't it throws
+ /// an <see cref="AssertionFailedError"/>.
+ /// </summary>
+ /// <param name="condition">The evaluated condition</param>
+ static public void Assert(bool condition)
+ {
+ Assertion.Assert(string.Empty, condition);
+ }
+ /// <summary>
+ /// /// Asserts that two doubles are equal concerning a delta. If the
+ /// expected value is infinity then the delta value is ignored.
+ /// </summary>
+ /// <param name="expected">The expected value</param>
+ /// <param name="actual">The actual value</param>
+ /// <param name="delta">The maximum acceptable difference between the
+ /// the expected and the actual</param>
+ static public void AssertEquals(double expected, double actual, double delta)
+ {
+ Assertion.AssertEquals(string.Empty, expected, actual, delta);
+ }
+ /// <summary>
+ /// /// Asserts that two singles are equal concerning a delta. If the
+ /// expected value is infinity then the delta value is ignored.
+ /// </summary>
+ /// <param name="expected">The expected value</param>
+ /// <param name="actual">The actual value</param>
+ /// <param name="delta">The maximum acceptable difference between the
+ /// the expected and the actual</param>
+ static public void AssertEquals(float expected, float actual, float delta)
+ {
+ Assertion.AssertEquals(string.Empty, expected, actual, delta);
+ }
- /// <summary>Protect constructor since it is a static only class</summary>
- protected Assertion() {
- }
-
- /// <summary>Asserts that a condition is true. If it isn't it throws
- /// an <see cref="AssertionFailedError"/>.</summary>
- static public void Assert(string message, bool condition) {
- if (!condition)
- Fail(message);
- }
-
- /// <summary>Asserts that a condition is true. If it isn't it throws
- /// an <see cref="AssertionFailedError"/>.</summary>
- static public void Assert(bool condition) {
- Assert(null, condition);
- }
-
- /// <summary>Asserts that two booleans are equal.</summary>
- static public void AssertEquals(bool expected, bool actual) {
- AssertEquals(null, expected, actual);
- }
-
- /// <summary>Asserts that two bytes are equal.</summary>
- static public void AssertEquals(byte expected, byte actual) {
- AssertEquals(null, expected, actual);
- }
+ /// <summary>Asserts that two objects are equal. If they are not
+ /// an <see cref="AssertionFailedError"/> is thrown.</summary>
+ static public void AssertEquals(Object expected, Object actual)
+ {
+ Assertion.AssertEquals(string.Empty, expected, actual);
+ }
+
+ /// <summary>Asserts that two doubles are equal concerning a delta.
+ /// If the expected value is infinity then the delta value is ignored.
+ /// </summary>
+ static public void AssertEquals(string message, double expected,
+ double actual, double delta)
+ {
+ // handle infinity specially since subtracting two infinite values gives
+ // NaN and the following test fails
+ if (double.IsInfinity(expected))
+ {
+ if (!(expected == actual))
+ Assertion.FailNotEquals(message, expected, actual);
+ }
+ else if (!(Math.Abs(expected-actual) <= delta))
+ Assertion.FailNotEquals(message, expected, actual);
+ }
+
+ /// <summary>Asserts that two floats are equal concerning a delta.
+ /// If the expected value is infinity then the delta value is ignored.
+ /// </summary>
+ static public void AssertEquals(string message, float expected,
+ float actual, float delta)
+ {
+ // handle infinity specially since subtracting two infinite values gives
+ // NaN and the following test fails
+ if (float.IsInfinity(expected))
+ {
+ if (!(expected == actual))
+ Assertion.FailNotEquals(message, expected, actual);
+ }
+ else if (!(Math.Abs(expected-actual) <= delta))
+ Assertion.FailNotEquals(message, expected, actual);
+ }
- /// <summary>Asserts that two chars are equal.</summary>
- static public void AssertEquals(char expected, char actual) {
- AssertEquals(null, expected, actual);
- }
-
- /// <summary>Asserts that two doubles are equal concerning a delta. If the expected
- /// value is infinity then the delta value is ignored.</summary>
- static public void AssertEquals(double expected, double actual, double delta) {
- AssertEquals(null, expected, actual, delta);
- }
-
- /// <summary>Asserts that two floats are equal concerning a delta. If the expected
- /// value is infinity then the delta value is ignored.</summary>
- static public void AssertEquals(float expected, float actual, float delta) {
- AssertEquals(null, expected, actual, delta);
- }
-
- /// <summary>Asserts that two ints are equal.</summary>
- static public void AssertEquals(int expected, int actual) {
- AssertEquals(null, expected, actual);
- }
-
- /// <summary>Asserts that two longs are equal.</summary>
- static public void AssertEquals(long expected, long actual) {
- AssertEquals(null, expected, actual);
- }
-
- /// <summary>Asserts that two objects are equal. If they are not
- /// an <see cref="AssertionFailedError"/> is thrown.</summary>
- static public void AssertEquals(Object expected, Object actual) {
- AssertEquals(null, expected, actual);
- }
-
- /// <summary>Asserts that two shorts are equal.</summary>
- static public void AssertEquals(short expected, short actual) {
- AssertEquals(null, expected, actual);
- }
-
- /// <summary>Asserts that two bools are equal.</summary>
- static public void AssertEquals(string message, bool expected, bool actual) {
- AssertEquals(message, (object)expected, (object)actual);
- }
-
- /// <summary>Asserts that two bytes are equal.</summary>
- static public void AssertEquals(string message, byte expected, byte actual) {
- AssertEquals(message, (object)expected, (object)actual);
- }
-
- /// <summary>Asserts that two chars are equal.</summary>
- static public void AssertEquals(string message, char expected, char actual) {
- AssertEquals(message, (object)expected, (object)actual);
- }
-
- /// <summary>Asserts that two doubles are equal concerning a delta. If the expected
- /// value is infinity then the delta value is ignored.</summary>
- static public void AssertEquals(string message, double expected,
- double actual, double delta) {
- // handle infinity specially since subtracting two infinite values gives NaN and the
- // following test fails
- if (double.IsInfinity(expected)) {
- if (!(expected == actual))
- FailNotEquals(message, expected, actual);
- } else if (!(Math.Abs(expected-actual) <= delta))
- FailNotEquals(message, expected, actual);
- }
-
- /// <summary>Asserts that two floats are equal concerning a delta. If the expected
- /// value is infinity then the delta value is ignored.</summary>
- static public void AssertEquals(string message, float expected,
- float actual, float delta) {
- // handle infinity specially since subtracting two infinite values gives NaN and the
- // following test fails
- if (double.IsInfinity(expected)) {
- if (!(expected == actual))
- FailNotEquals(message, expected, actual);
- } else if (!(Math.Abs(expected-actual) <= delta))
- FailNotEquals(message, expected, actual);
- }
-
- /// <summary>Asserts that two ints are equal.</summary>
- static public void AssertEquals(string message, int expected, int actual) {
- AssertEquals(message, (object)expected, (object)actual);
- }
-
- /// <summary>Asserts that two longs are equal.</summary>
- static public void AssertEquals(string message, long expected, long actual) {
- AssertEquals(message, (object)expected, (object)actual);
- }
-
- /// <summary>Asserts that two objects are equal. If they are not
- /// an <see cref="AssertionFailedError"/> is thrown.</summary>
- static public void AssertEquals(string message, Object expected,
- Object actual) {
- if (expected == null && actual == null)
- return;
- if (expected != null && expected.Equals(actual))
- return;
- FailNotEquals(message, expected, actual);
- }
-
- /// <summary>Asserts that two shorts are equal.</summary>
- static public void AssertEquals(string message, short expected, short actual) {
- AssertEquals(message, (object)expected, (object)actual);
- }
-
- /// <summary>Asserts that an object isn't null.</summary>
- static public void AssertNotNull(Object anObject) {
- AssertNotNull(null, anObject);
- }
-
- /// <summary>Asserts that an object isn't null.</summary>
- static public void AssertNotNull(string message, Object anObject) {
- Assert(message, anObject != null);
- }
-
- /// <summary>Asserts that an object is null.</summary>
- static public void AssertNull(Object anObject) {
- AssertNull(null, anObject);
- }
-
- /// <summary>Asserts that an object is null.</summary>
- static public void AssertNull(string message, Object anObject) {
- Assert(message, anObject == null);
- }
-
- /// <summary>Asserts that two objects refer to the same object. If they
- /// are not the same an <see cref="AssertionFailedError"/> is thrown.
- /// </summary>
- static public void AssertSame(Object expected, Object actual) {
- AssertSame(null, expected, actual);
- }
-
- /// <summary>Asserts that two objects refer to the same object.
- /// If they are not an <see cref="AssertionFailedError"/> is thrown.
- /// </summary>
- static public void AssertSame(string message, Object expected,
- Object actual) {
- if (expected == actual)
- return;
- FailNotSame(message, expected, actual);
- }
-
- /// <summary>Fails a test with no message.</summary>
- static public void Fail() {
- Fail(null);
- }
-
- /// <summary>Fails a test with the given message.</summary>
- static public void Fail(string message) {
- if (message == null)
- message = "";
- throw new AssertionFailedError(message);
- }
-
- static private void FailNotEquals(string message, Object expected,
- Object actual) {
- string formatted= "";
- if (message != null)
- formatted= message+" ";
- Fail(formatted+"expected:<"+expected+"> but was:<"+actual+">");
- }
-
- static private void FailNotSame(string message, Object expected, Object actual) {
- string formatted= "";
- if (message != null)
- formatted= message+" ";
- Fail(formatted+"expected same");
- }
- }
-}
+ /// <summary>Asserts that two objects are equal. If they are not
+ /// an <see cref="AssertionFailedError"/> is thrown.</summary>
+ static public void AssertEquals(string message, Object expected, Object actual)
+ {
+ if (expected == null && actual == null)
+ return;
+ if (expected != null && expected.Equals(actual))
+ return;
+ Assertion.FailNotEquals(message, expected, actual);
+ }
+
+ /// <summary>Asserts that an object isn't null.</summary>
+ static public void AssertNotNull(Object anObject)
+ {
+ Assertion.AssertNotNull(string.Empty, anObject);
+ }
+
+ /// <summary>Asserts that an object isn't null.</summary>
+ static public void AssertNotNull(string message, Object anObject)
+ {
+ Assertion.Assert(string.Empty, anObject != null);
+ }
+
+ /// <summary>Asserts that an object is null.</summary>
+ static public void AssertNull(Object anObject)
+ {
+ Assertion.AssertNull(string.Empty, anObject);
+ }
+
+ /// <summary>Asserts that an object is null.</summary>
+ static public void AssertNull(string message, Object anObject)
+ {
+ Assertion.Assert(message, anObject == null);
+ }
+
+ /// <summary>Asserts that two objects refer to the same object. If they
+ /// are not the same an <see cref="AssertionFailedError"/> is thrown.
+ /// </summary>
+ static public void AssertSame(Object expected, Object actual)
+ {
+ Assertion.AssertSame(string.Empty, expected, actual);
+ }
+
+ /// <summary>Asserts that two objects refer to the same object.
+ /// If they are not an <see cref="AssertionFailedError"/> is thrown.
+ /// </summary>
+ static public void AssertSame(string message, Object expected, Object actual)
+ {
+ if (expected == actual)
+ return;
+ Assertion.FailNotSame(message, expected, actual);
+ }
+
+ /// <summary>Fails a test with no message.</summary>
+ static public void Fail()
+ {
+ Assertion.Fail(string.Empty);
+ }
+
+ /// <summary>Fails a test with the given message.</summary>
+ static public void Fail(string message)
+ {
+ if (message == null)
+ message = string.Empty;
+ throw new AssertionFailedError(message);
+ }
+
+ static private void FailNotEquals(string message, Object expected, Object actual)
+ {
+ string formatted=string.Empty;
+ if (message != null)
+ formatted= message+" ";
+ Assertion.Fail(formatted+"expected:<"+expected+"> but was:<"+actual+">");
+ }
+
+ static private void FailNotSame(string message, Object expected, Object actual)
+ {
+ string formatted=string.Empty;
+ if (message != null)
+ formatted= message+" ";
+ Assertion.Fail(formatted+"expected same");
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/AssertionFailedError.cs b/mcs/nunit/src/NUnitCore/AssertionFailedError.cs
index ba1a8fec1b6..9afebde079c 100644
--- a/mcs/nunit/src/NUnitCore/AssertionFailedError.cs
+++ b/mcs/nunit/src/NUnitCore/AssertionFailedError.cs
@@ -1,13 +1,27 @@
-namespace NUnit.Framework {
+namespace NUnit.Framework
+{
+ using System;
+ using System.Runtime.Serialization;
- using System;
-
- /// <summary cref="System.Exception">Thrown when an assertion failed.</summary>
- public class AssertionFailedError: Exception {
- /// <summary>
- ///
- /// </summary>
- /// <param name="message"></param>
- public AssertionFailedError (string message) : base(message) {}
- }
-}
+ /// <summary>
+ /// Thrown when an assertion failed.
+ /// </summary>
+ [Serializable]
+ public class AssertionFailedError : ApplicationException//NUnitException
+ {
+ /// <summary>
+ /// Serialization Constructor
+ /// </summary>
+ protected AssertionFailedError(SerializationInfo info,
+ StreamingContext context) : base(info,context){}
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public AssertionFailedError (string message) : base(message) {}
+// public override bool IsAssertionFailure
+// {
+// get{return true;}
+// }
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/BaseTestRunner.cs b/mcs/nunit/src/NUnitCore/BaseTestRunner.cs
index ac423b17e17..7f3adfc6733 100644
--- a/mcs/nunit/src/NUnitCore/BaseTestRunner.cs
+++ b/mcs/nunit/src/NUnitCore/BaseTestRunner.cs
@@ -1,279 +1,323 @@
-namespace NUnit.Runner {
+namespace NUnit.Runner
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+ using System.IO;
+ using System.IO.IsolatedStorage;
+ using System.Reflection;
+ using NUnit.Framework;
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- using System.IO;
- using System.IO.IsolatedStorage;
- using System.Reflection;
+ /// <summary>
+ /// Base class for all test runners.
+ /// </summary>
+ /// <remarks>
+ ///
+ /// </remarks>
+ public abstract class BaseTestRunner: MarshalByRefObject, ITestListener
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ [Obsolete("Shoud be handled by a loader")]
+ public static string SUITE_PROPERTYNAME="Suite";
- using NUnit.Framework;
+ private static NameValueCollection fPreferences = new NameValueCollection();
+ private static int fgMaxMessageLength = 500;
+ private static bool fgFilterStack = true;
- /// <summary>Base class for all test runners.</summary>
- /// <remarks>This class was born live on stage in Sardinia during
- /// XP2000.</remarks>
- public abstract class BaseTestRunner: ITestListener {
- /// <summary>
- ///
- /// </summary>
- public static string SUITE_PROPERTYNAME="Suite";
+ private bool fLoading = true;
+ /// <summary>
+ ///
+ /// </summary>
+ public BaseTestRunner()
+ {
+ fPreferences = new NameValueCollection();
+ fPreferences.Add("loading", "true");
+ fPreferences.Add("filterstack", "true");
+ ReadPreferences();
+ fgMaxMessageLength = GetPreference("maxmessage", fgMaxMessageLength);
+ }
+
+ #region ITestListener Methods
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="t"></param>
+ public abstract void AddError(ITest test, Exception t);
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="t"></param>
+ public abstract void AddFailure(ITest test, AssertionFailedError t);
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ public abstract void EndTest(ITest test);
+ #endregion
- static NameValueCollection fPreferences = new NameValueCollection();
- static int fgMaxMessageLength = 500;
- static bool fgFilterStack = true;
- bool fLoading = true;
- /// <summary>
- ///
- /// </summary>
- public BaseTestRunner() {
- fPreferences = new NameValueCollection();
- fPreferences.Add("loading", "true");
- fPreferences.Add("filterstack", "true");
- ReadPreferences();
- fgMaxMessageLength = GetPreference("maxmessage", fgMaxMessageLength);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- /// <param name="t"></param>
- public abstract void AddError(ITest test, Exception t);
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- /// <param name="t"></param>
- public abstract void AddFailure(ITest test, AssertionFailedError t);
- /// <summary>
- /// Clears the status message.
- /// </summary>
- protected virtual void ClearStatus() { // Belongs in the GUI TestRunner class.
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- public abstract void EndTest(ITest test);
- /// <summary>
- /// Returns the formatted string of the elapsed time.
- /// </summary>
- public static string ElapsedTimeAsString(long runTime) {
- return ((double)runTime/1000).ToString();
- }
- /// <summary>
- /// Extract the class name from a string in VA/Java style
- /// </summary>
- public static string ExtractClassName(string className) {
- if(className.StartsWith("Default package for"))
- return className.Substring(className.LastIndexOf(".")+1);
- return className;
- }
- static bool FilterLine(string line) {
- string[] patterns = new string[] {
- "NUnit.Framework.TestCase",
- "NUnit.Framework.TestResult",
- "NUnit.Framework.TestSuite",
- "NUnit.Framework.Assertion." // don't filter AssertionFailure
- };
- for (int i = 0; i < patterns.Length; i++) {
- if (line.IndexOf(patterns[i]) > 0)
- return true;
- }
- return false;
- }
- /// <summary>
- /// Filters stack frames from internal NUnit classes
- /// </summary>
- public static string FilterStack(string stack) {
- string pref = GetPreference("filterstack");
- if (((pref != null) && !GetPreference("filterstack").Equals("true")) || fgFilterStack == false)
- return stack;
+#if false
+ /// <summary>
+ /// Clears the status message.
+ /// </summary>
+ protected virtual void ClearStatus()
+ {
+ // Belongs in the GUI TestRunner class.
+ }
+#endif
+ /// <summary>
+ /// Returns the formatted string of the elapsed time.
+ /// </summary>
+ public static string ElapsedTimeAsString(long runTime)
+ {
+ return ((double)runTime/1000).ToString();
+ }
+ /// <summary>
+ /// Extract the class name from a string in VA/Java style
+ /// </summary>
+ public static string ExtractClassName(string className)
+ {
+ if(className.StartsWith("Default package for"))
+ return className.Substring(className.LastIndexOf(".")+1);
+ return className;
+ }
+
+ static bool FilterLine(string line)
+ {
+ string[] patterns = new string[]
+ {
+ "NUnit.Framework.TestCase",
+ "NUnit.Framework.TestResult",
+ "NUnit.Framework.TestSuite",
+ "NUnit.Framework.Assertion." // don't filter AssertionFailure
+ };
+ for (int i = 0; i < patterns.Length; i++)
+ {
+ if (line.IndexOf(patterns[i]) > 0)
+ return true;
+ }
+ return false;
+ }
- StringWriter sw = new StringWriter();
- StringReader sr = new StringReader(stack);
+ /// <summary>
+ /// Filters stack frames from internal NUnit classes
+ /// </summary>
+ public static string FilterStack(string stack)
+ {
+ string pref = GetPreference("filterstack");
+ if (((pref != null) && !GetPreference("filterstack").Equals("true"))
+ || fgFilterStack == false)
+ return stack;
- string line;
- try {
- while ((line = sr.ReadLine()) != null) {
- if (!FilterLine(line))
- sw.WriteLine(line);
- }
- } catch (Exception) {
- return stack; // return the stack unfiltered
- }
- return sw.ToString();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="t"></param>
- /// <returns></returns>
- public static string GetFilteredTrace(Exception t) {
- return BaseTestRunner.FilterStack(t.StackTrace);
- }
+ StringWriter sw = new StringWriter();
+ StringReader sr = new StringReader(stack);
- /// <summary>
- ///
- /// </summary>
- /// <param name="key"></param>
- /// <returns></returns>
- public static string GetPreference(string key) {
- return fPreferences.Get(key);
- }
- private static int GetPreference(String key, int dflt)
- {
- String value= GetPreference(key);
- int intValue= dflt;
- if (value == null)
- return intValue;
- try {
- intValue= int.Parse(value);
- }
- catch (FormatException) {
- }
- return intValue;
- }
- private static FileStream GetPreferencesFile() {
- return new IsolatedStorageFileStream("NUnit.Prefs",
- FileMode.OpenOrCreate);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public virtual ITestSuiteLoader GetLoader() {
- if (UseReloadingTestSuiteLoader())
- return new ReloadingTestSuiteLoader();
- return new StandardTestSuiteLoader();
- }
+ try
+ {
+ string line;
+ while ((line = sr.ReadLine()) != null)
+ {
+ if (!FilterLine(line))
+ sw.WriteLine(line);
+ }
+ }
+ catch (Exception)
+ {
+ return stack; // return the stack unfiltered
+ }
+ return sw.ToString();
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="t"></param>
+ /// <returns></returns>
+ public static string GetFilteredTrace(Exception t)
+ {
+ return BaseTestRunner.FilterStack(t.StackTrace);
+ }
- /// <summary>
- /// Returns the ITest corresponding to the given suite. This is
- /// a template method, subclasses override RunFailed(), ClearStatus().
- /// </summary>
- public ITest GetTest(string suiteClassName) {
- if (suiteClassName.Length <= 0) {
- ClearStatus();
- return null;
- }
- Type testClass= null;
- try {
- testClass = LoadSuiteClass(suiteClassName);
- } catch (TypeLoadException e) {
- RunFailed(e.Message);
- return null;
- } catch (Exception e) {
- RunFailed("Error: " + e.ToString());
- return null;
- }
- PropertyInfo suiteProperty= null;
- suiteProperty = testClass.GetProperty(SUITE_PROPERTYNAME, new Type[0]);
- if (suiteProperty == null ) {
- // try to extract a test suite automatically
- ClearStatus();
- return new TestSuite(testClass);
- }
- ITest test= null;
- try {
- // static property
- test= (ITest)suiteProperty.GetValue(null, new Type[0]);
- if (test == null)
- return test;
- } catch(Exception e) {
- RunFailed("Could not get the Suite property. " + e);
- return null;
- }
- ClearStatus();
- return test;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public static bool InVAJava() {
- return false;
- }
- /// <summary>
- /// Returns the loaded Class for a suite name.
- /// </summary>
- protected Type LoadSuiteClass(string suiteClassName) {
- return GetLoader().Load(suiteClassName);
- }
- private static void ReadPreferences() {
- FileStream fs= null;
- try {
- fs= GetPreferencesFile();
- fPreferences= new NameValueCollection(fPreferences);
- ReadPrefsFromFile(ref fPreferences, fs);
- } catch (IOException) {
- try {
- if (fs != null)
- fs.Close();
- } catch (IOException) {
- }
- }
- }
- private static void ReadPrefsFromFile(ref NameValueCollection prefs, FileStream fs) {
- // Real method reads name/value pairs, populates, or maybe just
- // deserializes...
- }
- /// <summary>
- /// Override to define how to handle a failed loading of a test suite.
- /// </summary>
- protected abstract void RunFailed(String message);
- /// <summary>
- /// Truncates a String to the maximum length.
- /// </summary>
- public static String Truncate(String s) {
- if (fgMaxMessageLength != -1 && s.Length > fgMaxMessageLength)
- s= s.Substring(0, fgMaxMessageLength)+"...";
- return s;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- public abstract void StartTest(ITest test);
- /// <summary>
- ///
- /// </summary>
- /// <param name="args"></param>
- /// <param name="wait"></param>
- /// <returns></returns>
- protected string ProcessArguments(string[] args, ref bool wait) {
- string suiteName="";
- wait = false;
- foreach (string arg in args) {
- if (arg.Equals("/noloading"))
- SetLoading(false);
- else if (arg.Equals("/nofilterstack"))
- fgFilterStack = false;
- else if (arg.Equals("/wait"))
- wait = true;
- else if (arg.Equals("/c"))
- suiteName= ExtractClassName(arg);
- else if (arg.Equals("/v")){
- Console.Error.WriteLine("NUnit "+NUnit.Runner.Version.id()
- + " by Philip Craig");
- Console.Error.WriteLine("ported from JUnit 3.6 by Kent Beck"
- + " and Erich Gamma");
- } else
- suiteName = arg;
- }
- return suiteName;
- }
- /// <summary>
- /// Sets the loading behaviour of the test runner
- /// </summary>
- protected void SetLoading(bool enable) {
- fLoading = false;
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- protected bool UseReloadingTestSuiteLoader() {
- return GetPreference("loading").Equals("true") && fLoading;
- }
- }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="key"></param>
+ /// <returns></returns>
+ public static string GetPreference(string key)
+ {
+ return fPreferences.Get(key);
+ }
+
+ private static int GetPreference(String key, int dflt)
+ {
+ String value= GetPreference(key);
+ int intValue= dflt;
+ if (value != null)
+ {
+ try
+ {
+ intValue= int.Parse(value);
+ }
+ catch (FormatException) {}
+ }
+ return intValue;
+ }
+
+ private static FileStream GetPreferencesFile()
+ {
+ return new IsolatedStorageFileStream("NUnit.Prefs", FileMode.OpenOrCreate);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public virtual ITestLoader GetLoader()
+ {
+ if (UseReloadingTestSuiteLoader())
+ return new UnloadingLoader();
+ return new StandardLoader();
+ }
+
+ /// <summary>
+ /// Returns the ITest corresponding to the given suite. This is
+ /// a template method, subclasses override RunFailed(), ClearStatus().
+ /// </summary>
+ public ITest GetTest(string suiteClassName)
+ {
+ ITest test = null;
+ try
+ {
+ test = LoadSuiteClass(suiteClassName);
+ }
+ catch (TypeLoadException e)
+ {
+ RunFailed(e.Message);
+ return null;
+ }
+ catch (Exception e)
+ {
+ RunFailed("Error: " + e.ToString());
+ return null;
+ }
+ //ClearStatus();
+ return test;
+ }
+
+ /// <summary>
+ /// Returns the loaded Class for a suite name.
+ /// </summary>
+ protected ITest LoadSuiteClass(string suiteClassName)
+ {
+ return GetLoader().LoadTest(suiteClassName);
+ }
+
+ private static void ReadPreferences()
+ {
+ FileStream fs= null;
+ try
+ {
+ fs= GetPreferencesFile();
+ fPreferences= new NameValueCollection(fPreferences);
+ ReadPrefsFromFile(ref fPreferences, fs);
+ }
+ catch (IOException)
+ {
+ try
+ {
+ if (fs != null)
+ fs.Close();
+ }
+ catch (IOException)
+ {
+ }
+ }
+ }
+
+ /// <summary>
+ /// Real method reads name/value pairs, populates, or maybe just
+ /// deserializes...
+ /// </summary>
+ /// <param name="prefs"></param>
+ /// <param name="fs"></param>
+ private static void ReadPrefsFromFile(ref NameValueCollection prefs, FileStream fs)
+ {
+ }
+
+ /// <summary>
+ /// Override to define how to handle a failed loading of a test suite.
+ /// </summary>
+ protected abstract void RunFailed(string message);
+
+ /// <summary>
+ /// Truncates a String to the maximum length.
+ /// </summary>
+ /// <param name="message"></param>
+ /// <returns></returns>
+ public static string Truncate(string message)
+ {
+ if (fgMaxMessageLength != -1 && message.Length > fgMaxMessageLength)
+ message = message.Substring(0, fgMaxMessageLength)+"...";
+ return message;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ public abstract void StartTest(ITest test);
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="args"></param>
+ /// <param name="wait"></param>
+ /// <returns></returns>
+ protected string ProcessArguments(string[] args, ref bool wait)
+ {
+ string suiteName="";
+ wait = false;
+ foreach (string arg in args)
+ {
+ if (arg.Equals("/noloading"))
+ SetLoading(false);
+ else if (arg.Equals("/nofilterstack"))
+ fgFilterStack = false;
+ else if (arg.Equals("/wait"))
+ wait = true;
+ else if (arg.Equals("/c"))
+ suiteName= ExtractClassName(arg);
+ else if (arg.Equals("/v"))
+ {
+ Console.Error.WriteLine("NUnit "+NUnit.Runner.Version.id()
+ + " by Philip Craig");
+ Console.Error.WriteLine("ported from JUnit 3.6 by Kent Beck"
+ + " and Erich Gamma");
+ }
+ else
+ suiteName = arg;
+ }
+ return suiteName;
+ }
+
+ /// <summary>
+ /// Sets the loading behaviour of the test runner
+ /// </summary>
+ protected void SetLoading(bool enable)
+ {
+ fLoading = enable;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ protected bool UseReloadingTestSuiteLoader()
+ {
+ return bool.TrueString.Equals( GetPreference("loading")) && fLoading;
+ }
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs b/mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs
index 437cdaab977..0669a285c07 100644
--- a/mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs
+++ b/mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs
@@ -1,37 +1,37 @@
namespace NUnit.Runner
{
-
using System;
using System.Collections;
+ using System.Collections.Specialized;
using System.IO;
/// <summary>
- /// An implementation of a TestCollector that consults the
+ /// A TestCollector that consults the
/// class path. It considers all classes on the class path
/// excluding classes in JARs. It leaves it up to subclasses
/// to decide whether a class is a runnable Test.
- ///
/// <see cref="ITestCollector"/>
/// </summary>
- public abstract class ClassPathTestCollector: ITestCollector
+ [Obsolete("Use StandardLoader or UnloadingLoader")]
+ public abstract class ClassPathTestCollector : ITestCollector
{
/// <summary>
///
/// </summary>
- public ClassPathTestCollector()
- {
- }
+ public ClassPathTestCollector() {}
/// <summary>
///
/// </summary>
/// <returns></returns>
- public Hashtable CollectTests()
+ public string[] CollectTestsClassNames()
{
- string classPath= Environment.GetEnvironmentVariable("Path");
+ string classPath = Environment.GetEnvironmentVariable("Path");
char separator= Path.PathSeparator;
- Hashtable result= new Hashtable(100);
+ ArrayList result = new ArrayList();
CollectFilesInRoots(classPath.Split(separator), result);
- return result;
+ string[] retVal = new string[result.Count];
+ result.CopyTo(retVal);
+ return retVal;
}
/// <summary>
///
@@ -42,7 +42,8 @@ namespace NUnit.Runner
{
return classFileName;
}
- void CollectFilesInRoots(string[] roots, Hashtable result)
+
+ private void CollectFilesInRoots(string[] roots, IList result)
{
foreach (string directory in roots)
{
@@ -55,7 +56,7 @@ namespace NUnit.Runner
if (IsTestClass(file))
{
string className=ClassNameFromFile(file);
- result.Add(className, className);
+ result.Add(className);
}
}
}
@@ -69,8 +70,9 @@ namespace NUnit.Runner
protected virtual bool IsTestClass(string classFileName)
{
return
- (classFileName.EndsWith(".dll") || classFileName.EndsWith(".exe")) &&
- classFileName.IndexOf("Test") > 0;
+ ( classFileName.EndsWith(".dll")
+ || classFileName.EndsWith(".exe"))
+ && classFileName.IndexOf("Test") > 0;
}
}
} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/ExceptionTestCase.cs b/mcs/nunit/src/NUnitCore/ExceptionTestCase.cs
index 8af9414d4fe..a5ae174fd61 100644
--- a/mcs/nunit/src/NUnitCore/ExceptionTestCase.cs
+++ b/mcs/nunit/src/NUnitCore/ExceptionTestCase.cs
@@ -1,51 +1,53 @@
-namespace NUnit.Extensions {
+namespace NUnit.Extensions
+{
+ using System;
+ using NUnit.Framework;
- using System;
+ /// <summary>A TestCase that expects an Exception of class fExpected
+ /// to be thrown.</summary>
+ /// <remarks> The other way to check that an expected exception is thrown is:
+ /// <code>
+ /// try {
+ /// ShouldThrow();
+ /// }catch (SpecialException) {
+ /// return;
+ /// }
+ /// Assertion.Fail("Expected SpecialException");
+ /// </code>
+ ///
+ /// To use ExceptionTestCase, create a TestCase like:
+ /// <code>
+ /// new ExceptionTestCase("TestShouldThrow", typeof(SpecialException));
+ /// </code></remarks>
+ public class ExceptionTestCase: TestCase
+ {
+ private readonly Type fExpected;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="exception"></param>
+ public ExceptionTestCase(string name, Type exception) : base(name)
+ {
+ fExpected= exception;
+ }
- using NUnit.Framework;
-
- /// <summary>A TestCase that expects an Exception of class fExpected
- /// to be thrown.</summary>
- /// <remarks> The other way to check that an expected exception is thrown is:
- /// <code>
- /// try {
- /// ShouldThrow();
- /// }
- /// catch (SpecialException) {
- /// return;
- /// }
- /// Fail("Expected SpecialException");
- /// </code>
- ///
- /// To use ExceptionTestCase, create a TestCase like:
- /// <code>
- /// new ExceptionTestCase("TestShouldThrow", typeof(SpecialException));
- /// </code></remarks>
- public class ExceptionTestCase: TestCase {
-
- readonly Type fExpected;
-/// <summary>
-///
-/// </summary>
-/// <param name="name"></param>
-/// <param name="exception"></param>
- public ExceptionTestCase(string name, Type exception) : base(name) {
- fExpected= exception;
- }
-
- /// <summary>Execute the test method expecting that an Exception of
- /// class fExpected or one of its subclasses will be thrown.</summary>
- protected override void RunTest() {
- try {
- base.RunTest();
- }
- catch (Exception e) {
- if (fExpected.IsAssignableFrom(e.InnerException.GetType()))
- return;
- else
- throw e.InnerException;
- }
- Fail("Expected exception " + fExpected);
- }
- }
+ /// <summary>Execute the test method expecting that an Exception of
+ /// class fExpected or one of its subclasses will be thrown.</summary>
+ protected override void RunTest()
+ {
+ try
+ {
+ base.RunTest();
+ }
+ catch (Exception e)
+ {
+ if (fExpected.IsAssignableFrom(e.InnerException.GetType()))
+ return;
+ else
+ throw e.InnerException;
+ }
+ Assertion.Fail("Expected exception " + fExpected);
+ }
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/IProtectable.cs b/mcs/nunit/src/NUnitCore/IProtectable.cs
index 3186ee57e8e..ad86136602f 100644
--- a/mcs/nunit/src/NUnitCore/IProtectable.cs
+++ b/mcs/nunit/src/NUnitCore/IProtectable.cs
@@ -1,11 +1,12 @@
-namespace NUnit.Framework {
-
- /// <summary> An <c>IProtectable</c> can be run and can throw an Exception.
- /// </summary>
- /// <seealso cref="TestResult"/>
- public interface IProtectable {
-
- /// <summary>Run the the following method protected.</summary>
- void Protect();
- }
-}
+namespace NUnit.Framework
+{
+ /// <summary>
+ /// An <c>IProtectable</c> can be run and can throw an Exception.
+ /// </summary>
+ /// <seealso cref="TestResult"/>
+ public interface IProtectable
+ {
+ /// <summary>Run the the following method protected.</summary>
+ void Protect();
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/ITest.cs b/mcs/nunit/src/NUnitCore/ITest.cs
index 91ee9826715..098f4c0f23f 100644
--- a/mcs/nunit/src/NUnitCore/ITest.cs
+++ b/mcs/nunit/src/NUnitCore/ITest.cs
@@ -1,14 +1,18 @@
-namespace NUnit.Framework {
-
- /// <summary>An <c>ITest</c> can be run and collect its results.</summary>
- /// <seealso cref="TestResult"/>
- public interface ITest {
- /// <summary>Counts the number of test cases that will be run by this
- /// test.</summary>
- int CountTestCases { get; }
-
- /// <summary>Runs a test and collects its result in a
- /// <see cref="TestResult"/> instance.</summary>
- void Run(TestResult result);
- }
+namespace NUnit.Framework
+{
+ /// <summary>An <c>ITest</c> can be run and collect its results.</summary>
+ /// <seealso cref="TestResult"/>
+ public interface ITest
+ {
+ /// <summary>
+ /// Counts the number of test cases that will be run by this test.
+ /// </summary>
+ int CountTestCases { get; }
+ /// <summary>
+ /// Runs a test and collects its result in a
+ /// <see cref="TestResult"/> instance.
+ /// </summary>
+ /// <param name="result"></param>
+ void Run(TestResult result);
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/ITestCollector.cs b/mcs/nunit/src/NUnitCore/ITestCollector.cs
index 920ff19a590..40bf089be83 100644
--- a/mcs/nunit/src/NUnitCore/ITestCollector.cs
+++ b/mcs/nunit/src/NUnitCore/ITestCollector.cs
@@ -1,15 +1,16 @@
-namespace NUnit.Runner {
- using System.Collections;
-
- /// <summary>
- /// Collects Test class names to be presented by the TestSelector.
- /// <see foocref="TestSelector"/>
- /// </summary>
- public interface ITestCollector {
-
- /// <summary>
- /// Returns a StringCollection of qualified class names.
- /// </summary>
- Hashtable CollectTests();
- }
+namespace NUnit.Runner
+{
+ using System;
+
+ /// <summary>
+ /// Collects Test classes to be presented by the TestSelector.
+ /// <see foocref="TestSelector"/>
+ /// </summary>
+ public interface ITestCollector
+ {
+ /// <summary>
+ /// Returns an array of FullNames for classes that are tests.
+ /// </summary>
+ string[] CollectTestsClassNames();
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/ITestListener.cs b/mcs/nunit/src/NUnitCore/ITestListener.cs
index 175814b5d32..87726ea95d4 100644
--- a/mcs/nunit/src/NUnitCore/ITestListener.cs
+++ b/mcs/nunit/src/NUnitCore/ITestListener.cs
@@ -1,78 +1,65 @@
-namespace NUnit.Framework {
-
- using System;
+namespace NUnit.Framework
+{
+ using System;
- /// <summary>A Listener for test progress</summary>
- public interface ITestListener {
- /// <summary>An error occurred.</summary>
- void AddError(ITest test, Exception t);
-
- /// <summary>A failure occurred.</summary>
- void AddFailure(ITest test, AssertionFailedError t);
+ /// <summary>A Listener for test progress</summary>
+ public interface ITestListener
+ {
+ /// <summary>An error occurred.</summary>
+ void AddError(ITest test, Exception ex);
- /// <summary>A test ended.</summary>
- void EndTest(ITest test);
+ /// <summary>A failure occurred.</summary>
+ void AddFailure(ITest test, AssertionFailedError ex);
- /// <summary>A test started.</summary>
- void StartTest(ITest test);
- }
- /// <summary>
- ///
- /// </summary>
- public delegate void TestEventHandler(Object source, TestEventArgs e);
- /// <summary>
- ///
- /// </summary>
- public class TestEventArgs : EventArgs{
- /// <summary>
- ///
- /// </summary>
- protected ITest fTest;
- /// <summary>
- ///
- /// </summary>
- protected TestEventArgs (){}
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- public TestEventArgs (ITest test){
- fTest = test;
- }
- /// <summary>
- ///
- /// </summary>
- public ITest Test{
- get{return fTest;}
- }
- }
- /// <summary>
- ///
- /// </summary>
- public delegate void TestExceptionEventHandler(Object source,
- TestExceptionEventArgs e);
- /// <summary>
- ///
- /// </summary>
- public class TestExceptionEventArgs : TestEventArgs{
- private TestExceptionEventArgs(){}
+ /// <summary>A test ended.</summary>
+ void EndTest(ITest test);
- private Exception fThrownException;
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- /// <param name="e"></param>
- public TestExceptionEventArgs(ITest test, Exception e){
- //this(test);
- fTest = test;
- fThrownException = e;
- }
- /// <summary>
- ///
- /// </summary>
- public Exception ThrownException{
- get{return fThrownException;}
- }
- }
-}
+ /// <summary>A test started.</summary>
+ void StartTest(ITest test);
+ }
+#if false
+ public class TestEventArgs : System.EventArgs
+ {
+ private readonly ITest fTest;
+ public TestEventArgs(ITest test) : base()
+ {
+ fTest = test;
+ }
+ public ITest Test
+ {
+ get { return fTest;}
+ }
+ }
+ public class TestErrorArgs : TestEventArgs
+ {
+ private readonly Exception fThrownException;
+
+ public TestErrorArgs(ITest test, Exception thrownException) : base(test)
+ {
+ fThrownException = thrownException;
+ }
+
+ public TestErrorArgs(TestFailure error)
+ : this(error.FailedTest,error.ThrownException){}
+
+ public Exception ThrownException
+ {
+ get { return fThrownException;}
+
+ }
+ }
+
+ public delegate void TestErrorHandler(TestFailure failure);
+ public delegate void TestEventHandler(ITest test);
+
+ public interface ITestEvents
+ {
+ event TestErrorHandler TestErred;
+ event TestErrorHandler TestFailed;
+ event TestEventHandler TestStarted;
+ event TestEventHandler TestEnded;
+ event TestEventHandler RunStarted;
+ event TestEventHandler RunEnded;
+ }
+#endif
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/ITestSuiteLoader.cs b/mcs/nunit/src/NUnitCore/ITestSuiteLoader.cs
index f7bc5bdc1f0..71f7da29f6e 100644
--- a/mcs/nunit/src/NUnitCore/ITestSuiteLoader.cs
+++ b/mcs/nunit/src/NUnitCore/ITestSuiteLoader.cs
@@ -1,17 +1,17 @@
-namespace NUnit.Runner {
+namespace NUnit.Runner
+{
+ using System;
- using System;
-
- /// <summary>An interface to define how a test suite should be
- /// loaded.</summary>
- public interface ITestSuiteLoader {
- /// <summary>
- ///
- /// </summary>
- Type Load(string suiteClassName);
- /// <summary>
- ///
- /// </summary>
- Type Reload(Type aType);
- }
+ /// <summary>
+ /// An interface to define how a test suite should be loaded.
+ /// </summary>
+ [Obsolete("Use ILoader")]
+ public interface ITestSuiteLoader
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ Type Load(string suiteClassName);
+ //Type Reload(Type aType);
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/LoadingTestCollector.cs b/mcs/nunit/src/NUnitCore/LoadingTestCollector.cs
index 63ac74ef5f0..4938ee952e9 100644
--- a/mcs/nunit/src/NUnitCore/LoadingTestCollector.cs
+++ b/mcs/nunit/src/NUnitCore/LoadingTestCollector.cs
@@ -1,71 +1,54 @@
-namespace NUnit.Runner {
+namespace NUnit.Runner
+{
+ using System;
+ using System.Reflection;
+ using NUnit.Framework;
- using System;
- using System.Reflection;
-
- using NUnit.Framework;
-
- /// <summary>
- /// An implementation of a TestCollector that loads
- /// all classes on the class path and tests whether
- /// it is assignable from ITest or provides a static Suite property.
- /// <see cref="ITestCollector"/>
- /// </summary>
- public class LoadingClassPathTestCollector: ClassPathTestCollector {
-
- TestCaseClassLoader fLoader;
/// <summary>
- ///
+ /// An implementation of a TestCollector that loads
+ /// all classes on the class path and tests whether
+ /// it is assignable from ITest or provides a static Suite property.
+ /// <see cref="ITestCollector"/>
/// </summary>
- public LoadingClassPathTestCollector() {
- fLoader= new TestCaseClassLoader();
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="classFileName"></param>
- /// <returns></returns>
- protected override bool IsTestClass(string classFileName) {
- try {
- if (classFileName.EndsWith(".dll") || classFileName.EndsWith(".exe")) {
- Type testClass= ClassFromFile(classFileName);
- return (testClass != null) && IsTestClass(testClass);
- }
- } catch (TypeLoadException) {
- }
- return false;
- }
-
- Type ClassFromFile(string classFileName) {
- string className= ClassNameFromFile(classFileName);
- if (!fLoader.IsExcluded(className))
- return fLoader.LoadClass(className, false);
- return null;
- }
-
- bool IsTestClass(Type testClass) {
- if (HasSuiteMethod(testClass))
- return true;
- if (typeof(ITest).IsAssignableFrom(testClass) &&
- testClass.IsPublic &&
- HasPublicConstructor(testClass))
- return true;
- return false;
- }
+ [Obsolete("Use StandardLoader or UnloadingLoader")]
+ public class LoadingClassPathTestCollector: ClassPathTestCollector
+ {
- bool HasSuiteMethod(Type testClass) {
- return (testClass.GetProperty(BaseTestRunner.SUITE_PROPERTYNAME, new Type[0]) == null);
- }
+ TestCaseClassLoader fLoader;
+ /// <summary>
+ ///
+ /// </summary>
+ public LoadingClassPathTestCollector()
+ {
+ fLoader= new TestCaseClassLoader();
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="classFileName"></param>
+ /// <returns></returns>
+ protected override bool IsTestClass(string classFileName)
+ {
+ try
+ {
+ if (classFileName.EndsWith(".dll") || classFileName.EndsWith(".exe"))
+ {
+ Type testClass= ClassFromFile(classFileName);
+ return (testClass != null); //HACK: && TestCase.IsTest(testClass);
+ }
+ }
+ catch (TypeLoadException)
+ {
+ }
+ return false;
+ }
- bool HasPublicConstructor(Type testClass) {
- Type[] args= { typeof(string) };
- ConstructorInfo c= null;
- try {
- c= testClass.GetConstructor(args);
- } catch(Exception) {
- return false;
- }
- return true;
- }
- }
+ private Type ClassFromFile(string classFileName)
+ {
+ string className = base.ClassNameFromFile(classFileName);
+ if (!fLoader.IsExcluded(className))
+ return fLoader.LoadClass(className, false);
+ return null;
+ }
+ }
} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/NUnitException.cs b/mcs/nunit/src/NUnitCore/NUnitException.cs
index 155fe741547..f0273ef791f 100644
--- a/mcs/nunit/src/NUnitCore/NUnitException.cs
+++ b/mcs/nunit/src/NUnitCore/NUnitException.cs
@@ -1,24 +1,51 @@
-namespace NUnit.Framework {
-
- using System;
- using System.Diagnostics;
+namespace NUnit.Framework
+{
+ using System;
+ using System.Diagnostics;
+ using System.Runtime.Serialization;
- /// <summary>Thrown when an assertion failed. Here to preserve the inner
- /// exception and hence its stack trace.</summary>
- public class NUnitException: ApplicationException {
- /// <summary>
- ///
- /// </summary>
- /// <param name="message"></param>
- /// <param name="inner"></param>
- public NUnitException(string message, Exception inner) :
- base(message, inner) { }
- /// <summary>
- ///
- /// </summary>
- public bool IsAssertionFailure {
- get { return InnerException.GetType() == typeof(AssertionFailedError); }
- }
- }
-}
+ /// <summary>
+ /// Thrown when an assertion failed. Here to preserve the inner
+ /// exception and hence its stack trace.
+ /// </summary>
+ [Serializable]
+ public class NUnitException : ApplicationException
+ {
+ /// <summary>
+ /// Serialization Constructor
+ /// </summary>
+ protected NUnitException(SerializationInfo info,
+ StreamingContext context) : base(info,context){}
+ /// <summary>
+ /// Standard constructor
+ /// </summary>
+ /// <param name="message">The error message that explains
+ /// the reason for the exception</param>
+ public NUnitException(string message) : base (message){}
+ /// <summary>
+ /// Standard constructor
+ /// </summary>
+ /// <param name="message">The error message that explains
+ /// the reason for the exception</param>
+ /// <param name="inner">The exception that caused the
+ /// current exception</param>
+ public NUnitException(string message, Exception inner) :
+ base(message, inner) {}
+ /// <summary>
+ /// Indicates that this exception wraps an AssertionFailedError
+ /// exception
+ /// </summary>
+ public virtual bool IsAssertionFailure
+ {
+ get
+ {
+ AssertionFailedError inner = this.InnerException
+ as AssertionFailedError;
+ if(inner != null)
+ return true;
+ return false;
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/ReflectionUtils.cs b/mcs/nunit/src/NUnitCore/ReflectionUtils.cs
index 19f656f04c4..491e0e7ec91 100644
--- a/mcs/nunit/src/NUnitCore/ReflectionUtils.cs
+++ b/mcs/nunit/src/NUnitCore/ReflectionUtils.cs
@@ -1,74 +1,94 @@
-namespace NUnit.Runner {
+namespace NUnit.Runner
+{
- using System;
- using System.Collections;
- using System.Collections.Specialized;
- using System.IO;
- using System.Reflection;
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+ using System.IO;
+ using System.Reflection;
- using NUnit.Framework;
-/// <summary>
-///
-/// </summary>
- public class ReflectionUtils{
-/// <summary>
-///
-/// </summary>
-/// <param name="testClass"></param>
-/// <returns></returns>
- public static bool HasTests(Type testClass) {
+ using NUnit.Framework;
+ /// <summary>
+ ///
+ /// </summary>
+ [Obsolete("Use Standar Loader")]
+ public class ReflectionUtils
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="testClass"></param>
+ /// <returns></returns>
+ [Obsolete("Use Standar Loader")]
+ public static bool HasTests(Type testClass)
+ {
- PropertyInfo suiteProperty= null;
- suiteProperty = testClass.GetProperty("Suite", new Type[0]);
- if (suiteProperty == null ) {
- // try to extract a test suite automatically
- bool result = false;
- TestSuite dummy = new TestSuite(testClass, ref result);
- return result;
- }
- ITest test= null;
- try {
- // static property
- test= (ITest)suiteProperty.GetValue(null, new Type[0]);
- if (test == null)
- return false;
- } catch(Exception) {
- return false;
- }
- return true;
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="assemblyName"></param>
-/// <returns></returns>
- public static StringCollection GetAssemblyClasses(string assemblyName){
- StringCollection classNames = new StringCollection ();
- try {
- Assembly testAssembly = Assembly.LoadFrom(assemblyName);
+ PropertyInfo suiteProperty= null;
+ suiteProperty = testClass.GetProperty("Suite", new Type[0]);
+ if (suiteProperty == null )
+ {
+ // try to extract a test suite automatically
+ TestSuite dummy = new TestSuite(testClass, true);
+ return (dummy.CountTestCases > 0);
+ }
+ ITest test= null;
+ try
+ {
+ // static property
+ test= (ITest)suiteProperty.GetValue(null, new Type[0]);
+ if (test == null)
+ return false;
+ }
+ catch(Exception)
+ {
+ return false;
+ }
+ return true;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="assemblyName"></param>
+ /// <returns></returns>
+ [Obsolete("Use Standar Loader")]
+ public static StringCollection GetAssemblyClasses(string assemblyName)
+ {
+ StringCollection classNames = new StringCollection ();
+ try
+ {
+ Assembly testAssembly = Assembly.LoadFrom(assemblyName);
- foreach(Type testType in testAssembly.GetExportedTypes()){
- if(testType.IsClass && HasTests(testType)){
- classNames.Add(testType.FullName);
- }
- }
- }catch(ReflectionTypeLoadException rcle){
+ foreach(Type testType in testAssembly.GetExportedTypes())
+ {
+ if(testType.IsClass && HasTests(testType))
+ {
+ classNames.Add(testType.FullName);
+ }
+ }
+ }
+ catch(ReflectionTypeLoadException rcle)
+ {
- Type[] loadedTypes = rcle.Types;
- Exception[] exceptions = rcle.LoaderExceptions;
+ Type[] loadedTypes = rcle.Types;
+ Exception[] exceptions = rcle.LoaderExceptions;
- int exceptionCount = 0;
+ int exceptionCount = 0;
- for ( int i =0; i < loadedTypes.Length; i++ ){
- Console.Error.WriteLine("Unable to load a type because {0}", exceptions[exceptionCount] );
- exceptionCount++;
- }
- }catch(FileNotFoundException fnfe){
- Console.Error.WriteLine(fnfe.Message);
- }catch(Exception e){
- Console.Error.WriteLine("Error reading file {0}: {1}", assemblyName, e.Message);
- }
- return classNames;
- }
- }
-}
+ for ( int i =0; i < loadedTypes.Length; i++ )
+ {
+ Console.Error.WriteLine("Unable to load a type because {0}", exceptions[exceptionCount] );
+ exceptionCount++;
+ }
+ }
+ catch(FileNotFoundException fnfe)
+ {
+ Console.Error.WriteLine(fnfe.Message);
+ }
+ catch(Exception e)
+ {
+ Console.Error.WriteLine("Error reading file {0}: {1}", assemblyName, e.Message);
+ }
+ return classNames;
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/ReloadingTestSuiteLoader.cs b/mcs/nunit/src/NUnitCore/ReloadingTestSuiteLoader.cs
index 14aaac27b5d..de222ed9d77 100644
--- a/mcs/nunit/src/NUnitCore/ReloadingTestSuiteLoader.cs
+++ b/mcs/nunit/src/NUnitCore/ReloadingTestSuiteLoader.cs
@@ -1,28 +1,33 @@
-namespace NUnit.Runner {
+namespace NUnit.Runner
+{
- using System;
+ using System;
- /// <summary>A TestSuite loader that can reload classes.</summary>
- public class ReloadingTestSuiteLoader: ITestSuiteLoader {
- /// <summary>
- ///
- /// </summary>
- /// <param name="suiteClassName"></param>
- /// <returns></returns>
- public Type Load(string suiteClassName) {
- // TestCaseClassLoader loader= new TestCaseClassLoader();
- // return loader.LoadClass(suiteClassName, true);
- return Type.GetType(suiteClassName, true);
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="aClass"></param>
- /// <returns></returns>
- public Type Reload(Type aClass) {
- // TestCaseClassLoader loader= new TestCaseClassLoader();
- // return loader.LoadClass(aClass.ToString(), true);
- return aClass;
- }
- }
+ /// <summary>A TestSuite loader that can reload classes.</summary>
+ [Obsolete("Use StandardLoader or UnloadingLoader")]
+ public class ReloadingTestSuiteLoader: ITestSuiteLoader
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="suiteClassName"></param>
+ /// <returns></returns>
+ public Type Load(string suiteClassName)
+ {
+ // TestCaseClassLoader loader= new TestCaseClassLoader();
+ // return loader.LoadClass(suiteClassName, true);
+ return Type.GetType(suiteClassName, true);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="aClass"></param>
+ /// <returns></returns>
+ public Type Reload(Type aClass)
+ {
+ // TestCaseClassLoader loader= new TestCaseClassLoader();
+ // return loader.LoadClass(aClass.ToString(), true);
+ return aClass;
+ }
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/StandardTestSuiteLoader.cs b/mcs/nunit/src/NUnitCore/StandardTestSuiteLoader.cs
index 7ea7071e7c6..ebdd9565760 100644
--- a/mcs/nunit/src/NUnitCore/StandardTestSuiteLoader.cs
+++ b/mcs/nunit/src/NUnitCore/StandardTestSuiteLoader.cs
@@ -1,39 +1,47 @@
-namespace NUnit.Runner {
+namespace NUnit.Runner
+{
+ using System;
+ using System.Reflection;
+ using System.IO;
+ using System.Security;
- using System;
- using System.Reflection;
- using System.IO;
- using System.Security;
+ /// <summary>
+ /// The standard test suite loader. It can only load the same
+ /// class once.
+ /// </summary>
+ [Obsolete("Use StandardLoader or UnloadingLoader")]
+ public class StandardTestSuiteLoader: ITestSuiteLoader
+ {
+ /// <summary>
+ /// Loads
+ /// </summary>
+ /// <param name="testClassName"></param>
+ /// <returns></returns>
+ public Type Load(string testClassName)
+ {
+ Type testClass;
+ string[] classSpec=testClassName.Split(',');
+ if (classSpec.Length > 1)
+ {
+ FileInfo dll=new FileInfo(classSpec[1]);
+ if (!dll.Exists)
+ throw new FileNotFoundException("File " + dll.FullName + " not found", dll.FullName);
+ Assembly a = Assembly.LoadFrom(dll.FullName);
+ testClass=a.GetType(classSpec[0], true);
+ }
+ else
+ testClass = Type.GetType(testClassName, true);
+ return testClass;
+ }
- /// <summary>The standard test suite loader. It can only load the same
- /// class once.</summary>
- public class StandardTestSuiteLoader: ITestSuiteLoader {
- /// <summary>
- ///
- /// </summary>
- /// <param name="suiteClassName"></param>
- /// <returns></returns>
- public Type Load(string suiteClassName) {
- Type testClass;
- string[] classSpec=suiteClassName.Split(',');
- if (classSpec.Length > 1) {
- FileInfo dll=new FileInfo(classSpec[1]);
- if (!dll.Exists)
- throw new FileNotFoundException("File " + dll.FullName + " not found", dll.FullName);
- Assembly a = Assembly.LoadFrom(dll.FullName);
- testClass=a.GetType(classSpec[0], true);
- }
- else
- testClass = Type.GetType(suiteClassName, true);
- return testClass;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="aClass"></param>
- /// <returns></returns>
- public Type Reload(Type aClass) {
- return aClass;
- }
- }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="aClass"></param>
+ /// <returns></returns>
+ public Type Reload(Type aClass)
+ {
+ return aClass;
+ }
+ }
} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/TestCase.cs b/mcs/nunit/src/NUnitCore/TestCase.cs
index 45f54d6d0bb..e2e746394bf 100644
--- a/mcs/nunit/src/NUnitCore/TestCase.cs
+++ b/mcs/nunit/src/NUnitCore/TestCase.cs
@@ -1,196 +1,241 @@
-namespace NUnit.Framework {
-
- using System;
- using System.Reflection;
- /// <summary>A test case defines the fixture to run multiple Tests.</summary>
- /// <remarks> To define a test case
- /// <list type="number">
- /// <item><description>implement a subclass of TestCase</description></item>
- /// <item><description>define instance variables that store the state
- /// of the fixture</description></item>
- /// <item><description>initialize the fixture state by overriding
- /// <c>SetUp</c></description></item>
- /// <item><description>clean-up after a test by overriding
- /// <c>TearDown</c></description></item>
- /// </list>
- /// Each test runs in its own fixture so there
- /// can be no side effects among test runs.
- /// <example>Here is an example:
- /// <code>
- /// public class MathTest: TestCase {
- /// protected double fValue1;
- /// protected double fValue2;
- ///
- /// public MathTest(string name) : base(name) {}
- ///
- /// protected override void SetUp() {
- /// fValue1= 2.0;
- /// fValue2= 3.0;
- /// }
- /// }
- /// </code></example>
- ///
- /// For each test implement a method which interacts
- /// with the fixture. Verify the expected results with Assertions specified
- /// by calling <c>Assert</c> with a bool.
- /// <code>
- /// protected void TestAdd() {
- /// double result= fValue1 + fValue2;
- /// Assert(result == 5.0);
- /// }
- /// </code>
- /// Once the methods are defined you can run them. The framework supports
- /// both a static type safe and more dynamic way to run a test.
- /// In the static way you override the runTest method and define the method
- /// to be invoked.
- /// <code>
- /// protected class AddMathTest: TestCase {
- /// public void AddMathTest(string name) : base(name) {}
- /// protected override void RunTest() { TestAdd(); }
- /// }
- ///
- /// test test= new AddMathTest("Add");
- /// test.Run();
- /// </code>
- /// The dynamic way uses reflection to implement <c>RunTest</c>. It
- /// dynamically finds and invokes a method. In this case the name of the
- /// test case has to correspond to the test method to be run.
- /// <code>
- /// test= new MathTest("TestAdd");
- /// test.Run();
- /// </code>
- /// The Tests to be run can be collected into a <see cref="TestSuite"/>.
- /// NUnit provides different test runners which can run a test suite
- /// and collect the results.
- /// A test runner either expects a static property <c>Suite</c> as the entry
- /// point to get a test to run or it will extract the suite automatically.
- /// <code>
- /// public static ITest Suite {
- /// get {
- /// suite.AddTest(new MathTest("TestAdd"));
- /// suite.AddTest(new MathTest("TestDivideByZero"));
- /// return suite;
- /// }
- /// }
- /// </code></remarks>
- /// <seealso cref="TestResult"/>
- /// <seealso cref="TestSuite"/>
- public abstract class TestCase: Assertion, ITest {
-
- /// <summary>the name of the test case.</summary>
- private readonly string name;
-
- /// <summary>Constructs a test case with the given name.</summary>
- public TestCase(string TestName) {
- name = TestName;
- }
-
- /// <value>Counts the number of test cases executed by
- /// Run(TestResult result).</value>
- public int CountTestCases {
- get { return 1; }
- }
-
- /// <summary>Creates a default <see cref="TestResult"/> object.</summary>
- protected TestResult CreateResult() {
- return new TestResult();
- }
-
- /// <value>The name of the test case.</value>
- public string Name {
- get { return name; }
- }
-
- /// <summary>A convenience method to run this test, collecting the
- /// results with a default <see cref="TestResult"/> object.</summary>
- public TestResult Run() {
- TestResult result= CreateResult();
- Run(result);
- return result;
- }
-
- /// <summary>Runs the test case and collects the results in
- /// TestResult.</summary>
- public void Run(TestResult result) {
- result.Run(this);
- }
-
- /// <summary>Runs the bare test sequence.</summary>
- public void RunBare() {
- SetUp();
- try {
- RunTest();
- }
- finally {
- TearDown();
- }
- }
-
- /// <summary>Override to run the test and Assert its state.</summary>
- protected virtual void RunTest() {
- MethodInfo runMethod= GetType().GetMethod(name, new Type[0]);
- if (runMethod == null)
- Fail("Method \""+name+"\" not found");
+namespace NUnit.Framework
+{
+ using System;
+ using System.Reflection;
+
+ /// <summary>A test case defines the fixture to run multiple Tests.</summary>
+ /// <remarks> To define a test case
+ /// <list type="number">
+ /// <item><description>implement a subclass of TestCase</description></item>
+ /// <item><description>define instance variables that store the state
+ /// of the fixture</description></item>
+ /// <item><description>initialize the fixture state by overriding
+ /// <c>SetUp</c></description></item>
+ /// <item><description>clean-up after a test by overriding
+ /// <c>TearDown</c></description></item>
+ /// </list>
+ /// Each test runs in its own fixture so there can be no side effects
+ /// among test runs.
+ /// <example>Here is an example:
+ /// <code>
+ /// public class MathTest: TestCase {
+ /// protected double fValue1;
+ /// protected double fValue2;
+ ///
+ /// public MathTest(string name) : base(name) {}
+ ///
+ /// protected override void SetUp() {
+ /// fValue1= 2.0;
+ /// fValue2= 3.0;
+ /// }
+ /// }</code>
+ /// </example>
+ ///
+ /// For each test implement a method which interacts with the fixture.
+ /// Verify the expected results with Assertions specified by calling
+ /// <c>Assert</c> with a bool.
+ /// <code>
+ /// protected void TestAdd() {
+ /// double result= fValue1 + fValue2;
+ /// Assert(result == 5.0);
+ /// }
+ /// </code>
+ /// Once the methods are defined you can run them. The framework supports
+ /// both a static type safe and more dynamic way to run a test.
+ /// In the static way you override the runTest method and define the method
+ /// to be invoked.
+ /// <code>
+ /// protected class AddMathTest: TestCase {
+ /// public void AddMathTest(string name) : base(name) {}
+ /// protected override void RunTest() { TestAdd(); }
+ /// }
+ ///
+ /// test test= new AddMathTest("Add");
+ /// test.Run();
+ /// </code>
+ /// The dynamic way uses reflection to implement <c>RunTest</c>. It
+ /// dynamically finds and invokes a method. In this case the name of the
+ /// test case has to correspond to the test method to be run.
+ /// <code>
+ /// test= new MathTest("TestAdd");
+ /// test.Run();
+ /// </code>
+ /// The Tests to be run can be collected into a <see cref="TestSuite"/>.
+ /// NUnit provides different test runners which can run a test suite
+ /// and collect the results.
+ /// A test runner either expects a static property <c>Suite</c> as the entry
+ /// point to get a test to run or it will extract the suite automatically.
+ /// <code>
+ /// public static ITest Suite {
+ /// get {
+ /// suite.AddTest(new MathTest("TestAdd"));
+ /// suite.AddTest(new MathTest("TestDivideByZero"));
+ /// return suite;
+ /// }
+ /// }
+ /// </code></remarks>
+ /// <seealso cref="TestResult"/>
+ /// <seealso cref="TestSuite"/>
+ public abstract class TestCase: Assertion, ITest
+ {
+ #region Instance Variables
+ /// <summary>the name of the test case.</summary>
+ private readonly string fName;
+ #endregion
+
+ #region Constructors
+ /// <summary>Constructs a test case with no name.</summary>
+ public TestCase() : this(String.Empty){}
+
+ /// <summary>Constructs a test case with the given name.</summary>
+ public TestCase(string testName)
+ {
+ this.fName = testName;
+ }
+ #endregion
+
+ #region Properties
+ /// <value>Counts the number of test cases executed by
+ /// Run(TestResult result).</value>
+ public int CountTestCases
+ {
+ get { return 1; }
+ }
+
+ /// <value>The name of the test case.</value>
+ public string Name
+ {
+ get { return this.fName; }
+ }
+ #endregion
+
+ #region Utility Methods
+ /// <summary>Creates a default <see cref="TestResult"/> object.</summary>
+ protected TestResult CreateResult()
+ {
+ return new TestResult();
+ }
+ #endregion
+
+ #region Run Methods
+ /// <summary>A convenience method to run this test, collecting the
+ /// results with a default <see cref="TestResult"/> object.</summary>
+ public TestResult Run()
+ {
+ TestResult result = this.CreateResult();
+ this.Run(result);
+ return result;
+ }
+
+ /// <summary>Runs the test case and collects the results in
+ /// TestResult.</summary>
+ public void Run(TestResult result)
+ {
+ result.Run(this);
+ }
+
+ /// <summary>Runs the bare test sequence.</summary>
+ public void RunBare()
+ {
+ this.SetUp();
+ try
+ {
+ this.RunTest();
+ }
+ finally
+ {
+ this.TearDown();
+ }
+ }
+
+ /// <summary>Override to run the test and Assert its state.</summary>
+ protected virtual void RunTest()
+ {
+ MethodInfo runMethod = GetType().GetMethod(this.Name, new Type[0]);
+ if (runMethod == null)
+ Assertion.Fail("Method \""+this.Name+"\" not found");
- if (runMethod != null && !runMethod.IsPublic) {
- Fail("Method \""+name+"\" should be public");
- }
+ if (runMethod != null && !runMethod.IsPublic)
+ {
+ Assertion.Fail("Method \""+this.Name+"\" should be public");
+ }
object[] exa =
- runMethod.GetCustomAttributes(typeof(ExpectExceptionAttribute),true);
-
- try {
- runMethod.Invoke(this, null);
- }
- catch (TargetInvocationException e) {
- Exception i = e.InnerException;
- if (i is AssertionFailedError) {
- throw new NUnitException("", i);
- }
+ runMethod.GetCustomAttributes(typeof(ExpectExceptionAttribute),true);
- if (exa.Length > 0) {
- foreach (ExpectExceptionAttribute ex in exa) {
- if (ex.ExceptionExpected.IsAssignableFrom(i.GetType()))
- return;
- }
- Fail("Wrong exception: " + i);
- } else
- throw new NUnitException("", i);
- }
- catch (MemberAccessException e)
+ try
+ {
+ runMethod.Invoke(this, null);
+ }
+ catch (AssertionFailedError e)
+ {
+ throw new NUnitException("Run Error: ", e);
+ }
+ catch (TargetInvocationException e)
+ {
+ Exception inner = e.InnerException;
+ if (inner is AssertionFailedError)
+ {
+ throw new NUnitException("Run Error: ", inner);
+ }
+ if (exa.Length>0)
+ {
+ foreach (ExpectExceptionAttribute ex in exa)
+ {
+ if (ex.ExceptionExpected.IsAssignableFrom(inner.GetType()))
+ return;
+ }
+ Assertion.Fail("Unexpected Exception thrown: " + inner);
+ }
+ else
+ {
+ throw new NUnitException("Run Error: ", inner);
+ }
+ }
+ catch (MemberAccessException e)
{
throw new NUnitException("", e);
}
- if (exa.Length > 0) {
- System.Text.StringBuilder sb =
- new System.Text.StringBuilder
- ("One of these exceptions should have been thrown: ");
- bool first = true;
- foreach (ExpectExceptionAttribute ex in exa) {
- if (first)
- first = false;
- else
- sb.Append(", ");
- sb.Append(ex);
- }
- Fail(sb.ToString());
- }
- }
-
- /// <summary>Sets up the fixture, for example, open a network connection.
- /// This method is called before a test is executed.</summary>
- protected virtual void SetUp() {
- }
-
- /// <summary>Tears down the fixture, for example, close a network
- /// connection. This method is called after a test is executed.</summary>
- protected virtual void TearDown() {
- }
-
- /// <summary>Returns a string representation of the test case.</summary>
- public override string ToString() {
- return name+"("+GetType().ToString()+")";
- }
- }
-}
+ if (exa.Length > 0)
+ {
+ System.Text.StringBuilder sb =
+ new System.Text.StringBuilder
+ ("One of these exceptions should have been thrown: ");
+ bool first = true;
+ foreach (ExpectExceptionAttribute ex in exa)
+ {
+ if(first)
+ first = false;
+ else
+ sb.Append(", ");
+ sb.Append(ex);
+ }
+ Assertion.Fail(sb.ToString());
+ }
+ }
+
+ /// <summary>
+ /// Sets up the fixture, for example, open a network connection.
+ /// This method is called before a test is executed.
+ /// </summary>
+ protected virtual void SetUp() {}
+ /// <summary>
+ /// Tears down the fixture, for example, close a network
+ /// connection. This method is called after a test is executed.
+ /// </summary>
+ protected virtual void TearDown() {}
+ #endregion
+
+ #region Overrides
+ /// <summary>
+ /// Returns a string representation of the test case.
+ /// </summary>
+ public override string ToString()
+ {
+ return this.Name+"("+this.GetType().ToString()+")";
+ }
+ #endregion
+
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/TestCaseClassLoader.cs b/mcs/nunit/src/NUnitCore/TestCaseClassLoader.cs
index 52a73b6855e..80fc7e89100 100644
--- a/mcs/nunit/src/NUnitCore/TestCaseClassLoader.cs
+++ b/mcs/nunit/src/NUnitCore/TestCaseClassLoader.cs
@@ -1,37 +1,42 @@
-namespace NUnit.Runner {
- using System;
-/// <summary>
-///
-/// </summary>
- public class TestCaseClassLoader : StandardTestSuiteLoader {
- /// <summary>
- ///
- /// </summary>
- /// <param name="name"></param>
- /// <param name="resolve"></param>
- /// <returns></returns>
- public Type LoadClass(string name, bool resolve) {
- return Load(name);
- }
-/// <summary>
-///
-/// </summary>
-/// <param name="name"></param>
-/// <returns></returns>
- public bool IsExcluded(string name) {
- return false;
- }
- }
+namespace NUnit.Runner
+{
+ using System;
+
+ /// <summary>
+ ///
+ /// </summary>
+ [Obsolete("Use StandardLoader or UnloadingLoader")]
+ public class TestCaseClassLoader : StandardTestSuiteLoader
+ {
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <param name="resolve"></param>
+ /// <returns></returns>
+ public Type LoadClass(string name, bool resolve)
+ {
+ return Load(name);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="name"></param>
+ /// <returns></returns>
+ public bool IsExcluded(string name)
+ {
+ return false;
+ }
+ }
}
#if false
-
// commented out till figure out .net class reloading
namespace NUnit.Runner {
- /**
+ /**
* A custom class loader which enables the reloading
* of classes for each test run. The class loader
* can be configured with a list of package paths that
@@ -200,5 +205,4 @@ namespace NUnit.Runner {
return excluded;
}
}
-
#endif
diff --git a/mcs/nunit/src/NUnitCore/TestDecorator.cs b/mcs/nunit/src/NUnitCore/TestDecorator.cs
index 02753912350..eded1c24ba5 100644
--- a/mcs/nunit/src/NUnitCore/TestDecorator.cs
+++ b/mcs/nunit/src/NUnitCore/TestDecorator.cs
@@ -1,56 +1,71 @@
-namespace NUnit.Extensions {
+namespace NUnit.Extensions
+{
+ using System;
+ using NUnit.Framework;
- using System;
-
- using NUnit.Framework;
-
- /// <summary>A Decorator for Tests.</summary>
- /// <remarks>Use TestDecorator as the base class
- /// for defining new test decorators. TestDecorator subclasses
- /// can be introduced to add behaviour before or after a test
- /// is run.</remarks>
- public class TestDecorator: Assertion, ITest {
- /// <summary>
- ///
- /// </summary>
- protected readonly ITest fTest;
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- public TestDecorator(ITest test) {
- fTest= test;
- }
-
- /// <summary>The basic run behaviour.</summary>
- public void BasicRun(TestResult result) {
- fTest.Run(result);
- }
- /// <summary>
- ///
- /// </summary>
- public virtual int CountTestCases {
- get { return fTest.CountTestCases; }
- }
- /// <summary>
- ///
- /// </summary>
- public ITest GetTest {
- get { return fTest; }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="result"></param>
- public virtual void Run(TestResult result) {
- BasicRun(result);
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public override string ToString() {
- return fTest.ToString();
- }
- }
-}
+ /// <summary>A Decorator for Tests.</summary>
+ /// <remarks>Use TestDecorator as the base class
+ /// for defining new test decorators. TestDecorator subclasses
+ /// can be introduced to add behaviour before or after a test
+ /// is run.</remarks>
+ public class TestDecorator: Assertion, ITest
+ {
+ /// <summary>
+ /// A reference to the test that is being decorated
+ /// </summary>
+ protected readonly ITest fTest;
+ /// <summary>
+ /// Creates a decorator for the supplied test
+ /// </summary>
+ /// <param name="test">The test to be decorated</param>
+ public TestDecorator(ITest test)
+ {
+ if(test!= null)
+ {
+ this.fTest= test;
+ }
+ else
+ throw new ArgumentNullException("test");
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="result"></param>
+ public virtual void Run(TestResult result)
+ {
+ this.BasicRun(result);
+ }
+ /// <summary>The basic run behaviour.</summary>
+ public void BasicRun(TestResult result)
+ {
+ this.fTest.Run(result);
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ public virtual int CountTestCases
+ {
+ get { return fTest.CountTestCases; }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ public ITest GetTest
+ {
+ get { return fTest; }
+ }
+ //public string Name
+ //{
+ // get{return fTest.Name;}
+ //}
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public override string ToString()
+ {
+ return fTest.ToString();
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/TestFailure.cs b/mcs/nunit/src/NUnitCore/TestFailure.cs
index 7d768b494ba..4dad5bd02bd 100644
--- a/mcs/nunit/src/NUnitCore/TestFailure.cs
+++ b/mcs/nunit/src/NUnitCore/TestFailure.cs
@@ -1,44 +1,55 @@
-namespace NUnit.Framework {
-
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Text;
+namespace NUnit.Framework
+{
+ using System;
+ using System.Diagnostics;
+ using System.IO;
+ using System.Text;
- /// <summary>A <c>TestFailure</c> collects a failed test together with
- /// the caught exception.</summary>
- /// <seealso cref="TestResult"/>
- public class TestFailure {
- private readonly ITest failedTest;
- private readonly Exception thrownException;
+ /// <summary>
+ /// A <c>TestFailure</c> collects a failed test together with
+ /// the caught exception.
+ /// </summary>
+ /// <seealso cref="TestResult"/>
+ public class TestFailure : MarshalByRefObject
+ {
+ private readonly ITest fFailedTest;
+ private readonly Exception fThrownException;
- /// <summary>Constructs a TestFailure with the given test and
- /// exception.</summary>
- public TestFailure(ITest theFailedTest, Exception theThrownException) {
- failedTest= theFailedTest;
- thrownException= theThrownException;
- }
+ /// <summary>
+ /// Constructs a TestFailure with the given test and exception.
+ /// </summary>
+ public TestFailure(ITest theFailedTest, Exception theThrownException)
+ {
+ if(theFailedTest==null)
+ throw new ArgumentNullException("theFailedTest");
+ if(theThrownException==null)
+ throw new ArgumentNullException("theThrownException");
+ this.fFailedTest = theFailedTest;
+ this.fThrownException = theThrownException;
+ }
- /// <value>Gets the failed test.</value>
- public ITest FailedTest {
- get { return failedTest; }
- }
+ /// <value>Gets the failed test.</value>
+ public ITest FailedTest
+ {
+ get { return this.fFailedTest; }
+ }
- /// <value>True if it's a failure, false if error.</value>
- public bool IsFailure {
- get { return thrownException is AssertionFailedError; }
- }
+ /// <value>True if it's a failure, false if error.</value>
+ public bool IsFailure
+ {
+ get { return this.fThrownException is AssertionFailedError; }
+ }
- /// <value>Gets the thrown exception.</value>
- public Exception ThrownException {
- get { return thrownException; }
- }
+ /// <value>Gets the thrown exception.</value>
+ public Exception ThrownException
+ {
+ get { return this.fThrownException; }
+ }
- /// <summary>Returns a short description of the failure.</summary>
- public override string ToString() {
- StringBuilder buffer= new StringBuilder();
- buffer.Append(failedTest+": "+thrownException.Message);
- return buffer.ToString();
- }
- }
-}
+ /// <summary>Returns a short description of the failure.</summary>
+ public override string ToString()
+ {
+ return this.fFailedTest + ": " + this.fThrownException.Message;
+ }
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/TestResult.cs b/mcs/nunit/src/NUnitCore/TestResult.cs
index 9b0bfb7590d..ff274a8c4ff 100644
--- a/mcs/nunit/src/NUnitCore/TestResult.cs
+++ b/mcs/nunit/src/NUnitCore/TestResult.cs
@@ -1,181 +1,249 @@
-namespace NUnit.Framework {
-
- using System;
- using System.Collections;
- using System.Threading;
-
- /// <summary>A <c>TestResult</c> collects the results of executing
- /// a test case. It is an instance of the Collecting Parameter pattern.
- /// </summary><remarks>
- /// The test framework distinguishes between failures and errors.
- /// A failure is anticipated and checked for with assertions. Errors are
- /// unanticipated problems like an <c>ArgumentOutOfRangeException</c>.
- /// </remarks><seealso cref="ITest"/>
- public class TestResult {
- private ArrayList fFailures;
- private ArrayList fErrors;
- private ArrayList fListeners;
- private int fRunTests;
- private bool fStop;
- /// <summary>
- ///
- /// </summary>
- public TestResult() {
- fFailures= new ArrayList();
- fErrors= new ArrayList();
- fListeners= new ArrayList();
- }
-
- /// <summary>Adds an error to the list of errors. The passed in exception
- /// caused the error.</summary>
- public void AddError(ITest test, Exception t) {
- lock(this) {
- fErrors.Add(new TestFailure(test, t));
- foreach (ITestListener l in CloneListeners()) {
- l.AddError(test, t);
- }
- }
- }
-
- /// <summary>Adds a failure to the list of failures. The passed in
- /// exception caused the failure.</summary>
- public void AddFailure(ITest test, AssertionFailedError t) {
- lock(this)
- {
- fFailures.Add(new TestFailure(test, t));
- foreach (ITestListener l in CloneListeners()) {
- l.AddFailure(test, t);
- }
- }
- }
-
- /// <summary>Registers a TestListener.</summary>
- public void AddListener(ITestListener listener) {
- lock(this)
- fListeners.Add(listener);
- }
-
- /// <summary>Returns a copy of the listeners.</summary>
- private ArrayList CloneListeners() {
- lock(this)
- return (ArrayList)fListeners.Clone();
- }
-
- /// <summary>Informs the result that a test was completed.</summary>
- public void EndTest(ITest test) {
- foreach (ITestListener l in CloneListeners()) {
- l.EndTest(test);
- }
- }
-
- /// <value>Gets the number of detected errors.</value>
- public int ErrorCount {
- get {return fErrors.Count; }
- }
-
- /// <value>Returns an IEnumerable for the errors.</value>
- public IEnumerable Errors {
- get { return fErrors; }
- }
-
- /// <value>Gets the number of detected failures.</value>
- public int FailureCount {
- get {return fFailures.Count; }
- }
-
- /// <value>Returns an IEnumerable for the failures.</value>
- public IEnumerable Failures {
- get { return fFailures; }
- }
-
- /// <summary>Runs a TestCase.</summary>
- protected class ProtectedProtect: IProtectable {
- private TestCase fTest;
+namespace NUnit.Framework
+{
+ using System;
+ using System.Collections;
+ using System.Threading;
+
+ /// <summary>A <c>TestResult</c> collects the results of executing
+ /// a test case. It is an instance of the Collecting Parameter pattern.
+ /// </summary><remarks>
+ /// The test framework distinguishes between failures and errors.
+ /// A failure is anticipated and checked for with assertions. Errors are
+ /// unanticipated problems like an <c>ArgumentOutOfRangeException</c>.
+ /// </remarks><seealso cref="ITest"/>
+ public class TestResult : MarshalByRefObject
+ {
+ #region Instance Variables
+ private ArrayList fFailures;
+ private ArrayList fErrors;
+ private ArrayList fListeners;
+ private int fRunTests;
+ private bool fStop;
+ #endregion
+
+ #region Constructors
/// <summary>
///
/// </summary>
- /// <param name="test"></param>
- public ProtectedProtect(TestCase test) {
- fTest = test;
- }
+ public TestResult()
+ {
+ fFailures= new ArrayList();
+ fErrors= new ArrayList();
+ fListeners= new ArrayList();
+ }
+ #endregion
+
+ #region Collection Methods
/// <summary>
- ///
+ /// Adds an error to the list of errors. The passed in exception
+ /// caused the error.
/// </summary>
- public void Protect() {
- fTest.RunBare();
- }
- }
-
- /// <summary>Unregisters a TestListener</summary>
- public void RemoveListener(ITestListener listener) {
- lock(this) {
- fListeners.Remove(listener);
- }
- }
-
- /// <summary>Runs a TestCase.</summary>
- internal void Run(TestCase test) {
- StartTest(test);
- IProtectable p = new ProtectedProtect(test);
- RunProtected(test, p);
-
- EndTest(test);
- }
-
- /// <value>Gets the number of run tests.</value>
- public int RunCount {
- get {return fRunTests; }
- }
-
- /// <summary>Runs a TestCase.</summary>
- public void RunProtected(ITest test, IProtectable p) {
- try {
- p.Protect();
- }
- catch (NUnitException e) {
- if (e.IsAssertionFailure)
- AddFailure(test, (AssertionFailedError)e.InnerException);
- else
- AddError(test, e.InnerException);
- }
- catch (ThreadAbortException e) { // don't catch by accident
- throw e;
- }
- catch (AssertionFailedError e) {
- AddFailure(test, e);
- }
- catch (System.Exception e) {
- AddError(test, e);
- }
- }
-
- /// <summary>Checks whether the test run should stop.</summary>
- public bool ShouldStop {
- get {return fStop; }
- }
-
- /// <summary>Informs the result that a test will be started.</summary>
- public void StartTest(ITest test) {
- int count = test.CountTestCases;
- lock(this)
- fRunTests += count;
- foreach (ITestListener l in CloneListeners()) {
- l.StartTest(test);
- }
- }
-
- /// <summary>Marks that the test run should stop.</summary>
- public void Stop() {
- fStop= true;
- }
-
- /// <value>Returns whether the entire test was successful or not.</value>
- public bool WasSuccessful {
- get {
- lock(this)
- return (FailureCount == 0) && (ErrorCount == 0);
- }
- }
- }
-}
-
+ public void AddError(ITest test, Exception error)
+ {
+ lock(this)
+ {
+ this.fErrors.Add(new TestFailure(test, error));
+ foreach (ITestListener listner in CloneListeners())
+ {
+ listner.AddError(test, error);
+ }
+ }
+ }
+ /// <summary>
+ /// Adds a failure to the list of failures. The passed in
+ /// exception caused the failure.
+ /// </summary>
+ public void AddFailure(ITest test, AssertionFailedError failure)
+ {
+ lock(this)
+ {
+ fFailures.Add(new TestFailure(test, failure));
+ foreach (ITestListener listner in CloneListeners())
+ {
+ listner.AddFailure(test, failure);
+ }
+ }
+ }
+ #endregion
+
+ #region Events
+ /// <summary>Registers a TestListener.</summary>
+ public void AddListener(ITestListener listener)
+ {
+ lock(this)
+ this.fListeners.Add(listener);
+ }
+ /// <summary>Unregisters a TestListener</summary>
+ public void RemoveListener(ITestListener listener)
+ {
+ lock(this)
+ {
+ fListeners.Remove(listener);
+ }
+ }
+ /// <summary>Returns a copy of the listeners.</summary>
+ private ArrayList CloneListeners()
+ {
+ lock(this)
+ {
+ return (ArrayList)fListeners.Clone();
+ }
+ }
+ /// <summary>Informs the result that a test was completed.</summary>
+ public void EndTest(ITest test)
+ {
+ foreach (ITestListener listner in CloneListeners())
+ {
+ listner.EndTest(test);
+ }
+ }
+ /// <summary>Informs the result that a test will be started.</summary>
+ public void StartTest(ITest test)
+ {
+ lock(this)
+ {
+ this.fRunTests += test.CountTestCases;
+ }
+ foreach (ITestListener listner in CloneListeners())
+ {
+ listner.StartTest(test);
+ }
+ }
+ #endregion
+
+ #region Properties
+ /// <value>Gets the number of run tests.</value>
+ public int RunCount
+ {
+ get {lock(this)return this.fRunTests; }
+ }
+ /// <value>Gets the number of detected errors.</value>
+ public int ErrorCount
+ {
+ get {lock(this)return this.fErrors.Count; }
+ }
+ /// <value>Gets the number of detected failures.</value>
+ public int FailureCount
+ {
+ get {lock(this)return this.fFailures.Count; }
+ }
+ /// <summary>Checks whether the test run should stop.</summary>
+ public bool ShouldStop
+ {
+ get {lock(this)return this.fStop; }
+ }
+ /// <value>Returns whether the entire test was successful or not.</value>
+ public bool WasSuccessful
+ {
+ get
+ {
+ lock(this)
+ {
+ return (this.FailureCount == 0)
+ && (this.ErrorCount == 0);
+ }
+ }
+ }
+ /// <value>Returns a TestFailure[] for the errors.</value>
+ public TestFailure[] Errors
+ {
+ get
+ {
+ lock(this)
+ {
+ TestFailure[] retVal = new TestFailure[this.fErrors.Count];
+ this.fErrors.CopyTo(retVal);
+ return retVal;
+ }
+ }
+ }
+ /// <value>Returns a TestFauiler[] for the failures.</value>
+ public TestFailure[] Failures
+ {
+ get
+ {
+ lock(this)
+ {
+ TestFailure[] retVal = new TestFailure[this.fFailures.Count];
+ this.fFailures.CopyTo(retVal);
+ return retVal;
+ }
+ }
+ }
+ #endregion
+
+ #region Nested Classes
+ /// <summary>Runs a TestCase.</summary>
+ protected class ProtectedProtect: IProtectable
+ {
+ private TestCase fTest;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ public ProtectedProtect(TestCase test)
+ {
+ if(test != null)
+ {
+ this.fTest = test;
+ }
+ else
+ {
+ throw new ArgumentNullException("test");
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ public void Protect()
+ {
+ this.fTest.RunBare();
+ }
+ }
+ #endregion
+
+ #region Run Methods
+ /// <summary>Runs a TestCase.</summary>
+ internal void Run(TestCase test)
+ {
+ StartTest(test);
+ IProtectable p = new ProtectedProtect(test);
+ RunProtected(test, p);
+ EndTest(test);
+ }
+
+ /// <summary>Runs a TestCase.</summary>
+ public void RunProtected(ITest test, IProtectable p)
+ {
+ try
+ {
+ p.Protect();
+ }
+ catch (AssertionFailedError e)
+ {
+ AddFailure(test, e);
+ }
+ catch (NUnitException e)
+ {
+ if (e.IsAssertionFailure)
+ AddFailure(test, (AssertionFailedError)e.InnerException);
+ else
+ AddError(test, e.InnerException);
+ }
+ catch (ThreadAbortException e)
+ { // don't catch by accident
+ throw e;
+ }
+ catch (System.Exception e)
+ {
+ AddError(test, e);
+ }
+ }
+ /// <summary>Marks that the test run should stop.</summary>
+ public void Stop()
+ {
+ fStop= true;
+ }
+ #endregion
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/TestSetup.cs b/mcs/nunit/src/NUnitCore/TestSetup.cs
index fb360a60351..95823504015 100644
--- a/mcs/nunit/src/NUnitCore/TestSetup.cs
+++ b/mcs/nunit/src/NUnitCore/TestSetup.cs
@@ -1,58 +1,70 @@
-namespace NUnit.Extensions {
+namespace NUnit.Extensions
+{
+ using System;
+ using NUnit.Framework;
+
+ /// <summary>A Decorator to set up and tear down additional fixture state.
+ /// </summary><remarks>
+ /// Subclass TestSetup and insert it into your tests when you want
+ /// to set up additional state once before the tests are run.</remarks>
+ public class TestSetup: TestDecorator
+ {
+ #region Constructors
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ public TestSetup(ITest test) : base(test) {}
+ #endregion
- using System;
+ #region Nested Classes
+ /// <summary>
+ ///
+ /// </summary>
+ protected class ProtectedProtect: IProtectable
+ {
+ private readonly TestSetup fTestSetup;
+ private readonly TestResult fTestResult;
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="testSetup"></param>
+ /// <param name="testResult"></param>
+ public ProtectedProtect(TestSetup testSetup, TestResult testResult)
+ {
+ if(testSetup == null)
+ throw new ArgumentNullException("testSetup");
+ if(testResult == null)
+ throw new ArgumentNullException("testResult");
+ this.fTestSetup = testSetup;
+ this.fTestResult = testResult;
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ void IProtectable.Protect()
+ {
+ this.fTestSetup.SetUp();
+ this.fTestSetup.BasicRun(fTestResult);
+ this.fTestSetup.TearDown();
+ }
+ }
+ #endregion
- using NUnit.Framework;
-
- /// <summary>A Decorator to set up and tear down additional fixture state.
- /// </summary><remarks>
- /// Subclass TestSetup and insert it into your tests when you want
- /// to set up additional state once before the tests are run.</remarks>
- public class TestSetup: TestDecorator {
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- public TestSetup(ITest test) : base(test) {}
- /// <summary>
- ///
- /// </summary>
- protected class ProtectedProtect: IProtectable {
- private readonly TestSetup fTestSetup;
- private readonly TestResult fTestResult;
- /// <summary>
- ///
- /// </summary>
- /// <param name="testSetup"></param>
- /// <param name="testResult"></param>
- public ProtectedProtect(TestSetup testSetup, TestResult testResult) {
- fTestSetup = testSetup;
- fTestResult = testResult;
- }
- /// <summary>
- ///
- /// </summary>
- public void Protect() {
- fTestSetup.SetUp();
- fTestSetup.BasicRun(fTestResult);
- fTestSetup.TearDown();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="result"></param>
- public override void Run(TestResult result) {
- IProtectable p= new ProtectedProtect(this, result);
- result.RunProtected(this, p);
- }
- /// <summary>Sets up the fixture. Override to set up additional fixture
- /// state.</summary>
- protected virtual void SetUp() {
- }
- /// <summary>Tears down the fixture. Override to tear down the additional
- /// fixture state.</summary>
- protected virtual void TearDown() {
- }
- }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="result"></param>
+ public override void Run(TestResult result)
+ {
+ IProtectable p = new ProtectedProtect(this, result);
+ result.RunProtected(this, p);
+ }
+ /// <summary>Sets up the fixture. Override to set up additional fixture
+ /// state.</summary>
+ protected virtual void SetUp() {}
+ /// <summary>Tears down the fixture. Override to tear down the additional
+ /// fixture state.</summary>
+ protected virtual void TearDown() {}
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/TestSuite.cs b/mcs/nunit/src/NUnitCore/TestSuite.cs
index 558060ee4d1..7febc1150f5 100644
--- a/mcs/nunit/src/NUnitCore/TestSuite.cs
+++ b/mcs/nunit/src/NUnitCore/TestSuite.cs
@@ -1,243 +1,293 @@
-namespace NUnit.Framework {
-
- using System;
- using System.Collections;
- using System.Reflection;
-
- /// <summary>A <c>TestSuite</c> is a <c>Composite</c> of Tests.</summary>
- /// <remarks>It runs a collection of test cases. Here is an example using
- /// the dynamic test definition.
- /// <code>
- /// TestSuite suite= new TestSuite();
- /// suite.AddTest(new MathTest("TestAdd"));
- /// suite.AddTest(new MathTest("TestDivideByZero"));
- /// </code>
- /// Alternatively, a TestSuite can extract the Tests to be run automatically.
- /// To do so you pass the class of your TestCase class to the
- /// TestSuite constructor.
- /// <code>
- /// TestSuite suite= new TestSuite(typeof(MathTest));
- /// </code>
- /// This constructor creates a suite with all the methods
- /// starting with "Test" that take no arguments.</remarks>
- /// <seealso cref="ITest"/>
- public class TestSuite: MarshalByRefObject, ITest {
-
- private ArrayList fTests= new ArrayList(10);
- private string fName;
- private bool fHasWarnings = false;
-
- /// <summary>Constructs an empty TestSuite.</summary>
- public TestSuite() {
- }
-
- /// <summary>Constructs a TestSuite from the given class.</summary>
- /// <remarks>Adds all the methods
- /// starting with "Test" as test cases to the suite.
- /// Parts of this method was written at 2337 meters in the Hüffihütte,
- /// Kanton Uri</remarks>
- public TestSuite(Type theClass) {
- fName= theClass.Name;
- ConstructorInfo constructor = GetConstructor(theClass);
- if (constructor == null) {
- AddTest(Warning("Class "+theClass.Name+" has no public constructor TestCase(String name)"));
- return;
- }
- if (theClass.IsNotPublic) {
- AddTest(Warning("Class "+theClass.Name+" is not public"));
- return;
- }
-
- Type superClass= theClass;
- ArrayList names= new ArrayList();
- while (typeof(ITest).IsAssignableFrom(superClass)) {
- MethodInfo[] methods= superClass.GetMethods(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance);
- for (int i= 0; i < methods.Length; i++) {
- AddTestMethod(methods[i], names, constructor);
- }
- superClass= superClass.BaseType;
- }
- if (fTests.Count == 0)
- AddTest(Warning("No Tests found in "+theClass.ToString()));
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="theClass"></param>
- /// <param name="hasNonWarningTests"></param>
- public TestSuite(Type theClass, ref bool hasNonWarningTests) {
- hasNonWarningTests = false;
- fName= theClass.ToString();
- ConstructorInfo constructor= GetConstructor(theClass);
- if (constructor == null) {
- return;
- }
- if (theClass.IsNotPublic) {
- return;
- }
-
- Type superClass= theClass;
- ArrayList names= new ArrayList();
- while (typeof(ITest).IsAssignableFrom(superClass)) {
- MethodInfo[] methods= superClass.GetMethods(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance);
- for (int i= 0; i < methods.Length; i++) {
- AddTestMethod(methods[i], names, constructor);
- }
- superClass= superClass.BaseType;
- }
- if (fHasWarnings) {
- hasNonWarningTests = false;
- } else {
- hasNonWarningTests = (fTests.Count != 0);
- }
- }
-
- /// <summary>Constructs an empty TestSuite.</summary>
- public TestSuite(string name) {
- fName= name;
- }
-
- /// <summary>Adds a test to the suite.</summary>
- public void AddTest(ITest test) {
- fTests.Add(test);
- }
-
- private void AddTestMethod(MethodInfo m, ArrayList names,
- ConstructorInfo constructor) {
- string name= m.Name;
- if (names.Contains(name))
- return;
- if (IsPublicTestMethod(m)) {
- names.Add(name);
-
- Object[] args= new Object[]{name};
- try {
- AddTest((ITest)constructor.Invoke(args));
- } catch (TypeLoadException e) {
- AddTest(Warning("Cannot instantiate test case: "+name + "( " + e.ToString() + ")"));
- } catch (TargetInvocationException e) {
- AddTest(Warning("Exception in constructor: "+name + "( " + e.ToString() + ")"));
- }
- catch (MemberAccessException e)
- {
- AddTest(Warning("Cannot access test case: "+name + "( " + e.ToString() + ")"));
- }
-
- } else { // almost a test method
- if (IsTestMethod(m))
- AddTest(Warning("test method isn't public: "+m.Name));
- }
- }
-
- /// <summary>Adds the tests from the given class to the suite</summary>
- public void AddTestSuite(Type testClass) {
- AddTest(new TestSuite(testClass));
- }
-
- /// <value>The number of test cases that will be run by this test.</value>
- public int CountTestCases {
- get {
- int count= 0;
- foreach (ITest test in Tests) {
- count += test.CountTestCases;
- }
- return count;
- }
- }
-
- /// <summary>Gets a constructor which takes a single string as
- /// its argument.</summary>
- private ConstructorInfo GetConstructor(Type theClass) {
- Type[] args= { typeof(string) };
- return theClass.GetConstructor(args);
- }
-
- /// <summary>
- /// Returns the name of the suite. Not all test suites have a name
- /// and this method can return null.
- /// </summary>
- public string Name {
- get { return fName; }
- }
-
- private bool IsPublicTestMethod(MethodInfo m) {
- return IsTestMethod(m) && m.IsPublic;
- }
-
- private bool IsTestMethod(MethodInfo m) {
- string name= m.Name;
-
- ParameterInfo[] parameters= m.GetParameters();
- Type returnType= m.ReturnType;
- return parameters.Length == 0 && name.ToLower().StartsWith("test")
- && returnType.Equals(typeof(void));
- }
-
- /// <summary>Runs the Tests and collects their result in a
- /// TestResult.</summary>
- public virtual void Run(TestResult result) {
- foreach (ITest test in Tests) {
- if (result.ShouldStop )
- break;
- RunTest(test, result);
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="test"></param>
- /// <param name="result"></param>
- public virtual void RunTest(ITest test, TestResult result) {
- test.Run(result);
- }
+namespace NUnit.Framework
+{
+ using System;
+ using System.Collections;
+ using System.Collections.Specialized;
+ using System.Reflection;
+
+ /// <summary>A <c>TestSuite</c> is a <c>Composite</c> of Tests.</summary>
+ /// <remarks>It runs a collection of test cases. Here is an example using
+ /// the dynamic test definition.
+ /// <code>
+ /// TestSuite suite= new TestSuite();
+ /// suite.AddTest(new MathTest("TestAdd"));
+ /// suite.AddTest(new MathTest("TestDivideByZero"));
+ /// </code>
+ /// Alternatively, a TestSuite can extract the Tests to be run automatically.
+ /// To do so you pass the class of your TestCase class to the
+ /// TestSuite constructor.
+ /// <code>
+ /// TestSuite suite= new TestSuite(typeof(MathTest));
+ /// </code>
+ /// This constructor creates a suite with all the methods
+ /// starting with "Test" that take no arguments.</remarks>
+ /// <seealso cref="ITest"/>
+ public class TestSuite: MarshalByRefObject, ITest
+ {
+ #region Instance Variables
+ private ArrayList fTests= new ArrayList(10);
+ private string fName;
+ private bool fSupressWarnings = false;
+ private string fDynamicConstructionQualifiedName= string.Empty;
+
+ #endregion
+
+ #region Constructors
+ /// <summary>Constructs an empty TestSuite with a name.</summary>
+ public TestSuite(string name)
+ {
+ if(name==null)
+ this.fName=String.Empty;
+ this.fName = name;
+ }
+
+ /// <summary>Constructs an empty TestSuite with no name.</summary>
+ public TestSuite() : this(String.Empty){}
+
+ /// <summary>Constructs a TestSuite from the given class.</summary>
+ /// <remarks>Adds all the methods starting with "Test" as test cases
+ /// to the suite. Parts of this method was written at 2337 meters in
+ /// the Hüffihütte, Kanton Uri</remarks>
+ /// <param name="theClass"></param>
+ /// <param name="supressWarnings"></param>
+ public TestSuite(Type theClass, bool supressWarnings) :
+ this(theClass.FullName)
+ {
+ this.fSupressWarnings = supressWarnings;
+ //REFACTOR: these checks are also found in AssemblyTestCollector
+ if( theClass.IsClass
+ && (theClass.IsPublic || theClass.IsNestedPublic)
+ && !theClass.IsAbstract
+ && typeof(ITest).IsAssignableFrom(theClass)
+ )
+ {
+ ConstructorInfo FixtureConstructor = GetConstructor(theClass);
+ if(FixtureConstructor != null)
+ {
+ {
+ MethodInfo[] methods = theClass.GetMethods(
+ BindingFlags.Public
+ |BindingFlags.NonPublic
+ |BindingFlags.Instance
+ );
+ foreach (MethodInfo method in methods)
+ {
+ AddTestMethod(method, FixtureConstructor);
+ }
+ if (this.fTests.Count == 0)
+ AddWarning("No Tests found in "+theClass.ToString());
+ }
+ }
+ else
+ {
+ AddWarning("Class "+theClass.Name
+ +" has no public constructor TestCase(String name)");
+ }
+ }
+ else
+ {
+ AddWarning("Type '" + theClass.Name
+ +"' must be a public, not abstract class that"
+ +" implements ITest.");
+ }
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="theClass"></param>
+ public TestSuite(Type theClass) : this(theClass,false){}
+ #endregion
+
+ #region Collection Methods
+ /// <summary>Adds a test to the suite.</summary>
+ public void AddTest(ITest test)
+ {
+ fTests.Add(test);
+ }
- /// <value>The test at the given index.</value>
- /// <remarks>Formerly TestAt(int).</remarks>
- public ITest this[int index] {
- get {return (ITest)fTests[index]; }
- }
+ /// <summary>Adds the tests from the given class to the suite</summary>
+ public void AddTestSuite(Type testClass)
+ {
+ AddTest(new TestSuite(testClass));
+ }
+ #endregion
+
+ #region Dynamic Test Case Creation
+ //private void AddTestMethod(MethodInfo m, StringCollection names,
+ private void AddTestMethod(MethodInfo m,
+ ConstructorInfo constructor)
+ {
+ string name = m.Name;
+ if (IsPublicTestMethod(m))
+ {
+ Object[] args= new Object[]{name};
+ try
+ {
+ AddTest((ITest)constructor.Invoke(args));
+ }
+ catch (TypeLoadException e)
+ {
+ AddWarning("Cannot instantiate test case: "+name + "( " + e.ToString() + ")");
+ }
+ catch (TargetInvocationException e)
+ {
+ AddWarning("Exception in constructor: "+name + "( " + e.ToString() + ")");
+ }
+ catch (MemberAccessException e)
+ {
+ AddWarning("Cannot access test case: "+name + "( " + e.ToString() + ")");
+ }
+ }
+ else
+ { // almost a test method
+ if (IsTestMethod(m))
+ AddWarning("test method isn't public: "+m.Name);
+ }
+ }
+
+ /// <summary>Gets a constructor which takes a single string as
+ /// its argument.</summary>
+ private ConstructorInfo GetConstructor(Type theClass)
+ {
+ //REFACTOR: these checks are also found in AssemblyTestCollector
+ return theClass.GetConstructor(new Type[]{typeof(string)});
+ }
+
+ private bool IsPublicTestMethod(MethodInfo methodToCheck)
+ {
+ return methodToCheck.IsPublic
+ && IsTestMethod(methodToCheck);
+ }
+
+ private bool IsTestMethod(MethodInfo methodToCheck)
+ {
+ return
+ !methodToCheck.IsAbstract
+ && methodToCheck.GetParameters().Length == 0
+ && methodToCheck.ReturnType.Equals(typeof(void))
+ && methodToCheck.Name.ToLower().StartsWith("test")
+ ;
+ }
+ #endregion
+
+ #region Properties
+ /// <summary>
+ /// Returns the name of the suite. Not all test suites have a name
+ /// and this method can return null.
+ /// </summary>
+ public string Name
+ {
+ get { return this.fName; }
+ }
+
+ /// <summary>
+ /// The number of test cases that will be run by this test.
+ /// </summary>
+ public int CountTestCases
+ {
+ get
+ {
+ int count= 0;
+ foreach (ITest test in this.Tests)
+ {
+ count += test.CountTestCases;
+ }
+ return count;
+ }
+ }
+
+ /// <value>The number of Tests in this suite.</value>
+ public int TestCount
+ {
+ get {return this.fTests.Count; }
+ }
+
+ /// <value>The test at the given index.</value>
+ /// <remarks>Formerly TestAt(int).</remarks>
+ public ITest this[int index]
+ {
+ get {return (ITest)this.fTests[index]; }
+ }
- /// <value>The number of Tests in this suite.</value>
- public int TestCount {
- get {return fTests.Count; }
- }
+ /// <value>The Tests as a Test[].</value>
+ public ITest[] Tests
+ {
+ get {
+ ITest[] ret = new ITest[this.fTests.Count];
+ this.fTests.CopyTo(ret);
+ return ret;
+ }
+ }
+ #endregion
+
+ #region Utility Methods
+ private void AddWarning(string message)
+ {
+ if(!this.fSupressWarnings)
+ AddTest(new WarningFail(message));
+ }
+ #endregion
+
+ #region Run Methods
+ /// <summary>Runs the Tests and collects their result in a
+ /// TestResult.</summary>
+ public virtual void Run(TestResult result)
+ {
+ foreach (ITest test in Tests)
+ {
+ if (result.ShouldStop )
+ break;
+ RunTest(test, result);
+ }
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="test"></param>
+ /// <param name="result"></param>
+ public virtual void RunTest(ITest test, TestResult result)
+ {
+ test.Run(result);
+ }
- /// <value>The Tests as an ArrayList.</value>
- public ArrayList Tests {
- get { return fTests; }
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public override string ToString() {
- if (Name != null)
- return Name;
- return base.ToString();
- }
-
- private ITest Warning(string message) {
- fHasWarnings = true;
- return new WarningFail(message);
- }
-
- /// <summary>Returns a test which will fail and log a warning
- /// message.</summary>
- public class WarningFail: TestCase {
- private string fMessage;
- /// <summary>
- ///
- /// </summary>
- /// <param name="message"></param>
- public WarningFail(string message): base("warning") {
- fMessage = message;
- }
- /// <summary>
- ///
- /// </summary>
- protected override void RunTest() {
- Fail(fMessage);
- }
- }
- }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ #endregion
+
+ #region Overrides
+ public override string ToString()
+ {
+ return this.Name;
+ }
+ #endregion
+
+ #region Nested Classes
+ /// <summary>A test which will fail and log a warning
+ /// message.</summary>
+ public class WarningFail : TestCase
+ {
+ private string fMessage;
+
+ /// <summary>
+ ///
+ /// </summary>
+ /// <param name="message"></param>
+ public WarningFail(string message): base("warning")
+ {
+ this.fMessage = message;
+ }
+
+ /// <summary>
+ ///
+ /// </summary>
+ protected override void RunTest()
+ {
+ Assertion.Fail(fMessage);
+ }
+ }
+ #endregion
+ }
}
diff --git a/mcs/nunit/src/NUnitCore/Version.cs b/mcs/nunit/src/NUnitCore/Version.cs
index 64a5a7a23c2..bc7770df126 100644
--- a/mcs/nunit/src/NUnitCore/Version.cs
+++ b/mcs/nunit/src/NUnitCore/Version.cs
@@ -1,18 +1,23 @@
-namespace NUnit.Runner {
-
+namespace NUnit.Runner
+{
+ using System.Reflection;
/// <summary>
/// This class defines the current version of NUnit
/// </summary>
- public class Version {
- private Version() {
- // don't instantiate
- }
- /// <summary>
- ///
- /// </summary>
- /// <returns></returns>
- public static string id() {
- return "1.10";
- }
- }
+ public class Version
+ {
+ private Version()
+ {
+ // don't instantiate
+ }
+ /// <summary>
+ ///
+ /// </summary>
+ /// <returns></returns>
+ public static string id()
+ {
+ return Assembly.GetExecutingAssembly().GetName().Version.ToString();
+ //return "1.10";
+ }
+ }
}