Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Laval <jeremie.laval@gmail.com>2018-01-04 21:03:28 +0300
committerJérémie Laval <jeremie.laval@gmail.com>2018-01-04 21:03:28 +0300
commit837b4c1aa29379e4e672a90e5379642804609dc0 (patch)
tree86c70b1f84db731a7085db6cf09d95af4a04e815 /main/src/addins/MonoDevelop.UnitTesting.NUnit
parent0017df5cd485496b0269c51a70ddfbd78c9a25fc (diff)
[NUnit] Properly enumerate project assembly reference dependencies.
This commits changes the way dependencies of a test project are computed by relying on the MSBuild machinary instead of being limited to only the project model. This fixes cases where assembly references are computed on the fly e.g. when custom `ReferencePath` are specified in the project so that `<Reference />` with no hint path are still resolved (something the old system would mistakenly think of as GAC assemblies). The commits changes the API for gathering dependencies to be asynchronous and applies the same sort of filtering as before to only load dependencies that wouldn't be otherwise loaded. An exception here is that facades are pulled in by the underlying call to `GetReferences` without a way to differentiate them from other references, that causes assembly load errors down the line which this commit works around that by wrapping the call in `InitSupportAssemblies` in a try/catch. NB: The scenario that called for this fix is a MonoDevelop addin testsuite which has very specific considerations when it comes to assembly loading. Since that test-suite already uses a custom console runner (via vstool\mdtool) to execute unit-tests maybe it would be a good idea in general to also allow delegation of `GetTestInfo` to a custom runner as well.
Diffstat (limited to 'main/src/addins/MonoDevelop.UnitTesting.NUnit')
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs17
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitProjectTestSuite.cs29
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnit3Runner/NUnitTestRunner.cs10
-rw-r--r--main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnitRunner/NUnitTestRunner.cs10
4 files changed, 46 insertions, 20 deletions
diff --git a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs
index df35ef8e2f..67852fee35 100644
--- a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitAssemblyTestSuite.cs
@@ -212,7 +212,7 @@ namespace MonoDevelop.UnitTesting.NUnit
AsyncCreateTests (ld);
});
};
- ld.SupportAssemblies = new List<string> (SupportAssemblies);
+ ld.SupportAssemblies = GetSupportAssembliesAsync ();
ld.NUnitVersion = NUnitVersion;
AsyncLoadTest (ld);
@@ -332,7 +332,8 @@ namespace MonoDevelop.UnitTesting.NUnit
if (File.Exists (ld.Path)) {
runner = new ExternalTestRunner ();
runner.Connect (ld.NUnitVersion).Wait ();
- ld.Info = runner.GetTestInfo (ld.Path, ld.SupportAssemblies).Result;
+ var supportAssemblies = new List<string> (ld.SupportAssemblies.Result);
+ ld.Info = runner.GetTestInfo (ld.Path, supportAssemblies).Result;
}
} catch (AggregateException exception){
var baseException = exception.GetBaseException ();
@@ -664,11 +665,19 @@ namespace MonoDevelop.UnitTesting.NUnit
protected abstract string AssemblyPath {
get;
}
-
+
+ [Obsolete ("Override GetSupportAssembliesAsync instead")]
protected virtual IEnumerable<string> SupportAssemblies {
get { yield break; }
}
+ protected virtual Task<IEnumerable<string>> GetSupportAssembliesAsync ()
+ {
+ #pragma warning disable 618
+ return Task.FromResult (SupportAssemblies);
+ #pragma warning restore 618
+ }
+
// File where cached test info for this test suite will be saved
// Returns null by default which means that test info will not be saved.
protected virtual string TestInfoCachePath {
@@ -683,7 +692,7 @@ namespace MonoDevelop.UnitTesting.NUnit
public NunitTestInfo Info;
public TestInfoCache InfoCache;
public WaitCallback Callback;
- public List<string> SupportAssemblies;
+ public Task<IEnumerable<string>> SupportAssemblies;
public NUnitVersion NUnitVersion;
}
diff --git a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitProjectTestSuite.cs b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitProjectTestSuite.cs
index 55ed1578fb..1d9f1a7510 100644
--- a/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitProjectTestSuite.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting.NUnit/MonoDevelop.UnitTesting.NUnit/NUnitProjectTestSuite.cs
@@ -205,21 +205,26 @@ namespace MonoDevelop.UnitTesting.NUnit
protected override string TestInfoCachePath {
get { return Path.Combine (resultsPath, storeId + ".test-cache"); }
}
-
- protected override IEnumerable<string> SupportAssemblies {
- get {
+
+ protected override async Task<IEnumerable<string>> GetSupportAssembliesAsync ()
+ {
+ DotNetProject project = base.OwnerSolutionItem as DotNetProject;
+
+ if (project != null) {
+ var references = await project.GetReferences (IdeApp.Workspace.ActiveConfiguration).ConfigureAwait (false);
// Referenced assemblies which are not in the gac and which are not localy copied have to be preloaded
- DotNetProject project = base.OwnerSolutionItem as DotNetProject;
- if (project != null) {
- foreach (var pr in project.References) {
- if (pr.ReferenceType != ReferenceType.Package && !pr.LocalCopy && pr.ReferenceOutputAssembly) {
- foreach (string file in pr.GetReferencedFileNames (IdeApp.Workspace.ActiveConfiguration))
- yield return file;
- }
- }
- }
+ var supportAssemblies = references.Where (r => !r.IsCopyLocal && (!r.IsProjectReference || r.ReferenceOutputAssembly) && !r.IsFrameworkFile && !r.IsImplicit && !IsGacReference (r))
+ .Select (r => r.FilePath.FullPath.ToString ())
+ .Where (File.Exists)
+ .Distinct ()
+ .ToList ();
+ return supportAssemblies;
}
+
+ return Enumerable.Empty<string> ();
}
+
+ bool IsGacReference (AssemblyReference r) => string.Equals (r.Metadata.GetValue ("ResolvedFrom"), "{GAC}", StringComparison.OrdinalIgnoreCase);
}
}
diff --git a/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnit3Runner/NUnitTestRunner.cs b/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnit3Runner/NUnitTestRunner.cs
index 517c30437a..93002f6305 100644
--- a/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnit3Runner/NUnitTestRunner.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnit3Runner/NUnitTestRunner.cs
@@ -205,8 +205,14 @@ namespace NUnit3Runner
void InitSupportAssemblies (string[] supportAssemblies)
{
// Preload support assemblies (they may not be in the test assembly directory nor in the gac)
- foreach (string asm in supportAssemblies)
- Assembly.LoadFrom (asm);
+ foreach (string asm in supportAssemblies) {
+ try {
+ Assembly.LoadFrom (asm);
+ } catch (Exception e) {
+ Console.WriteLine ("Couldn't load assembly {0}", asm);
+ Console.WriteLine (e);
+ }
+ }
}
private TestFilter CreateTestFilter (string[] nameFilter)
diff --git a/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnitRunner/NUnitTestRunner.cs b/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnitRunner/NUnitTestRunner.cs
index 8059c6d934..e66b39c5b5 100644
--- a/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnitRunner/NUnitTestRunner.cs
+++ b/main/src/addins/MonoDevelop.UnitTesting.NUnit/NUnitRunner/NUnitTestRunner.cs
@@ -155,8 +155,14 @@ namespace MonoDevelop.UnitTesting.NUnit.External
void InitSupportAssemblies (string[] supportAssemblies)
{
// Preload support assemblies (they may not be in the test assembly directory nor in the gac)
- foreach (string asm in supportAssemblies)
- Assembly.LoadFrom (asm);
+ foreach (string asm in supportAssemblies) {
+ try {
+ Assembly.LoadFrom (asm);
+ } catch (Exception e) {
+ Console.WriteLine ("Couldn't load assembly {0}", asm);
+ Console.WriteLine (e);
+ }
+ }
}
public override object InitializeLifetimeService ()