зеркало из
1
0
Форкнуть 0

Added FIleLoadException to warning list in discovery, ref Issue #21

This commit is contained in:
Terje Sandstrom 2013-12-09 22:30:30 +01:00
Родитель ffbfcb6d94
Коммит e1a1cdec10
5 изменённых файлов: 209 добавлений и 197 удалений

1
.gitignore поставляемый
Просмотреть файл

@ -9,3 +9,4 @@ TestResults
/Backup
/UpgradeLog.htm
packages/
Backup/

Просмотреть файл

@ -1,113 +1,119 @@
// ****************************************************************
// Copyright (c) 2011 NUnit Software. All rights reserved.
// ****************************************************************
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NUnit.Core;
using NUnit.Util;
namespace NUnit.VisualStudio.TestAdapter
{
using System;
[FileExtension(".dll")]
[FileExtension(".exe")]
[DefaultExecutorUri(NUnitTestExecutor.ExecutorUri)]
public sealed class NUnitTestDiscoverer : NUnitTestAdapter, ITestDiscoverer
{
#region ITestDiscoverer Members
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
{
testLog.Initialize(messageLogger);
Info("discovering tests", "started");
// Ensure any channels registered by other adapters are unregistered
CleanUpRegisteredChannels();
foreach (string sourceAssembly in sources)
{
testLog.SendDebugMessage("Processing " + sourceAssembly);
TestRunner runner = new TestDomain();
TestPackage package = new TestPackage(sourceAssembly);
TestConverter testConverter = null;
try
{
if (runner.Load(package))
{
testConverter = new TestConverter(testLog, sourceAssembly);
int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
testLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
}
else
{
testLog.NUnitLoadError(sourceAssembly);
}
}
catch (System.BadImageFormatException)
{
// we skip the native c++ binaries that we don't support.
testLog.AssemblyNotSupportedWarning(sourceAssembly);
}
catch (System.IO.FileNotFoundException ex)
{
// Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
testLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
}
catch (System.Exception ex)
{
testLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
}
finally
{
if (testConverter != null)
testConverter.Dispose();
testConverter = null;
runner.Unload();
}
}
Info("discovering test", "finished");
}
private int ProcessTestCases(ITest test, ITestCaseDiscoverySink discoverySink, TestConverter testConverter)
{
int cases = 0;
if (test.IsSuite)
{
foreach (ITest child in test.Tests)
cases += ProcessTestCases(child, discoverySink,testConverter);
}
else
{
try
{
#if LAUNCHDEBUGGER
Debugger.Launch();
#endif
TestCase testCase = testConverter.ConvertTestCase(test);
discoverySink.SendTestCase(testCase);
cases += 1;
}
catch (System.Exception ex)
{
testLog.SendErrorMessage("Exception converting " + test.TestName.FullName, ex);
}
}
return cases;
}
#endregion
}
}
// ****************************************************************
// Copyright (c) 2011 NUnit Software. All rights reserved.
// ****************************************************************
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
using NUnit.Core;
using NUnit.Util;
namespace NUnit.VisualStudio.TestAdapter
{
using System;
[FileExtension(".dll")]
[FileExtension(".exe")]
[DefaultExecutorUri(NUnitTestExecutor.ExecutorUri)]
public sealed class NUnitTestDiscoverer : NUnitTestAdapter, ITestDiscoverer
{
#region ITestDiscoverer Members
public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger messageLogger, ITestCaseDiscoverySink discoverySink)
{
testLog.Initialize(messageLogger);
Info("discovering tests", "started");
// Ensure any channels registered by other adapters are unregistered
CleanUpRegisteredChannels();
foreach (string sourceAssembly in sources)
{
testLog.SendDebugMessage("Processing " + sourceAssembly);
TestRunner runner = new TestDomain();
TestPackage package = new TestPackage(sourceAssembly);
TestConverter testConverter = null;
try
{
if (runner.Load(package))
{
testConverter = new TestConverter(testLog, sourceAssembly);
int cases = ProcessTestCases(runner.Test, discoverySink, testConverter);
testLog.SendDebugMessage(string.Format("Discovered {0} test cases", cases));
}
else
{
testLog.NUnitLoadError(sourceAssembly);
}
}
catch (System.BadImageFormatException)
{
// we skip the native c++ binaries that we don't support.
testLog.AssemblyNotSupportedWarning(sourceAssembly);
}
catch (System.IO.FileNotFoundException ex)
{
// Probably from the GetExportedTypes in NUnit.core, attempting to find an assembly, not a problem if it is not NUnit here
testLog.DependentAssemblyNotFoundWarning(ex.FileName, sourceAssembly);
}
catch (FileLoadException ex)
{
// Attempts to load an invalid assembly, or an assembly with missing dependencies
testLog.LoadingAssemblyFailedWarning(ex.FileName, sourceAssembly);
}
catch (System.Exception ex)
{
testLog.SendErrorMessage("Exception thrown discovering tests in " + sourceAssembly, ex);
}
finally
{
if (testConverter != null)
testConverter.Dispose();
testConverter = null;
runner.Unload();
}
}
Info("discovering test", "finished");
}
private int ProcessTestCases(ITest test, ITestCaseDiscoverySink discoverySink, TestConverter testConverter)
{
int cases = 0;
if (test.IsSuite)
{
foreach (ITest child in test.Tests)
cases += ProcessTestCases(child, discoverySink,testConverter);
}
else
{
try
{
#if LAUNCHDEBUGGER
Debugger.Launch();
#endif
TestCase testCase = testConverter.ConvertTestCase(test);
discoverySink.SendTestCase(testCase);
cases += 1;
}
catch (System.Exception ex)
{
testLog.SendErrorMessage("Exception converting " + test.TestName.FullName, ex);
}
}
return cases;
}
#endregion
}
}

