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:18 +0300
committerMartin Baulig <martin@novell.com>2002-02-27 12:38:18 +0300
commit5755971d0063ee3ab6278448f026367495a8aa3c (patch)
treea2a9a3434428793fcfc5b31f26b0ed7cb5070c29 /mcs/nunit/src
parente0e69047e9f20f9a85217f92c45e3b640e6ed81d (diff)
Initial revision
svn path=/trunk/mcs/; revision=2711
Diffstat (limited to 'mcs/nunit/src')
-rwxr-xr-xmcs/nunit/src/NUnitConsole/NUnitConsole.csproj93
-rwxr-xr-xmcs/nunit/src/NUnitCore/AssemblyTestCollector.cs72
-rwxr-xr-xmcs/nunit/src/NUnitCore/ITestLoader.cs58
-rwxr-xr-xmcs/nunit/src/NUnitCore/NUnitCore.csproj238
-rwxr-xr-xmcs/nunit/src/NUnitCore/StandardLoader.cs222
5 files changed, 683 insertions, 0 deletions
diff --git a/mcs/nunit/src/NUnitConsole/NUnitConsole.csproj b/mcs/nunit/src/NUnitConsole/NUnitConsole.csproj
new file mode 100755
index 00000000000..c7376873b47
--- /dev/null
+++ b/mcs/nunit/src/NUnitConsole/NUnitConsole.csproj
@@ -0,0 +1,93 @@
+<VisualStudioProject>
+ <CSHARP
+ ProjectType = "Local"
+ ProductVersion = "7.0.9254"
+ SchemaVersion = "1.0"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = "Logo.ico"
+ AssemblyKeyContainerName = ""
+ AssemblyName = "NUnitConsole"
+ AssemblyOriginatorKeyFile = ""
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Flow"
+ DefaultTargetSchema = "IE32Nav30"
+ DelaySign = "false"
+ NoStandardLibraries = "false"
+ OutputType = "Exe"
+ RootNamespace = "NUnitConsole"
+ StartupObject = ""
+ >
+ <Config
+ Name = "Debug"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "0"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "DEBUG;TRACE"
+ DocumentationFile = "NUnitConsole.xml"
+ DebugSymbols = "true"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ Optimize = "false"
+ OutputPath = "bin\Debug\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ <Config
+ Name = "Release"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "0"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "TRACE"
+ DocumentationFile = ""
+ DebugSymbols = "false"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ Optimize = "true"
+ OutputPath = "bin\Release\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "NUnitCore"
+ Project = "{434945C6-B4F0-416B-AC43-2631EA091AAA}"
+ Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
+ Private = "True"
+ />
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ />
+ </References>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "AssemblyInfo.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NUnitConsoleMain.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestRunner.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ </Include>
+ </Files>
+ </CSHARP>
+</VisualStudioProject>
+
diff --git a/mcs/nunit/src/NUnitCore/AssemblyTestCollector.cs b/mcs/nunit/src/NUnitCore/AssemblyTestCollector.cs
new file mode 100755
index 00000000000..9c707c43e33
--- /dev/null
+++ b/mcs/nunit/src/NUnitCore/AssemblyTestCollector.cs
@@ -0,0 +1,72 @@
+using System;
+using NUnit.Framework;
+
+namespace NUnit.Runner
+{
+ /// <summary>
+ /// Collects the names of all classes in an assembly that are tests.
+ /// </summary>
+ public sealed class AssemblyTestCollector : MarshalByRefObject, ITestCollector
+ {
+ #region Instance Variables
+ private string fAssemblyName;
+ private StandardLoader fLoader;
+ #endregion
+
+ #region Constructors
+ /// <summary>
+ /// Create a new AssemblyTestCollector for the specified
+ /// assembly, and uses the supplied loader to load the tests
+ /// from the assembly.
+ /// </summary>
+ /// <param name="assemblyName">The file name of the assembly
+ /// from which to load classes</param>
+ /// <param name="loader">An instance if the standard loader to
+ /// use for loading tests from the assembly.</param>
+ public AssemblyTestCollector(string assemblyName,
+ StandardLoader loader)
+ {
+ if(loader!=null)
+ fLoader = loader;
+ else
+ throw new ArgumentNullException("loader");
+
+ if(assemblyName != null)
+ {
+ fAssemblyName = assemblyName;
+ }
+ else
+ throw new ArgumentNullException("assemblyName");
+
+ }
+ /// <summary>
+ /// Create a new AssemblyTestCollector for the specified
+ /// assembly.
+ /// </summary>
+ /// <param name="assemblyName">The file name of the assembly
+ /// from which to load classes.</param>
+ public AssemblyTestCollector(string assemblyName)
+ : this(assemblyName,new StandardLoader()){}
+ /// <summary>
+ /// returns a System.String[] of FullNames for all test classes
+ /// contained within the assembly.
+ /// Implements ITestCollector.CollectTestsClassNames()
+ /// </summary>
+ #endregion
+
+ #region ITestCollector Methods
+ public string[] CollectTestsClassNames()
+ {
+ Type[] tests = fLoader.GetTestTypes(fAssemblyName);
+ string[] ret = new string[tests.Length];
+ int i=0;
+ foreach (Type testType in tests)
+ {
+ ret[i] = testType.FullName;
+ i++;
+ }
+ return ret;
+ }
+ #endregion
+ }
+}
diff --git a/mcs/nunit/src/NUnitCore/ITestLoader.cs b/mcs/nunit/src/NUnitCore/ITestLoader.cs
new file mode 100755
index 00000000000..ed0a08ed73c
--- /dev/null
+++ b/mcs/nunit/src/NUnitCore/ITestLoader.cs
@@ -0,0 +1,58 @@
+namespace NUnit.Runner
+{
+ using System;
+ using NUnit.Framework;
+ using System.Runtime.Serialization;
+
+ /// <summary>
+ /// Basic contract governing loading of tests
+ /// </summary>
+ public interface ITestLoader
+ {
+ /// <summary>
+ /// Loads an instance of the test class specified by the name.
+ /// Loadable in most cases will be an assembly qualified name.
+ ///
+ /// Other loaders could dynamically construct a test case from
+ /// an XML file or a database record.
+ /// </summary>
+ ITest LoadTest(string loadableName);
+
+ /// <summary>
+ /// Return the name used by the loader to load an instance
+ /// of the supplied test
+ /// </summary>
+ /// <param name="test"></param>
+ /// <returns></returns>
+ string GetLoadName(ITest test);
+ }
+
+ /// <summary>
+ /// Error thrown during assembly and class loading problems
+ /// </summary>
+ [Serializable]
+ public class LoaderException : NUnitException
+ {
+ /// <summary>
+ /// Serialization Constructor
+ /// </summary>
+ protected LoaderException(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>
+ /// <param name="innerException">The exception that caused the
+ /// current exception</param>
+ public LoaderException(string message, Exception innerException) :
+ base(message, innerException) {}
+ /// <summary>
+ /// Standard constructor
+ /// </summary>
+ /// <param name="message">The error message that explains
+ /// the reason for the exception</param>
+ public LoaderException(string message) :
+ base(message) {}
+ }
+} \ No newline at end of file
diff --git a/mcs/nunit/src/NUnitCore/NUnitCore.csproj b/mcs/nunit/src/NUnitCore/NUnitCore.csproj
new file mode 100755
index 00000000000..e53d5db8fff
--- /dev/null
+++ b/mcs/nunit/src/NUnitCore/NUnitCore.csproj
@@ -0,0 +1,238 @@
+<VisualStudioProject>
+ <CSHARP
+ ProjectType = "Local"
+ ProductVersion = "7.0.9466"
+ SchemaVersion = "1.0"
+ >
+ <Build>
+ <Settings
+ ApplicationIcon = ""
+ AssemblyKeyContainerName = ""
+ AssemblyName = "NUnitCore"
+ AssemblyOriginatorKeyFile = ""
+ DefaultClientScript = "JScript"
+ DefaultHTMLPageLayout = "Flow"
+ DefaultTargetSchema = "IE32Nav30"
+ DelaySign = "false"
+ OutputType = "Library"
+ RootNamespace = "NUnitCore"
+ StartupObject = ""
+ >
+ <Config
+ Name = "Debug"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "0"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "DEBUG;TRACE"
+ DocumentationFile = "NUnitCore.xml"
+ DebugSymbols = "true"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ Optimize = "false"
+ OutputPath = "bin\Debug\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ <Config
+ Name = "Release"
+ AllowUnsafeBlocks = "false"
+ BaseAddress = "0"
+ CheckForOverflowUnderflow = "false"
+ ConfigurationOverrideFile = ""
+ DefineConstants = "TRACE"
+ DocumentationFile = ""
+ DebugSymbols = "false"
+ FileAlignment = "4096"
+ IncrementalBuild = "false"
+ Optimize = "true"
+ OutputPath = "bin\Release\"
+ RegisterForComInterop = "false"
+ RemoveIntegerChecks = "false"
+ TreatWarningsAsErrors = "false"
+ WarningLevel = "4"
+ />
+ </Settings>
+ <References>
+ <Reference
+ Name = "System"
+ AssemblyName = "System"
+ />
+ <Reference
+ Name = "SYSTEM.WINDOWS.FORMS"
+ AssemblyName = "System.Windows.Forms"
+ />
+ <Reference
+ Name = "System.Data"
+ AssemblyName = "System.Data"
+ />
+ <Reference
+ Name = "System.XML"
+ AssemblyName = "System.Xml"
+ />
+ </References>
+ </Build>
+ <Files>
+ <Include>
+ <File
+ RelPath = "ActiveTestSuite.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "AssemblyInfo.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "AssemblyTestCollector.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Assertion.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "AssertionFailedError.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "BaseTestRunner.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ClassPathTestCollector.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ExceptionTestCase.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ExpectExceptionAttribute.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "IFailureDetailView.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "IProtectable.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ITest.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ITestCollector.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ITestListener.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ITestLoader.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ITestSuiteLoader.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "LoadingTestCollector.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "NUnitException.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ReflectionUtils.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "ReloadingTestSuiteLoader.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "RepeatedTest.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "StandardLoader.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "StandardTestSuiteLoader.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestCase.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestCaseClassLoader.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestDecorator.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestFailure.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestResult.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestSetup.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "TestSuite.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ <File
+ RelPath = "Version.cs"
+ SubType = "Code"
+ BuildAction = "Compile"
+ />
+ </Include>
+ </Files>
+ </CSHARP>
+</VisualStudioProject>
+
diff --git a/mcs/nunit/src/NUnitCore/StandardLoader.cs b/mcs/nunit/src/NUnitCore/StandardLoader.cs
new file mode 100755
index 00000000000..5666c56aac3
--- /dev/null
+++ b/mcs/nunit/src/NUnitCore/StandardLoader.cs
@@ -0,0 +1,222 @@
+namespace NUnit.Runner
+{
+ using System;
+ using System.Collections;
+ using System.Reflection;
+ using NUnit.Framework;
+
+ /// <summary>
+ /// Same as StandardLoader.
+ /// TODO: Clean up "Unloading" concepts in framework
+ /// </summary>
+ public class UnloadingLoader : StandardLoader{}
+
+ /// <summary>
+ /// TestLoader that
+ /// </summary>
+ public class StandardLoader : ITestLoader
+ {
+ #region Overidable loader implementatioons
+ /// <summary>
+ /// Attempts by all means possible to return a test for the given type.
+ /// Check in the following order:
+ /// 1. For a static Suite property, that implments ITest.
+ /// 2. Tries to dynamically create a suite for the type.
+ /// </summary>
+ /// <param name="testClass"></param>
+ /// <returns></returns>
+ protected virtual ITest CoerceTestFrom(Type testClass)
+ {
+ try
+ {
+ ITest test = GetStaticSuiteProperty(testClass);
+ if (test == null )
+ {
+ // try to extract a test suite automatically
+ test = new TestSuite(testClass);
+ }
+ return test;
+ }
+ catch (Exception e)
+ {
+ throw new NUnitException("Error building test for class: "
+ + testClass.FullName,e);
+ }
+ }
+
+ /// <summary>
+ /// Searches for the type specified by the testClassName in the
+ /// specified assembly, and if found, attempts to coerce a test
+ /// from the type.
+ /// </summary>
+ /// <param name="testClassName"></param>
+ /// <param name="assemblyFileName"></param>
+ /// <returns></returns>
+ public virtual ITest LoadTest(string testClassName,
+ string assemblyFileName)
+ {
+ try
+ {
+ return this.CoerceTestFrom(
+ getAssembly(assemblyFileName).GetType(testClassName));
+ }
+ catch (Exception e)
+ {
+ throw new LoaderException("Error loading test class: "
+ + testClassName + "," + assemblyFileName, e);
+ }
+ }
+ /// <summary>
+ /// Determines if a Type is a test.
+ /// </summary>
+ /// <param name="typeToCheck"></param>
+ protected virtual bool IsTestClass(Type typeToCheck)
+ {
+ if(typeToCheck!=null)
+ {
+ if( typeToCheck.IsClass
+ && typeToCheck.IsPublic
+ && !typeToCheck.IsAbstract)
+ {
+ try
+ {
+ if( (typeof(ITest).IsAssignableFrom(typeToCheck)
+ // Has public single string constructor
+ && (typeToCheck.GetConstructor(new Type[]{typeof(string)})!=null))
+ || GetStaticSuiteProperty(typeToCheck)!= null)
+ {
+ return true;
+ }
+ }
+ catch(System.Security.SecurityException)
+ {
+ // eat security exceptions, since shouldn't
+ // have errors on classes we can't access
+ }
+ }
+ return false;
+ }
+ else
+ {
+ throw new ArgumentNullException("typeToCheck");
+ }
+ }
+ /// <summary>
+ /// Uses reflection to obtain the suite property for the Type
+ /// </summary>
+ /// <param name="testClass"></param>
+ /// <returns>The Suite property of the Type, or null if the property
+ /// does not exist</returns>
+ protected virtual TestSuite GetStaticSuiteProperty(Type testClass)
+ {
+ if(testClass!=null)
+ {
+ TestSuite test = null;
+ PropertyInfo suiteProperty = testClass.GetProperty("Suite"
+ ,BindingFlags.Static|BindingFlags.Public
+ ,Type.DefaultBinder // unknown
+ ,typeof(ITest) // Itest return type
+ ,Type.EmptyTypes // no parameters
+ ,new ParameterModifier[0] // unknown
+ );
+ if (suiteProperty != null )
+ {
+ test = (TestSuite)suiteProperty.GetValue(null, new Object[0]);
+ }
+ return test;
+ }
+ else
+ {
+ throw new ArgumentNullException ("testClass");
+ }
+ }
+ private Assembly getAssembly(string assemblyFileName)
+ {
+ try
+ {
+ return Assembly.LoadFrom(assemblyFileName);
+ }
+ catch(ArgumentNullException)
+ {
+ throw new ArgumentNullException("assemblyFileName");
+ }
+ }
+ #endregion
+
+ #region ILoader Methods
+ /// <summary>
+ /// Implements ILoader.GetLoadName().
+ /// </summary>
+ /// <param name="test"></param>
+ /// <returns></returns>
+ public virtual string GetLoadName(ITest test)
+ {
+ Type testType = test.GetType();
+ if(testType.Equals(typeof(TestSuite)))
+ {
+ string tname = test.ToString();
+ testType = Type.GetType(tname);
+ }
+ if(testType != null)
+ return testType.FullName+","+testType.Assembly.CodeBase;
+ else
+ return string.Empty;
+ }
+ /// <summary>
+ /// Implements ILoader.LoadTest().
+ /// Loads an instance of the test class specified by the
+ /// AssemblyQualifiedName. The assembly qualified name
+ /// contains the Full Clas Name, followed by the CodeBase
+ /// (file or url) of the assembly. If the class is found,
+ /// the loader will attempt to return a TestSuite for the
+ /// class. Trying first the static Suite property, followed
+ /// by trying to dynamically create a suite for the class.
+ /// </summary>
+ /// <param name="assemblyQualifiedName">The qualified name
+ /// for the class taking the form
+ /// "Namespace.ClassName,AssemblyFileName" without the quotes.
+ /// Assembly file name can be a fulied qualified path name, or
+ /// a URL.</param>
+ /// <returns></returns>
+ public virtual ITest LoadTest(string assemblyQualifiedName)
+ {
+ if(assemblyQualifiedName==null)
+ throw new ArgumentNullException("assemblyQualifiedName");
+
+ string[] nameParts = assemblyQualifiedName.Split(new Char[]{','});
+ if(nameParts.Length >= 1)
+ {
+ return this.LoadTest(nameParts[0].Trim(),nameParts[1].Trim());
+ }
+ else
+ {
+ throw new ArgumentException("Expected an Assembly Qualified Class"
+ + " Name, containing the file name of the assembly",
+ "assemblyQualifiedName");
+ }
+ }
+ #endregion
+
+ /// <summary>
+ /// Examies all types in the specified assembly and returns a list of those
+ /// types that can be coerced into tests.
+ /// </summary>
+ /// <param name="assemblyFileName"></param>
+ /// <returns></returns>
+ public virtual Type[] GetTestTypes(string assemblyFileName)
+ {
+ Assembly assembly = getAssembly(assemblyFileName);
+ ArrayList Tests = new ArrayList(assembly.GetExportedTypes().Length);
+ foreach(Type typeToCheck in assembly.GetExportedTypes())
+ {
+ if(this.IsTestClass(typeToCheck))
+ {
+ Tests.Add(typeToCheck);
+ }
+ }
+ Type[] ret = new Type[Tests.Count];
+ Tests.CopyTo(ret);
+ return ret;
+ }
+ }
+} \ No newline at end of file