You've already forked linux-packaging-mono
Imported Upstream version 5.20.0.180
Former-commit-id: ff953ca879339fe1e1211f7220f563e1342e66cb
This commit is contained in:
parent
0e2d47d1c8
commit
0510252385
@@ -82,6 +82,17 @@ namespace NUnit.Framework.Api
|
||||
get;
|
||||
}
|
||||
|
||||
#if MONO
|
||||
/// <summary>
|
||||
/// Gets any exception associated with an
|
||||
/// error or failure.
|
||||
/// </summary>
|
||||
string ExceptionType
|
||||
{
|
||||
get;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets the number of asserts executed
|
||||
/// when running the test and all its children.
|
||||
|
@@ -52,7 +52,7 @@ namespace NUnit.Framework.Internal.Commands
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__
|
||||
#if !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__ && !MONOTOUCH_TV && !MONOTOUCH_WATCH
|
||||
if (ex is ThreadAbortException)
|
||||
Thread.ResetAbort();
|
||||
#endif
|
||||
|
@@ -64,7 +64,7 @@ namespace NUnit.Framework.Internal.Commands
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__
|
||||
#if !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__ && !MONOTOUCH_TV && !MONOTOUCH_WATCH
|
||||
if (ex is ThreadAbortException)
|
||||
Thread.ResetAbort();
|
||||
#endif
|
||||
|
@@ -85,7 +85,7 @@ namespace NUnit.Framework.Internal.Commands
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
#if !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__
|
||||
#if !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__ && !MONOTOUCH_TV && !MONOTOUCH_WATCH
|
||||
if (ex is ThreadAbortException)
|
||||
Thread.ResetAbort();
|
||||
#endif
|
||||
|
@@ -23,6 +23,7 @@
|
||||
|
||||
using System;
|
||||
using NUnit.Framework.Api;
|
||||
using System.Reflection;
|
||||
|
||||
namespace NUnit.Framework.Internal
|
||||
{
|
||||
@@ -55,6 +56,13 @@ namespace NUnit.Framework.Internal
|
||||
/// </summary>
|
||||
private string stackTrace;
|
||||
|
||||
#if MONO
|
||||
/// <summary>
|
||||
/// The exceptionType at the point of failure
|
||||
/// </summary>
|
||||
private string exceptionType;
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Message giving the reason for failure, error or skipping the test
|
||||
/// </summary>
|
||||
@@ -162,6 +170,17 @@ namespace NUnit.Framework.Internal
|
||||
get { return stackTrace; }
|
||||
}
|
||||
|
||||
#if MONO
|
||||
/// <summary>
|
||||
/// Gets any exception associated with an
|
||||
/// error or failure.
|
||||
/// </summary>
|
||||
public virtual string ExceptionType
|
||||
{
|
||||
get { return exceptionType; }
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the count of asserts executed
|
||||
/// when running the test.
|
||||
@@ -412,6 +431,10 @@ namespace NUnit.Framework.Internal
|
||||
if (ex is NUnitException)
|
||||
ex = ex.InnerException;
|
||||
|
||||
#if MONO
|
||||
exceptionType = ex?.GetType().ToString();
|
||||
#endif
|
||||
|
||||
if (ex is System.Threading.ThreadAbortException)
|
||||
SetResult(ResultState.Cancelled, "Test cancelled by user", ex.StackTrace);
|
||||
else if (ex is AssertionException)
|
||||
@@ -422,10 +445,17 @@ namespace NUnit.Framework.Internal
|
||||
SetResult(ResultState.Inconclusive, ex.Message, StackFilter.Filter(ex.StackTrace));
|
||||
else if (ex is SuccessException)
|
||||
SetResult(ResultState.Success, ex.Message, StackFilter.Filter(ex.StackTrace));
|
||||
else
|
||||
SetResult(ResultState.Error,
|
||||
else {
|
||||
MethodInfo write = null;
|
||||
if (Environment.GetEnvironmentVariable ("MONO_TEST_TELEMETRY") != null)
|
||||
write = Type.GetType ("Mono.Runtime", false).GetMethod ("WriteStateToDisk", BindingFlags.NonPublic | BindingFlags.Static);
|
||||
if (write != null)
|
||||
write.Invoke (null, new object [] { ex });
|
||||
|
||||
SetResult(ResultState.Error,
|
||||
ExceptionHelper.BuildMessage(ex),
|
||||
ExceptionHelper.BuildStackTrace(ex));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -306,7 +306,7 @@ namespace NUnit.Framework.Internal
|
||||
if (other == null)
|
||||
return -1;
|
||||
|
||||
return this.FullName.CompareTo(other.FullName);
|
||||
return String.CompareOrdinal (this.FullName, other.FullName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -21,7 +21,7 @@
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ***********************************************************************
|
||||
|
||||
#if (CLR_2_0 || CLR_4_0) && !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__
|
||||
#if (CLR_2_0 || CLR_4_0) && !NETCF && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__ && !MONOTOUCH_TV && !MONOTOUCH_WATCH
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
|
@@ -122,7 +122,7 @@ namespace NUnit.Framework.Internal.WorkItems
|
||||
{
|
||||
_context = new TestExecutionContext(context);
|
||||
|
||||
#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__
|
||||
#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__ && !MONOTOUCH_TV && !MONOTOUCH_WATCH
|
||||
// Timeout set at a higher level
|
||||
int timeout = _context.TestCaseTimeout;
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace NUnit.Framework.Internal.WorkItems
|
||||
#endif
|
||||
}
|
||||
|
||||
#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__
|
||||
#if (CLR_2_0 || CLR_4_0) && !SILVERLIGHT && !__TVOS__ && !__WATCHOS__ && !MONOTOUCH_TV && !MONOTOUCH_WATCH
|
||||
private void RunTestWithTimeout(int timeout)
|
||||
{
|
||||
Thread thread = new Thread(new ThreadStart(RunTest));
|
||||
|
@@ -313,7 +313,11 @@ namespace NUnitLite.Runner
|
||||
break;
|
||||
case "format":
|
||||
resultFormat = val;
|
||||
if (resultFormat != "nunit3" && resultFormat != "nunit2")
|
||||
if (resultFormat != "nunit3" && resultFormat != "nunit2"
|
||||
#if MONO
|
||||
&& resultFormat != "xunit"
|
||||
#endif
|
||||
)
|
||||
InvalidOption(option);
|
||||
break;
|
||||
case "out":
|
||||
|
226
external/nunit-lite/NUnitLite-1.0.0/src/framework/Runner/OutputWriters/XunitXmlOutputWriter.cs
vendored
Normal file
226
external/nunit-lite/NUnitLite-1.0.0/src/framework/Runner/OutputWriters/XunitXmlOutputWriter.cs
vendored
Normal file
@@ -0,0 +1,226 @@
|
||||
#if MONO
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Reflection;
|
||||
using System.Xml;
|
||||
using System.IO;
|
||||
using NUnit.Framework.Api;
|
||||
using NUnit.Framework.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace NUnitLite.Runner
|
||||
{
|
||||
/// <summary>
|
||||
/// XunitXmlOutputWriter is able to create an xml file representing
|
||||
/// the result of a test run in xUnit.net v2 format.
|
||||
/// </summary>
|
||||
public class XunitXmlOutputWriter : OutputWriter
|
||||
{
|
||||
private XmlWriter xmlWriter;
|
||||
private DateTime startTime;
|
||||
private static Dictionary<string, string> resultStates = new Dictionary<string, string>();
|
||||
|
||||
static XunitXmlOutputWriter()
|
||||
{
|
||||
resultStates["Passed"] = "Pass";
|
||||
resultStates["Failed"] = "Fail";
|
||||
resultStates["Failed:Error"] = "Fail";
|
||||
resultStates["Failed:Cancelled"] = "Fail";
|
||||
resultStates["Inconclusive"] = "Skip";
|
||||
resultStates["Skipped"] = "Skip";
|
||||
resultStates["Skipped:Ignored"] = "Skip";
|
||||
resultStates["Skipped:Invalid"] = "Skip";
|
||||
}
|
||||
|
||||
public XunitXmlOutputWriter(DateTime startTime)
|
||||
{
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public override void WriteResultFile(ITestResult result, TextWriter writer)
|
||||
{
|
||||
XmlTextWriter xmlWriter = new XmlTextWriter(writer);
|
||||
xmlWriter.Formatting = Formatting.Indented;
|
||||
|
||||
try
|
||||
{
|
||||
WriteXmlOutput(result, xmlWriter);
|
||||
}
|
||||
finally
|
||||
{
|
||||
writer.Close();
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteXmlOutput(ITestResult result, XmlWriter xmlWriter)
|
||||
{
|
||||
this.xmlWriter = xmlWriter;
|
||||
|
||||
InitializeXmlFile(result);
|
||||
WriteResultElement(result);
|
||||
TerminateXmlFile();
|
||||
}
|
||||
|
||||
private void InitializeXmlFile(ITestResult result)
|
||||
{
|
||||
ResultSummary summaryResults = new ResultSummary(result);
|
||||
|
||||
xmlWriter.WriteStartDocument();
|
||||
|
||||
xmlWriter.WriteStartElement("assemblies");
|
||||
|
||||
xmlWriter.WriteStartElement("assembly");
|
||||
|
||||
xmlWriter.WriteAttributeString("name", result.FullName);
|
||||
AssemblyName assemblyName = AssemblyHelper.GetAssemblyName(Assembly.GetExecutingAssembly());
|
||||
xmlWriter.WriteAttributeString("environment", $"nunit-version: {assemblyName.Version}, clr-version: {Environment.Version}, os-version: {Environment.OSVersion}, platform: {Environment.OSVersion.Platform}, cwd: {Environment.CurrentDirectory}, machine-name: {Environment.MachineName}, user: {Environment.UserName}, user-domain: {Environment.UserDomainName}");
|
||||
xmlWriter.WriteAttributeString("test-framework", "nunitlite");
|
||||
xmlWriter.WriteAttributeString("run-date", XmlConvert.ToString(startTime, "yyyy-MM-dd"));
|
||||
xmlWriter.WriteAttributeString("run-time", XmlConvert.ToString(startTime, "HH:mm:ss"));
|
||||
|
||||
xmlWriter.WriteAttributeString("total", summaryResults.TestCount.ToString());
|
||||
xmlWriter.WriteAttributeString("errors", summaryResults.ErrorCount.ToString());
|
||||
xmlWriter.WriteAttributeString("failed", summaryResults.FailureCount.ToString());
|
||||
xmlWriter.WriteAttributeString("skipped", summaryResults.SkipCount.ToString());
|
||||
|
||||
// TODO: inconclusive? invalid?
|
||||
var passedCount = summaryResults.TestCount - summaryResults.FailureCount - summaryResults.SkipCount - summaryResults.NotRunCount;
|
||||
xmlWriter.WriteAttributeString("passed", passedCount.ToString());
|
||||
}
|
||||
|
||||
private void WriteResultElement(ITestResult result)
|
||||
{
|
||||
if (result.Test is TestSuite) {
|
||||
if ((result.Test as TestSuite).TestType == "Assembly") {
|
||||
WriteChildResults(result);
|
||||
return;
|
||||
}
|
||||
StartTestElement(result);
|
||||
WriteChildResults(result);
|
||||
xmlWriter.WriteEndElement(); // test element
|
||||
}
|
||||
else {
|
||||
StartTestElement(result);
|
||||
WritePropertiesAndCategories(result);
|
||||
|
||||
switch (result.ResultState.Status)
|
||||
{
|
||||
case TestStatus.Skipped:
|
||||
case TestStatus.Inconclusive:
|
||||
WriteReasonElement(result.Message);
|
||||
break;
|
||||
case TestStatus.Failed:
|
||||
WriteFailureElement(result.Message, result.StackTrace, result.ExceptionType ?? "UnknownException");
|
||||
break;
|
||||
}
|
||||
|
||||
xmlWriter.WriteEndElement(); // test element
|
||||
}
|
||||
}
|
||||
|
||||
private void TerminateXmlFile()
|
||||
{
|
||||
xmlWriter.WriteEndElement(); // assembly
|
||||
xmlWriter.WriteEndElement(); // assemblies
|
||||
xmlWriter.WriteEndDocument();
|
||||
xmlWriter.Flush();
|
||||
xmlWriter.Close();
|
||||
}
|
||||
|
||||
private void StartTestElement(ITestResult result)
|
||||
{
|
||||
ITest test = result.Test;
|
||||
TestSuite suite = test as TestSuite;
|
||||
|
||||
if (suite != null)
|
||||
{
|
||||
xmlWriter.WriteStartElement("collection");
|
||||
xmlWriter.WriteAttributeString("name", result.Test.FullName);
|
||||
}
|
||||
else
|
||||
{
|
||||
xmlWriter.WriteStartElement("test");
|
||||
xmlWriter.WriteAttributeString("name", result.FullName);
|
||||
xmlWriter.WriteAttributeString("type", result.Test.FixtureType.ToString());
|
||||
xmlWriter.WriteAttributeString("method", result.Name);
|
||||
}
|
||||
|
||||
TestStatus status = result.ResultState.Status;
|
||||
string translatedResult = resultStates[result.ResultState.ToString()];
|
||||
|
||||
xmlWriter.WriteAttributeString("result", translatedResult);
|
||||
xmlWriter.WriteAttributeString("time", result.Duration.TotalSeconds.ToString());
|
||||
}
|
||||
|
||||
private void WritePropertiesAndCategories(ITestResult result)
|
||||
{
|
||||
IPropertyBag properties = result.Test.Properties;
|
||||
int nprops = 0;
|
||||
|
||||
foreach (string key in properties.Keys)
|
||||
{
|
||||
foreach (object prop in properties[key])
|
||||
{
|
||||
if (nprops++ == 0)
|
||||
xmlWriter.WriteStartElement("traits");
|
||||
|
||||
xmlWriter.WriteStartElement("trait");
|
||||
xmlWriter.WriteAttributeString("name", key);
|
||||
xmlWriter.WriteAttributeString("value", prop.ToString());
|
||||
xmlWriter.WriteEndElement();
|
||||
}
|
||||
}
|
||||
|
||||
if (nprops > 0)
|
||||
xmlWriter.WriteEndElement();
|
||||
}
|
||||
|
||||
private void WriteReasonElement(string message)
|
||||
{
|
||||
xmlWriter.WriteStartElement("reason");
|
||||
xmlWriter.WriteCData(message);
|
||||
xmlWriter.WriteEndElement();
|
||||
}
|
||||
|
||||
private void WriteFailureElement(string message, string stackTrace, string exceptionType)
|
||||
{
|
||||
xmlWriter.WriteStartElement("failure");
|
||||
xmlWriter.WriteAttributeString("exception-type", exceptionType);
|
||||
xmlWriter.WriteStartElement("message");
|
||||
WriteCData(message);
|
||||
xmlWriter.WriteEndElement();
|
||||
xmlWriter.WriteStartElement("stack-trace");
|
||||
if (stackTrace != null)
|
||||
WriteCData(stackTrace);
|
||||
xmlWriter.WriteEndElement();
|
||||
xmlWriter.WriteEndElement();
|
||||
}
|
||||
|
||||
private void WriteChildResults(ITestResult result)
|
||||
{
|
||||
foreach (ITestResult childResult in result.Children)
|
||||
WriteResultElement(childResult);
|
||||
}
|
||||
|
||||
private void WriteCData(string text)
|
||||
{
|
||||
int start = 0;
|
||||
while (true)
|
||||
{
|
||||
int illegal = text.IndexOf("]]>", start);
|
||||
if (illegal < 0)
|
||||
break;
|
||||
xmlWriter.WriteCData(text.Substring(start, illegal - start + 2));
|
||||
start = illegal + 2;
|
||||
if (start >= text.Length)
|
||||
return;
|
||||
}
|
||||
|
||||
if (start > 0)
|
||||
xmlWriter.WriteCData(text.Substring(start));
|
||||
else
|
||||
xmlWriter.WriteCData(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -109,10 +109,6 @@ namespace NUnitLite.Runner
|
||||
/// <param name="args">An array of arguments</param>
|
||||
public void Execute(string[] args)
|
||||
{
|
||||
// NOTE: Execute must be directly called from the
|
||||
// test assembly in order for the mechanism to work.
|
||||
Assembly callingAssembly = Assembly.GetCallingAssembly();
|
||||
|
||||
this.commandLineOptions = new CommandLineOptions();
|
||||
commandLineOptions.Parse(args);
|
||||
|
||||
@@ -163,8 +159,12 @@ namespace NUnitLite.Runner
|
||||
}
|
||||
}
|
||||
|
||||
if (assemblies.Count == 0)
|
||||
if (assemblies.Count == 0) {
|
||||
// NOTE: Execute must be directly called from the
|
||||
// test assembly in order for the mechanism to work.
|
||||
Assembly callingAssembly = Assembly.GetCallingAssembly();
|
||||
assemblies.Add(callingAssembly);
|
||||
}
|
||||
|
||||
// TODO: For now, ignore all but first assembly
|
||||
Assembly assembly = assemblies[0] as Assembly;
|
||||
@@ -321,8 +321,14 @@ namespace NUnitLite.Runner
|
||||
|
||||
if (resultFormat == "nunit2")
|
||||
new NUnit2XmlOutputWriter(startTime).WriteResultFile(result, resultFile);
|
||||
else
|
||||
else if (resultFormat == "nunit3")
|
||||
new NUnit3XmlOutputWriter(startTime).WriteResultFile(result, resultFile);
|
||||
#if MONO
|
||||
else if (resultFormat == "xunit")
|
||||
new XunitXmlOutputWriter(startTime).WriteResultFile(result, resultFile);
|
||||
#endif
|
||||
else
|
||||
throw new Exception("Unknown resultFormat.");
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine("Results saved as {0}.", resultFile);
|
||||
|
Reference in New Issue
Block a user