|
|
@ -7,213 +7,213 @@ using NUnit.Core; |
|
|
|
|
|
|
|
|
|
|
|
namespace MicroBuildServer.DotNetBuilder |
|
|
|
namespace MicroBuildServer.DotNetBuilder |
|
|
|
{ |
|
|
|
{ |
|
|
|
class NUnitTester |
|
|
|
class NUnitTester |
|
|
|
{ |
|
|
|
{ |
|
|
|
private const string DATA_TEST_RESULTS_KEY = "TestResults"; |
|
|
|
private const string DATA_TEST_RESULTS_KEY = "TestResults"; |
|
|
|
|
|
|
|
|
|
|
|
private class Listener : EventListener |
|
|
|
private class Listener : EventListener |
|
|
|
{ |
|
|
|
{ |
|
|
|
public readonly Messages Messages = new Messages(); |
|
|
|
public readonly Messages Messages = new Messages(); |
|
|
|
|
|
|
|
|
|
|
|
private bool runFail; |
|
|
|
private bool runFail; |
|
|
|
private bool suiteFail; |
|
|
|
private bool suiteFail; |
|
|
|
|
|
|
|
|
|
|
|
private static bool IsSuccess(TestResult result) |
|
|
|
private static bool IsSuccess(TestResult result) |
|
|
|
{ |
|
|
|
{ |
|
|
|
return result.IsSuccess || result.ResultState == ResultState.Ignored; |
|
|
|
return result.IsSuccess || result.ResultState == ResultState.Ignored; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static string FormatResult(TestResult result) |
|
|
|
private static string FormatResult(TestResult result) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var additional = new List<string>(); |
|
|
|
var additional = new List<string>(); |
|
|
|
if (result.IsSuccess) |
|
|
|
if (result.IsSuccess) |
|
|
|
{ |
|
|
|
{ |
|
|
|
additional.Add("success"); |
|
|
|
additional.Add("success"); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (result.IsError) |
|
|
|
else if (result.IsError) |
|
|
|
{ |
|
|
|
{ |
|
|
|
additional.Add("error"); |
|
|
|
additional.Add("error"); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (result.IsFailure) |
|
|
|
else if (result.IsFailure) |
|
|
|
{ |
|
|
|
{ |
|
|
|
additional.Add("fail"); |
|
|
|
additional.Add("fail"); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (result.ResultState == ResultState.Ignored) |
|
|
|
else if (result.ResultState == ResultState.Ignored) |
|
|
|
{ |
|
|
|
{ |
|
|
|
additional.Add("ignored"); |
|
|
|
additional.Add("ignored"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
additional.Add("status unknown"); |
|
|
|
additional.Add("status unknown"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(result.Message)) |
|
|
|
if (!string.IsNullOrEmpty(result.Message)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
additional.Add("message = " + result.Message); |
|
|
|
additional.Add("message = " + result.Message); |
|
|
|
} |
|
|
|
} |
|
|
|
return additional.Any() ? result.Name + "; " + string.Join(", ", additional) : result.Name; |
|
|
|
return additional.Any() ? result.Name + "; " + string.Join(", ", additional) : result.Name; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void RunFinished(Exception exception) |
|
|
|
public void RunFinished(Exception exception) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateError("Run finished: " + exception)); |
|
|
|
Messages.Add(Message.CreateError("Run finished: " + exception)); |
|
|
|
runFail = true; |
|
|
|
runFail = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void RunFinished(TestResult result) |
|
|
|
public void RunFinished(TestResult result) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var message = string.Format("Run finished: {0}", FormatResult(result)); |
|
|
|
var message = string.Format("Run finished: {0}", FormatResult(result)); |
|
|
|
|
|
|
|
|
|
|
|
if (!IsSuccess(result) && !runFail) |
|
|
|
if (!IsSuccess(result) && !runFail) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateError(message)); |
|
|
|
Messages.Add(Message.CreateError(message)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateInfo(message)); |
|
|
|
Messages.Add(Message.CreateInfo(message)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void RunStarted(string name, int testCount) |
|
|
|
public void RunStarted(string name, int testCount) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateInfo("Run started: " + name)); |
|
|
|
Messages.Add(Message.CreateInfo("Run started: " + name)); |
|
|
|
runFail = false; |
|
|
|
runFail = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void SuiteFinished(TestResult result) |
|
|
|
public void SuiteFinished(TestResult result) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var message = string.Format("Suite finished: {0}", FormatResult(result)); |
|
|
|
var message = string.Format("Suite finished: {0}", FormatResult(result)); |
|
|
|
|
|
|
|
|
|
|
|
if (!IsSuccess(result) && !suiteFail) |
|
|
|
if (!IsSuccess(result) && !suiteFail) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateError(message)); |
|
|
|
Messages.Add(Message.CreateError(message)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateInfo(message)); |
|
|
|
Messages.Add(Message.CreateInfo(message)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!result.IsSuccess) |
|
|
|
if (!result.IsSuccess) |
|
|
|
{ |
|
|
|
{ |
|
|
|
runFail = true; |
|
|
|
runFail = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void SuiteStarted(TestName testName) |
|
|
|
public void SuiteStarted(TestName testName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateInfo("Suite started: " + testName.Name)); |
|
|
|
Messages.Add(Message.CreateInfo("Suite started: " + testName.Name)); |
|
|
|
suiteFail = false; |
|
|
|
suiteFail = false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void TestFinished(TestResult result) |
|
|
|
public void TestFinished(TestResult result) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var message = string.Format("Test finished: {0}", FormatResult(result)); |
|
|
|
var message = string.Format("Test finished: {0}", FormatResult(result)); |
|
|
|
|
|
|
|
|
|
|
|
if (!IsSuccess(result)) |
|
|
|
if (!IsSuccess(result)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateError(message)); |
|
|
|
Messages.Add(Message.CreateError(message)); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateInfo(message)); |
|
|
|
Messages.Add(Message.CreateInfo(message)); |
|
|
|
} |
|
|
|
} |
|
|
|
suiteFail = true; |
|
|
|
suiteFail = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void TestOutput(TestOutput testOutput) |
|
|
|
public void TestOutput(TestOutput testOutput) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateInfo("Test output: " + testOutput.Text)); |
|
|
|
Messages.Add(Message.CreateInfo("Test output: " + testOutput.Text)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void TestStarted(TestName testName) |
|
|
|
public void TestStarted(TestName testName) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateInfo("Test started: " + testName.Name)); |
|
|
|
Messages.Add(Message.CreateInfo("Test started: " + testName.Name)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void UnhandledException(Exception exception) |
|
|
|
public void UnhandledException(Exception exception) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Messages.Add(Message.CreateError("Unhandled exception: " + exception)); |
|
|
|
Messages.Add(Message.CreateError("Unhandled exception: " + exception)); |
|
|
|
suiteFail = true; |
|
|
|
suiteFail = true; |
|
|
|
runFail = true; |
|
|
|
runFail = true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public interface ITestWorker |
|
|
|
public interface ITestWorker |
|
|
|
{ |
|
|
|
{ |
|
|
|
void DoTest(string testLibraryPath); |
|
|
|
void DoTest(string testLibraryPath); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[Serializable] |
|
|
|
[Serializable] |
|
|
|
public class TestWorker : MarshalByRefObject, ITestWorker |
|
|
|
public class TestWorker : MarshalByRefObject, ITestWorker |
|
|
|
{ |
|
|
|
{ |
|
|
|
public void DoTest(string testLibraryPath) |
|
|
|
public void DoTest(string testLibraryPath) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Console.SetOut(new StubWriter()); |
|
|
|
Console.SetOut(new StubWriter()); |
|
|
|
var listener = new Listener(); |
|
|
|
var listener = new Listener(); |
|
|
|
CoreExtensions.Host.InitializeService(); |
|
|
|
CoreExtensions.Host.InitializeService(); |
|
|
|
var package = new TestPackage(testLibraryPath); |
|
|
|
var package = new TestPackage(testLibraryPath); |
|
|
|
//package.AutoBinPath = true; |
|
|
|
//package.AutoBinPath = true; |
|
|
|
//package.BasePath = Path.GetDirectoryName(TestLibraryPath); |
|
|
|
//package.BasePath = Path.GetDirectoryName(TestLibraryPath); |
|
|
|
//package.ConfigurationFile = TestLibraryPath + ".config"; |
|
|
|
//package.ConfigurationFile = TestLibraryPath + ".config"; |
|
|
|
TestRunner runner = new SimpleTestRunner(); |
|
|
|
TestRunner runner = new SimpleTestRunner(); |
|
|
|
if (runner.Load(package)) |
|
|
|
if (runner.Load(package)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
runner.Run(listener, TestFilter.Empty, true, LoggingThreshold.All); |
|
|
|
runner.Run(listener, TestFilter.Empty, true, LoggingThreshold.All); |
|
|
|
} |
|
|
|
} |
|
|
|
//DebugTestResult(Console.Out, result); |
|
|
|
//DebugTestResult(Console.Out, result); |
|
|
|
|
|
|
|
|
|
|
|
if (!listener.Messages.Any()) |
|
|
|
if (!listener.Messages.Any()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
listener.Messages.Add(Message.CreateError("No messages from listener")); |
|
|
|
listener.Messages.Add(Message.CreateError("No messages from listener")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
AppDomain.CurrentDomain.SetData(DATA_TEST_RESULTS_KEY, new Response(listener.Messages)); |
|
|
|
AppDomain.CurrentDomain.SetData(DATA_TEST_RESULTS_KEY, new Response(listener.Messages)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/*private static void DebugTestResult(object rawResult, int level = 0) |
|
|
|
/*private static void DebugTestResult(object rawResult, int level = 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (rawResult == null) |
|
|
|
if (rawResult == null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Console.WriteLine("Result is null"); |
|
|
|
Console.WriteLine("Result is null"); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var prefix = new string('\t', level); |
|
|
|
var prefix = new string('\t', level); |
|
|
|
Console.WriteLine("{0}RESULT START", prefix); |
|
|
|
Console.WriteLine("{0}RESULT START", prefix); |
|
|
|
Console.WriteLine("{0}Type: {1}", prefix, rawResult); |
|
|
|
Console.WriteLine("{0}Type: {1}", prefix, rawResult); |
|
|
|
if (rawResult is TestResult) |
|
|
|
if (rawResult is TestResult) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var result = (TestResult) rawResult; |
|
|
|
var result = (TestResult) rawResult; |
|
|
|
Console.WriteLine("{0}Full name: {1}", prefix, result.FullName); |
|
|
|
Console.WriteLine("{0}Full name: {1}", prefix, result.FullName); |
|
|
|
Console.WriteLine("{0}Has results: {1}", prefix, result.HasResults); |
|
|
|
Console.WriteLine("{0}Has results: {1}", prefix, result.HasResults); |
|
|
|
Console.WriteLine("{0}Success? {1}", prefix, result.IsSuccess); |
|
|
|
Console.WriteLine("{0}Success? {1}", prefix, result.IsSuccess); |
|
|
|
Console.WriteLine("{0}Message: {1}", prefix, result.Message); |
|
|
|
Console.WriteLine("{0}Message: {1}", prefix, result.Message); |
|
|
|
Console.WriteLine("{0}Test: {1}", prefix, result.Test.TestName); |
|
|
|
Console.WriteLine("{0}Test: {1}", prefix, result.Test.TestName); |
|
|
|
|
|
|
|
|
|
|
|
if (result.Results != null) |
|
|
|
if (result.Results != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Console.WriteLine("{0}Results: {1}", prefix, result.Results.Count); |
|
|
|
Console.WriteLine("{0}Results: {1}", prefix, result.Results.Count); |
|
|
|
foreach (var v in result.Results) |
|
|
|
foreach (var v in result.Results) |
|
|
|
{ |
|
|
|
{ |
|
|
|
DebugTestResult(v, level+1); |
|
|
|
DebugTestResult(v, level+1); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Console.WriteLine("{0}RESULT END", prefix); |
|
|
|
Console.WriteLine("{0}RESULT END", prefix); |
|
|
|
}*/ |
|
|
|
}*/ |
|
|
|
|
|
|
|
|
|
|
|
public static Response Test(TestRequest request) |
|
|
|
public static Response Test(TestRequest request) |
|
|
|
{ |
|
|
|
{ |
|
|
|
AppDomainSetup setup = new AppDomainSetup(); |
|
|
|
AppDomainSetup setup = new AppDomainSetup(); |
|
|
|
setup.ConfigurationFile = request.TestLibraryPath + ".config"; |
|
|
|
setup.ConfigurationFile = request.TestLibraryPath + ".config"; |
|
|
|
setup.ApplicationBase = Path.GetDirectoryName(request.TestLibraryPath); |
|
|
|
setup.ApplicationBase = Path.GetDirectoryName(request.TestLibraryPath); |
|
|
|
AppDomain tester = AppDomain.CreateDomain("tester", AppDomain.CurrentDomain.Evidence, setup); |
|
|
|
AppDomain tester = AppDomain.CreateDomain("tester", AppDomain.CurrentDomain.Evidence, setup); |
|
|
|
|
|
|
|
|
|
|
|
var worker = (ITestWorker) tester.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof (TestWorker).FullName); |
|
|
|
var worker = (ITestWorker) tester.CreateInstanceFromAndUnwrap(Assembly.GetExecutingAssembly().Location, typeof (TestWorker).FullName); |
|
|
|
|
|
|
|
|
|
|
|
worker.DoTest(request.TestLibraryPath); |
|
|
|
worker.DoTest(request.TestLibraryPath); |
|
|
|
return (Response)(tester.GetData(DATA_TEST_RESULTS_KEY)); |
|
|
|
return (Response)(tester.GetData(DATA_TEST_RESULTS_KEY)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|