Просмотреть файл

@ -21,5 +21,5 @@ using System.Runtime.InteropServices;
[assembly: ComVisible(false)]
[assembly: Guid("c0aad5e4-b486-49bc-b3e8-31e01be6fefe")]
[assembly: AssemblyVersion("1.0.0.7")]
[assembly: AssemblyFileVersion("1.0.0.7")]
[assembly: AssemblyVersion("1.0.0.8")]
[assembly: AssemblyFileVersion("1.0.0.8")]

Просмотреть файл

@ -1,81 +1,86 @@
// ****************************************************************
// Copyright (c) 2013 NUnit Software. All rights reserved.
// ****************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
namespace NUnit.VisualStudio.TestAdapter
{
/// <summary>
/// TestLogger wraps an IMessageLogger and adds various
/// utility methods for sending messages. Since the
/// IMessageLogger is only provided when the discovery
/// and execution objects are called, we use two-phase
/// construction. Until Initialize is called, the logger
/// simply swallows all messages without sending them
/// anywhere.
/// </summary>
public class TestLogger : IMessageLogger
{
private IMessageLogger messageLogger;
public void Initialize(IMessageLogger messageLogger)
{
this.messageLogger = messageLogger;
}
public void AssemblyNotSupportedWarning(string sourceAssembly)
{
SendWarningMessage("Assembly not supported: " + sourceAssembly);
}
public void DependentAssemblyNotFoundWarning(string dependentAssembly, string sourceAssembly)
{
SendWarningMessage("Dependent Assembly " + dependentAssembly + " of " + sourceAssembly + " not found. Can be ignored if not a NUnit project.");
}
public void NUnitLoadError(string sourceAssembly)
{
SendErrorMessage("NUnit failed to load " + sourceAssembly);
}
public void SendErrorMessage(string message)
{
SendMessage(TestMessageLevel.Error, message);
}
public void SendErrorMessage(string message, Exception ex)
{
SendMessage(TestMessageLevel.Error, message);
SendMessage(TestMessageLevel.Error, ex.ToString());
}
public void SendWarningMessage(string message)
{
SendMessage(TestMessageLevel.Warning, message);
}
public void SendInformationalMessage(string message)
{
SendMessage(TestMessageLevel.Informational, message);
}
public void SendDebugMessage(string message)
{
#if DEBUG
SendMessage(TestMessageLevel.Informational, message);
#endif
}
public void SendMessage(TestMessageLevel testMessageLevel, string message)
{
if (messageLogger != null)
messageLogger.SendMessage(testMessageLevel, message);
}
}
}
// ****************************************************************
// Copyright (c) 2013 NUnit Software. All rights reserved.
// ****************************************************************
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
namespace NUnit.VisualStudio.TestAdapter
{
/// <summary>
/// TestLogger wraps an IMessageLogger and adds various
/// utility methods for sending messages. Since the
/// IMessageLogger is only provided when the discovery
/// and execution objects are called, we use two-phase
/// construction. Until Initialize is called, the logger
/// simply swallows all messages without sending them
/// anywhere.
/// </summary>
public class TestLogger : IMessageLogger
{
private IMessageLogger messageLogger;
public void Initialize(IMessageLogger messageLogger)
{
this.messageLogger = messageLogger;
}
public void AssemblyNotSupportedWarning(string sourceAssembly)
{
SendWarningMessage("Assembly not supported: " + sourceAssembly);
}
public void DependentAssemblyNotFoundWarning(string dependentAssembly, string sourceAssembly)
{
SendWarningMessage("Dependent Assembly " + dependentAssembly + " of " + sourceAssembly + " not found. Can be ignored if not a NUnit project.");
}
public void LoadingAssemblyFailedWarning(string dependentAssembly, string sourceAssembly)
{
SendWarningMessage("Assembly " + dependentAssembly + " loaded through " + sourceAssembly + " failed. Assembly is ignored. Correct deployment of dependencies if this is an error.");
}
public void NUnitLoadError(string sourceAssembly)
{
SendErrorMessage("NUnit failed to load " + sourceAssembly);
}
public void SendErrorMessage(string message)
{
SendMessage(TestMessageLevel.Error, message);
}
public void SendErrorMessage(string message, Exception ex)
{
SendMessage(TestMessageLevel.Error, message);
SendMessage(TestMessageLevel.Error, ex.ToString());
}
public void SendWarningMessage(string message)
{
SendMessage(TestMessageLevel.Warning, message);
}
public void SendInformationalMessage(string message)
{
SendMessage(TestMessageLevel.Informational, message);
}
public void SendDebugMessage(string message)
{
#if DEBUG
SendMessage(TestMessageLevel.Informational, message);
#endif
}
public void SendMessage(TestMessageLevel testMessageLevel, string message)
{
if (messageLogger != null)
messageLogger.SendMessage(testMessageLevel, message);
}
}
}

Просмотреть файл

@ -3,7 +3,7 @@
<Identifier Id="NUnitTestAdapterInstall..7c53286e-ac4f-485f-915c-5ec5a4c47b0c">
<Name>NUnit Test Adapter</Name>
<Author>Charlie Poole</Author>
<Version>1.0.0.7</Version>
<Version>1.0.0.8</Version>
<Description xml:space="preserve">NUnit adapter for integrated test execution under Visual Studio 2012 RTM, Update 1-4,and Visual Studio 2013. Compatible with NUnit 2.0 through 2.6.2.</Description>
<Locale>1033</Locale>
<MoreInfoUrl>http://nunit.org/index.php?p=vsTestAdapter&amp;r=2.6.2</MoreInfoUrl>