Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Importing NUnit 1.11.

svn path=/branches/NUNIT/mcs/; revision=2713
  • Loading branch information...
commit 7f0542b133e5f1eee15f337e0263c14406091a7e 1 parent 9f187b5
Martin Baulig authored
Showing with 2,373 additions and 2,021 deletions.
  1. +4 −4 mcs/nunit/src/NUnitConsole/AssemblyInfo.cs
  2. +35 −30 mcs/nunit/src/NUnitConsole/NUnitConsoleMain.cs
  3. +260 −221 mcs/nunit/src/NUnitConsole/TestRunner.cs
  4. +104 −84 mcs/nunit/src/NUnitCore/ActiveTestSuite.cs
  5. +3 −3 mcs/nunit/src/NUnitCore/AssemblyInfo.cs
  6. +180 −200 mcs/nunit/src/NUnitCore/Assertion.cs
  7. +26 −12 mcs/nunit/src/NUnitCore/AssertionFailedError.cs
  8. +314 −270 mcs/nunit/src/NUnitCore/BaseTestRunner.cs
  9. +17 −15 mcs/nunit/src/NUnitCore/ClassPathTestCollector.cs
  10. +50 −48 mcs/nunit/src/NUnitCore/ExceptionTestCase.cs
  11. +12 −11 mcs/nunit/src/NUnitCore/IProtectable.cs
  12. +17 −13 mcs/nunit/src/NUnitCore/ITest.cs
  13. +15 −14 mcs/nunit/src/NUnitCore/ITestCollector.cs
  14. +61 −74 mcs/nunit/src/NUnitCore/ITestListener.cs
  15. +15 −15 mcs/nunit/src/NUnitCore/ITestSuiteLoader.cs
  16. +48 −65 mcs/nunit/src/NUnitCore/LoadingTestCollector.cs
  17. +49 −22 mcs/nunit/src/NUnitCore/NUnitException.cs
  18. +87 −67 mcs/nunit/src/NUnitCore/ReflectionUtils.cs
  19. +30 −25 mcs/nunit/src/NUnitCore/ReloadingTestSuiteLoader.cs
  20. +44 −36 mcs/nunit/src/NUnitCore/StandardTestSuiteLoader.cs
  21. +233 −188 mcs/nunit/src/NUnitCore/TestCase.cs
  22. +31 −27 mcs/nunit/src/NUnitCore/TestCaseClassLoader.cs
  23. +70 −55 mcs/nunit/src/NUnitCore/TestDecorator.cs
  24. +49 −38 mcs/nunit/src/NUnitCore/TestFailure.cs
  25. +244 −176 mcs/nunit/src/NUnitCore/TestResult.cs
  26. +67 −55 mcs/nunit/src/NUnitCore/TestSetup.cs
  27. +289 −239 mcs/nunit/src/NUnitCore/TestSuite.cs
  28. +19 −14 mcs/nunit/src/NUnitCore/Version.cs
View
8 mcs/nunit/src/NUnitConsole/AssemblyInfo.cs
@@ -30,7 +30,7 @@
// 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 @@
// (*) 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("")]
View
65 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);
+ }
+ }
+ }
+}
View
481 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; }
+ }
+ }
}
View
188 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
+ }
}
View
6 mcs/nunit/src/NUnitCore/AssemblyInfo.cs
@@ -30,7 +30,7 @@
// 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 @@
// documentation for more information on this.
//
[assembly: AssemblyDelaySign(false)]
-//[assembly: AssemblyKeyFile(@"..\..\..\..\NUnit.key")]
-[assembly: AssemblyKeyName("")]
+[assembly: AssemblyKeyFile(@"..\..\..\..\NUnit.key")]
+[assembly: AssemblyKeyName("")]
View
380 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");
+ }
+ }
+}
View
38 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;}
+// }
+ }
+}
View
584 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;
+ }
+ }
}
View
32 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 @@ protected string ClassNameFromFile(string classFileName)
{
return classFileName;
}
- void CollectFilesInRoots(string[] roots, Hashtable result)
+
+ private void CollectFilesInRoots(string[] roots, IList result)
{
foreach (string directory in roots)
{
@@ -55,7 +56,7 @@ void CollectFilesInRoots(string[] roots, Hashtable result)
if (IsTestClass(file))
{
string className=ClassNameFromFile(file);
- result.Add(className, className);
+ result.Add(className);
}
}
}
@@ -69,8 +70,9 @@ void CollectFilesInRoots(string[] roots, Hashtable result)
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;
}
}
}
View
98 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);
+ }
+ }
}
View
23 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();
+ }
+}
View
30 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);
+ }
}
View
29 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();
+ }
}
View
135 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
+}
View
30 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);
+ }
}
View
113 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 fals