Add Nunit2 files
authorNick Drochak <nickd@mono-cvs.ximian.com>
Mon, 9 Dec 2002 14:42:20 +0000 (14:42 -0000)
committerNick Drochak <nickd@mono-cvs.ximian.com>
Mon, 9 Dec 2002 14:42:20 +0000 (14:42 -0000)
svn path=/trunk/mcs/; revision=9481

mcs/nunit20/nunit-console/App.ico [new file with mode: 0755]
mcs/nunit20/nunit-console/AssemblyInfo.cs [new file with mode: 0755]
mcs/nunit20/nunit-console/ConsoleUi.cs [new file with mode: 0755]
mcs/nunit20/nunit-console/MonoConsole.cs [new file with mode: 0755]
mcs/nunit20/nunit-console/app.config [new file with mode: 0755]
mcs/nunit20/nunit-console/makefile.gnu [new file with mode: 0755]
mcs/nunit20/nunit-console/nunit-console.csproj [new file with mode: 0755]

diff --git a/mcs/nunit20/nunit-console/App.ico b/mcs/nunit20/nunit-console/App.ico
new file mode 100755 (executable)
index 0000000..3a5525f
Binary files /dev/null and b/mcs/nunit20/nunit-console/App.ico differ
diff --git a/mcs/nunit20/nunit-console/AssemblyInfo.cs b/mcs/nunit20/nunit-console/AssemblyInfo.cs
new file mode 100755 (executable)
index 0000000..c604751
--- /dev/null
@@ -0,0 +1,58 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+//
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+//
+[assembly: AssemblyTitle("")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("NUnit")]
+[assembly: AssemblyCopyright("Copyright (C) 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. \nCopyright (C) 2000-2002 Philip Craig.\nAll Rights Reserved.")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]                
+
+//
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Revision and Build Numbers 
+// by using the '*' as shown below:
+
+[assembly: AssemblyVersion("2.0.9.001")]
+
+//
+// In order to sign your assembly you must specify a key to use. Refer to the 
+// Microsoft .NET Framework documentation for more information on assembly signing.
+//
+// Use the attributes below to control which key is used for signing. 
+//
+// Notes: 
+//   (*) If no key is specified, the assembly is not signed.
+//   (*) KeyName refers to a key that has been installed in the Crypto Service
+//       Provider (CSP) on your machine. KeyFile refers to a file which contains
+//       a key.
+//   (*) If the KeyFile and the KeyName values are both specified, the 
+//       following processing occurs:
+//       (1) If the KeyName can be found in the CSP, that key is used.
+//       (2) If the KeyName does not exist and the KeyFile does exist, the key 
+//           in the KeyFile is installed into the CSP and used.
+//   (*) In order to create a KeyFile, you can use the sn.exe (Strong Name) utility.
+//       When specifying the KeyFile, the location of the KeyFile should be
+//       relative to the project output directory which is
+//       %Project Directory%\obj\<configuration>. For example, if your KeyFile is
+//       located in the project directory, you would specify the AssemblyKeyFile 
+//       attribute as [assembly: AssemblyKeyFile("..\\..\\mykey.snk")]
+//   (*) Delay Signing is an advanced option - see the Microsoft .NET Framework
+//       documentation for more information on this.
+//
+[assembly: AssemblyDelaySign(false)]
+[assembly: AssemblyKeyFile("")]
+[assembly: AssemblyKeyName("")]
diff --git a/mcs/nunit20/nunit-console/ConsoleUi.cs b/mcs/nunit20/nunit-console/ConsoleUi.cs
new file mode 100755 (executable)
index 0000000..a772e71
--- /dev/null
@@ -0,0 +1,259 @@
+#region Copyright (c) 2002, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Philip A. Craig
+/************************************************************************************
+'
+' Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov
+' Copyright © 2000-2002 Philip A. Craig
+'
+' This software is provided 'as-is', without any express or implied warranty. In no 
+' event will the authors be held liable for any damages arising from the use of this 
+' software.
+' 
+' Permission is granted to anyone to use this software for any purpose, including 
+' commercial applications, and to alter it and redistribute it freely, subject to the 
+' following restrictions:
+'
+' 1. The origin of this software must not be misrepresented; you must not claim that 
+' you wrote the original software. If you use this software in a product, an 
+' acknowledgment (see the following) in the product documentation is required.
+'
+' Portions Copyright © 2002 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov 
+' or Copyright © 2000-2002 Philip A. Craig
+'
+' 2. Altered source versions must be plainly marked as such, and must not be 
+' misrepresented as being the original software.
+'
+' 3. This notice may not be removed or altered from any source distribution.
+'
+'***********************************************************************************/
+#endregion
+
+namespace NUnit.Console
+{
+       using System;
+       using System.IO;
+       using System.Reflection;
+       using System.Xml;
+       using System.Xml.Xsl;
+       using System.Xml.XPath;
+       using System.Resources;
+       using System.Text;
+       using NUnit.Core;
+       using NUnit.Util;
+       
+
+       /// <summary>
+       /// Summary description for ConsoleUi.
+       /// </summary>
+       public class ConsoleUi
+       {
+               private NUnit.Framework.TestDomain testDomain;
+               private string outputFile;
+               private XmlTextReader transformReader;
+
+               public static int Main(string[] args)
+               {
+                       int returnCode = 0;
+
+                       ConsoleOptions parser = new ConsoleOptions(args);
+                       if(!parser.nologo)
+                               WriteCopyright();
+
+                       if(parser.help)
+                       {
+                               parser.Help();
+                       }
+                       else if(parser.NoArgs) 
+                       {
+                               Console.Error.WriteLine("\nfatal error: no inputs specified");
+                               parser.Help();
+                       }
+                       else if(!parser.Validate())
+                       {
+                               Console.Error.WriteLine("\nfatal error: invalid arguments");
+                               parser.Help();
+                               returnCode = 2;
+                       }
+                       else
+                       {
+                               ConsoleWriter outStream = new ConsoleWriter(Console.Out);
+                               ConsoleWriter errorStream = new ConsoleWriter(Console.Error);
+                               NUnit.Framework.TestDomain domain = new NUnit.Framework.TestDomain(outStream, errorStream);
+
+                               Test test = MakeTestFromCommandLine(domain, parser);
+                               try
+                               {
+                                       if(test == null)
+                                       {
+                                               Console.Error.WriteLine("\nfatal error: invalid assembly {0}", parser.Assembly);
+                                               returnCode = 2;
+                                       }
+                                       else
+                                       {
+                                               Directory.SetCurrentDirectory(new FileInfo(parser.Assembly).DirectoryName);
+                                               string xmlResult = "TestResult.xml";
+                                               if(parser.IsXml)
+                                                       xmlResult = parser.xml;
+
+                                               XmlTextReader reader = GetTransformReader(parser);
+                                               if(reader != null)
+                                               {
+                                                       ConsoleUi consoleUi = new ConsoleUi(domain, xmlResult, reader);
+                                                       returnCode = consoleUi.Execute();
+                                                       if(parser.wait)
+                                                       {
+                                                               Console.Out.WriteLine("Hit <enter> key to continue");
+                                                               Console.ReadLine();
+                                                       }
+                                               }
+                                               else
+                                                       returnCode = 3;
+                                       }
+                               }
+                               finally
+                               {
+                                       domain.Unload();
+                               }
+                       }
+
+
+                       return returnCode;
+               }
+
+               private static XmlTextReader GetTransformReader(ConsoleOptions parser)
+               {
+                       XmlTextReader reader = null;
+                       if(!parser.IsTransform)
+                       {
+                               Assembly assembly = Assembly.GetAssembly(typeof(XmlResultVisitor));
+                               ResourceManager resourceManager = new ResourceManager("NUnit.Framework.Transform",assembly);
+                               string xmlData = (string)resourceManager.GetObject("Summary.xslt");
+
+                               reader = new XmlTextReader(new StringReader(xmlData));
+                       }
+                       else
+                       {
+                               FileInfo xsltInfo = new FileInfo(parser.transform);
+                               if(!xsltInfo.Exists)
+                               {
+                                       Console.Error.WriteLine("\nTransform file: {0} does not exist", xsltInfo.FullName);
+                                       reader = null;
+                               }
+                               else
+                               {
+                                       reader = new XmlTextReader(xsltInfo.FullName);
+                               }
+                       }
+
+                       return reader;
+               }
+
+               private static void WriteCopyright()
+               {
+                       Assembly executingAssembly = Assembly.GetExecutingAssembly();
+                       System.Version version = executingAssembly.GetName().Version;
+
+                       object[] objectAttrs = executingAssembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false);
+                       AssemblyProductAttribute productAttr = (AssemblyProductAttribute)objectAttrs[0];
+
+                       objectAttrs = executingAssembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);
+                       AssemblyCopyrightAttribute copyrightAttr = (AssemblyCopyrightAttribute)objectAttrs[0];
+
+                       Console.WriteLine(String.Format("{0} version {1}", productAttr.Product, version.ToString(3)));
+                       Console.WriteLine(copyrightAttr.Copyright);
+               }
+
+               private static Test MakeTestFromCommandLine(NUnit.Framework.TestDomain testDomain, 
+                       ConsoleOptions parser)
+               {
+                       Test test = null;
+
+                       if(!DoesFileExist(parser.Assembly)) return null; 
+                       
+                       if(parser.IsAssembly)
+                       {
+                               test = testDomain.Load(parser.Assembly);
+                               if(test == null) Console.WriteLine("\nfatal error: assembly ({0}) is invalid", parser.Assembly);
+                       }
+                       else if(parser.IsFixture)
+                       {
+                               test = testDomain.Load(parser.fixture, parser.Assembly);
+                               if(test == null) Console.WriteLine("\nfatal error: fixture ({0}) in assembly ({1}) is invalid", parser.fixture, parser.Assembly);
+                       }
+                       return test;
+               }
+
+               private static bool DoesFileExist(string fileName)
+               {
+                       FileInfo fileInfo = new FileInfo(fileName);
+                       return fileInfo.Exists;
+               }
+
+               private static void WriteHelp(TextWriter writer)
+               {
+                       writer.WriteLine("\n\n         NUnit console options\n");
+                       writer.WriteLine("/assembly:<assembly name>                            Assembly to test");
+                       writer.WriteLine("/fixture:<class name> /assembly:<assembly name>      Fixture or Suite to run");
+                       writer.WriteLine("\n\n         XML formatting options");
+                       writer.WriteLine("/xml:<file>                 XML result file to generate");
+                       writer.WriteLine("/transform:<file>           XSL transform file");
+               }
+
+               public ConsoleUi(NUnit.Framework.TestDomain testDomain, string xmlFile, XmlTextReader reader)
+               {
+                       this.testDomain = testDomain;
+                       outputFile = xmlFile;
+                       transformReader = reader;
+               }
+
+               public int Execute()
+               {
+                       EventCollector collector = new EventCollector();
+                       TestResult result = testDomain.Run(collector);
+
+                       Console.WriteLine("\n");
+                       XmlResultVisitor resultVisitor = new XmlResultVisitor(outputFile, result);
+                       result.Accept(resultVisitor);
+                       resultVisitor.Write();
+                       CreateSummaryDocument();
+
+                       int resultCode = 0;
+                       if(result.IsFailure)
+                               resultCode = 1;
+                       return resultCode;
+               }
+
+               private void CreateSummaryDocument()
+               {
+                       XPathDocument originalXPathDocument = new XPathDocument (outputFile);
+                       XslTransform summaryXslTransform = new XslTransform();
+                       summaryXslTransform.Load(transformReader);
+                       
+                       summaryXslTransform.Transform(originalXPathDocument,null,Console.Out);
+               }
+
+               private class EventCollector : LongLivingMarshalByRefObject, EventListener
+               {
+                       public void TestFinished(TestCaseResult testResult)
+                       {
+                               if(testResult.Executed)
+                               {
+                                       if(testResult.IsFailure)
+                                       {       
+                                               Console.Write("F");
+                                       }
+                               }
+                               else
+                                       Console.Write("N");
+                       }
+
+                       public void TestStarted(TestCase testCase)
+                       {
+                               Console.Write(".");
+                       }
+
+                       public void SuiteStarted(TestSuite suite) {}
+                       public void SuiteFinished(TestSuiteResult result) {}
+               }
+
+       }
+}
diff --git a/mcs/nunit20/nunit-console/MonoConsole.cs b/mcs/nunit20/nunit-console/MonoConsole.cs
new file mode 100755 (executable)
index 0000000..4b55d9c
--- /dev/null
@@ -0,0 +1,52 @@
+//
+// NUnit.Console.MonoConsole.cs
+//
+// Author:
+//   Jackson Harper (Jackson@LatitudeGeo.com)
+//
+
+using System;
+using System.Reflection;
+using NUnit.Framework;
+
+
+namespace NUnit.Console {
+
+  /// <summary>
+  ///    This is a lightweight NUnit 2.0 console runner designed to run
+  ///    in mono's current state. As soon as AppDomains are fully implemented
+  ///    in mono the nunit-console class can be used
+  /// </summary>
+  public class MonoConsole {
+
+    private Assembly    mAssembly;
+
+    //
+    // Public Constructors
+    //
+
+    public MonoConsole( string assemblypath ) {
+      mAssembly  =  Assembly.LoadFrom( assemblypath );
+      Run();
+    }
+    
+    //
+    // Private Methods
+    //
+    
+    private void Run() {
+
+    }
+
+    private void TestType( Type t ) {
+
+    }
+
+    private void TestMethod( MemberInfo method ) {
+
+    }
+
+  }
+
+}
+
diff --git a/mcs/nunit20/nunit-console/app.config b/mcs/nunit20/nunit-console/app.config
new file mode 100755 (executable)
index 0000000..e1bb1c3
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<configuration>
+  <appSettings>
+    <!--   User application and configured property settings go here.-->
+    <!--   Example: <add key="settingName" value="settingValue"/> -->
+    <add key="shadowfiles.path" value="%temp%\nunit20\ShadowCopyCache" />
+  </appSettings>
+</configuration>
\ No newline at end of file
diff --git a/mcs/nunit20/nunit-console/makefile.gnu b/mcs/nunit20/nunit-console/makefile.gnu
new file mode 100755 (executable)
index 0000000..f915161
--- /dev/null
@@ -0,0 +1,12 @@
+#
+# Makefile for nunit-console.exe
+#
+# Author:
+#   Jackson Harper (Jackson@LatitudeGeo.com)
+#
+
+all:
+       mcs *.cs /r:../NUnit.Framework.dll /r:../NUnit.Util.dll /out:../nunit-console.exe
+
+clean:
+       rm -f ../nunit-console.exe
\ No newline at end of file
diff --git a/mcs/nunit20/nunit-console/nunit-console.csproj b/mcs/nunit20/nunit-console/nunit-console.csproj
new file mode 100755 (executable)
index 0000000..cfbf2d3
--- /dev/null
@@ -0,0 +1,107 @@
+<VisualStudioProject>
+    <CSHARP
+        ProjectType = "Local"
+        ProductVersion = "7.0.9466"
+        SchemaVersion = "1.0"
+        ProjectGuid = "{9367EC89-6A38-42BA-9607-0DC288E4BC3A}"
+    >
+        <Build>
+            <Settings
+                ApplicationIcon = ""
+                AssemblyKeyContainerName = ""
+                AssemblyName = "nunit-console"
+                AssemblyOriginatorKeyFile = ""
+                DefaultClientScript = "JScript"
+                DefaultHTMLPageLayout = "Grid"
+                DefaultTargetSchema = "IE50"
+                DelaySign = "false"
+                OutputType = "Exe"
+                RootNamespace = "nunit_console"
+                StartupObject = ""
+            >
+                <Config
+                    Name = "Debug"
+                    AllowUnsafeBlocks = "false"
+                    BaseAddress = "285212672"
+                    CheckForOverflowUnderflow = "false"
+                    ConfigurationOverrideFile = ""
+                    DefineConstants = "DEBUG;TRACE"
+                    DocumentationFile = ""
+                    DebugSymbols = "true"
+                    FileAlignment = "4096"
+                    IncrementalBuild = "true"
+                    Optimize = "false"
+                    OutputPath = "bin\Debug\"
+                    RegisterForComInterop = "false"
+                    RemoveIntegerChecks = "false"
+                    TreatWarningsAsErrors = "false"
+                    WarningLevel = "4"
+                />
+                <Config
+                    Name = "Release"
+                    AllowUnsafeBlocks = "false"
+                    BaseAddress = "285212672"
+                    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"
+                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.dll"
+                />
+                <Reference
+                    Name = "System.Data"
+                    AssemblyName = "System.Data"
+                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.Data.dll"
+                />
+                <Reference
+                    Name = "System.XML"
+                    AssemblyName = "System.Xml"
+                    HintPath = "..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.0.3705\System.XML.dll"
+                />
+                <Reference
+                    Name = "nunit.framework.dll"
+                    Project = "{83DD7E12-A705-4DBA-9D71-09C8973D9382}"
+                    Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
+                />
+                <Reference
+                    Name = "nunit.util.dll"
+                    Project = "{61CE9CE5-943E-44D4-A381-814DC1406767}"
+                    Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
+                />
+            </References>
+        </Build>
+        <Files>
+            <Include>
+                <File
+                    RelPath = "app.config"
+                    BuildAction = "None"
+                />
+                <File
+                    RelPath = "AssemblyInfo.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
+                    RelPath = "ConsoleUi.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+            </Include>
+        </Files>
+    </CSHARP>
+</VisualStudioProject>
+