Skip to content

Commit 41944bf

Browse files
[Bug] Fix tests not found in dotnet core projects
1 parent 68a4c42 commit 41944bf

File tree

3 files changed

+22
-30
lines changed

3 files changed

+22
-30
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: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Product>Machine.Specifications.Runner.VisualStudio</Product>
1313
<AssemblyTitle>Machine.Specifications.Runner.VisualStudio</AssemblyTitle>
1414
<PackageId>Machine.Specifications.Runner.VisualStudio </PackageId>
15-
<Version>1.0.0</Version>
15+
<Version>2.0.0</Version>
1616
<AssemblyVersion>1.0.0.0</AssemblyVersion>
1717
<Authors>https://github.com/machine/machine.vstestadapter</Authors>
1818
<PackageProjectUrl>https://github.com/machine/machine.vstestadapter</PackageProjectUrl>
@@ -25,26 +25,25 @@
2525
<PropertyGroup Condition="'$(TargetFramework)'=='netcoreapp1.1'">
2626
<DefineConstants>NETSTANDARD</DefineConstants>
2727
</PropertyGroup>
28-
29-
<ItemGroup Condition="'$(TargetFramework)'==$(_TargetDotNetCore)">
28+
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>

0 commit comments

Comments
 (0)