Skip to content

Commit 4160fbc

Browse files
authored
Merge pull request #81 from machine/bug/fix-dotnet-core
[Bug] Fix tests not found in dotnet core projects/out of memory
2 parents 68a4c42 + 428c282 commit 4160fbc

File tree

4 files changed

+23
-31
lines changed

4 files changed

+23
-31
lines changed

Source/Machine.VSTestAdapter/Discovery/BuiltIn/SourceCodeLocationFinder.cs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
43
using System.Reflection;
54
using Mono.Cecil;
65
using Mono.Cecil.Cil;
76

87
namespace Machine.VSTestAdapter.Discovery.BuiltIn
98
{
10-
public class SourceCodeLocationFinder
9+
public class SourceCodeLocationFinder : IDisposable
1110
{
1211
private readonly Lazy<AssemblyDefinition> assemblyDefinition;
1312

@@ -36,11 +35,15 @@ private AssemblyDefinition LoadAssembly(string assemblyFilePath)
3635
});
3736
}
3837

38+
public void Dispose()
39+
{
40+
Assembly?.Dispose();
41+
}
42+
3943
private AssemblyDefinition Assembly {
4044
get { return assemblyDefinition.Value; }
4145
}
4246

43-
4447
private string HandleNestedTypeName(string type)
4548
{
4649
return type.Replace("+", "/");
@@ -63,23 +66,18 @@ private SourceCodeLocationInfo GetFieldLocationCore(TypeDefinition type, string
6366
if (!constructorDefinition.HasBody)
6467
return null;
6568

66-
#if NETCOREAPP1_1
6769
if (constructorDefinition.DebugInformation == null)
6870
return null;
69-
#endif
7071

7172
Instruction instruction = constructorDefinition.Body.Instructions
72-
.Where(x => x.Operand != null &&
73+
.SingleOrDefault(x => x.Operand != null &&
7374
x.Operand.GetType().IsAssignableFrom(typeof(FieldDefinition)) &&
74-
((MemberReference)x.Operand).Name == fieldFullName).SingleOrDefault();
75+
((MemberReference)x.Operand).Name == fieldFullName);
7576

7677
while (instruction != null)
7778
{
78-
#if NETCOREAPP1_1
7979
SequencePoint sequencePoint = constructorDefinition.DebugInformation?.GetSequencePoint(instruction);
80-
#else
81-
SequencePoint sequencePoint = instruction.SequencePoint;
82-
#endif
80+
8381
if (sequencePoint != null && !IsHidden(sequencePoint))
8482
{
8583
return new SourceCodeLocationInfo()
@@ -97,13 +95,7 @@ private SourceCodeLocationInfo GetFieldLocationCore(TypeDefinition type, string
9795

9896
private bool IsHidden(SequencePoint sequencePoint)
9997
{
100-
101-
#if NETCOREAPP1_1
10298
return sequencePoint.IsHidden;
103-
#else
104-
const int lineNumberIndicatingHiddenLine = 0xfeefee;
105-
return sequencePoint.StartLine == lineNumberIndicatingHiddenLine;
106-
#endif
10799
}
108100
}
109101

Source/Machine.VSTestAdapter/Discovery/BuiltIn/TestDiscoverer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public IEnumerable<MSpecTestCase> DiscoverTests(string assemblyPath)
2424
Assembly assembly = AssemblyHelper.Load(assemblyPath);
2525
IEnumerable<Context> contexts = assemblyExplorer.FindContextsIn(assembly);
2626

27-
SourceCodeLocationFinder locationFinder = new SourceCodeLocationFinder(assemblyPath);
28-
29-
return contexts.SelectMany(context => CreateTestCase(context, locationFinder)).ToList();
27+
using (SourceCodeLocationFinder locationFinder = new SourceCodeLocationFinder(assemblyPath))
28+
{
29+
return contexts.SelectMany(context => CreateTestCase(context, locationFinder)).ToList();
30+
}
3031
}
3132

3233
private IEnumerable<MSpecTestCase> CreateTestCase(Context context, SourceCodeLocationFinder locationFinder)

Source/Machine.VSTestAdapter/Machine.VSTestAdapter.csproj

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,24 @@
2626
<DefineConstants>NETSTANDARD</DefineConstants>
2727
</PropertyGroup>
2828

29-
<ItemGroup Condition="'$(TargetFramework)'==$(_TargetDotNetCore)">
29+
<ItemGroup>
3030
<PackageReference Include="Mono.Cecil" Version="[0.10-*, 0.11)" />
31-
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="[15.0.0,16)">
32-
<PrivateAssets>All</PrivateAssets> <!-- Only a reference during build/dev time -->
33-
</PackageReference>
3431
<PackageReference Include="Machine.Specifications" Version="[0.11.0, 1.0)">
3532
<PrivateAssets>All</PrivateAssets>
3633
<!-- Only a reference during build/dev time -->
3734
</PackageReference>
3835
</ItemGroup>
36+
37+
<ItemGroup Condition="'$(TargetFramework)'==$(_TargetDotNetCore)">
38+
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="[15.0.0,16)">
39+
<PrivateAssets>All</PrivateAssets> <!-- Only a reference during build/dev time -->
40+
</PackageReference>
41+
</ItemGroup>
3942

4043
<ItemGroup Condition="'$(TargetFramework)'=='$(_TargetDotNetFramework)'">
41-
<PackageReference Include="Mono.Cecil" Version="0.9.6.1" />
4244
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="[11.0.0,16.0.0)">
4345
<PrivateAssets>All</PrivateAssets> <!-- Only a reference during build/dev time -->
4446
</PackageReference>
45-
<PackageReference Include="Machine.Specifications" Version="[0.11.0, 1.0)">
46-
<PrivateAssets>All</PrivateAssets> <!-- Only a reference during build/dev time -->
47-
</PackageReference>
4847
</ItemGroup>
4948

5049
<ItemGroup>

appveyor.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
environment:
2-
nuget_version: '2.6.1'
3-
assembly_version: '2.6.1'
2+
nuget_version: '2.7.0'
3+
assembly_version: '2.7.0'
44

55
version: '$(nuget_version)+{build}'
66

@@ -28,7 +28,7 @@ test_script: dotnet test -c %CONFIGURATION% Source\Machine.VSTestAdapter.Specs
2828
deploy:
2929
- provider: GitHub
3030
description: |
31-
* Fix to support for VS 2017 15.5.x
31+
* Fix for out ot memory exceptions and tests not showing up
3232
3333
on:
3434
appveyor_repo_tag: true

0 commit comments

Comments
 (0)