Skip to content

Commit a014bf0

Browse files
authored
Path is empty for VB My namespace (#1073)
Path is empty for VB My namespace
1 parent 1ff097d commit a014bf0

File tree

7 files changed

+59
-9
lines changed

7 files changed

+59
-9
lines changed

Documentation/Changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
### Fixed
1010
-Incorrect coverage for methods returning IAsyncEnumerable in generic classes [#1383](https://github.com/coverlet-coverage/coverlet/issues/1383)
1111
-Wrong branch coverage for async methods .NET Standard 1.x [#1376](https://github.com/coverlet-coverage/coverlet/issues/1376)
12+
-Empty path exception in visual basic projects [#775](https://github.com/coverlet-coverage/coverlet/issues/775)
1213
-Allign published nuget package version to github release version [#1413](https://github.com/coverlet-coverage/coverlet/issues/1413)
1314
-Sync nuget and github release versions [#1122](https://github.com/coverlet-coverage/coverlet/issues/1122)
1415

coverlet.sln

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{9A8B19D4
5454
test\Directory.Build.targets = test\Directory.Build.targets
5555
EndProjectSection
5656
EndProject
57+
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "coverlet.tests.projectsample.vbmynamespace", "test\coverlet.tests.projectsample.vbmynamespace\coverlet.tests.projectsample.vbmynamespace.vbproj", "{C9B7DC34-3E04-4F20-AED4-73791AF8020D}"
58+
EndProject
5759
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "coverlet.tests.projectsample.fsharp", "test\coverlet.tests.projectsample.fsharp\coverlet.tests.projectsample.fsharp.fsproj", "{1CBF6966-2A67-4D2C-8598-D174B83072F4}"
5860
EndProject
5961
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "coverlet.tests.projectsample.netframework", "test\coverlet.tests.projectsample.netframework\coverlet.tests.projectsample.netframework.csproj", "{E69D68C9-78ED-4076-A14B-D07295A4B2A5}"
@@ -120,6 +122,10 @@ Global
120122
{F8199E19-FA9A-4559-9101-CAD7028121B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
121123
{F8199E19-FA9A-4559-9101-CAD7028121B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
122124
{F8199E19-FA9A-4559-9101-CAD7028121B4}.Release|Any CPU.Build.0 = Release|Any CPU
125+
{C9B7DC34-3E04-4F20-AED4-73791AF8020D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
126+
{C9B7DC34-3E04-4F20-AED4-73791AF8020D}.Debug|Any CPU.Build.0 = Debug|Any CPU
127+
{C9B7DC34-3E04-4F20-AED4-73791AF8020D}.Release|Any CPU.ActiveCfg = Release|Any CPU
128+
{C9B7DC34-3E04-4F20-AED4-73791AF8020D}.Release|Any CPU.Build.0 = Release|Any CPU
123129
{1CBF6966-2A67-4D2C-8598-D174B83072F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
124130
{1CBF6966-2A67-4D2C-8598-D174B83072F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
125131
{1CBF6966-2A67-4D2C-8598-D174B83072F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -150,6 +156,7 @@ Global
150156
{9A8B19D4-4A24-4217-AEFE-159B68F029A1} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
151157
{1CBF6966-2A67-4D2C-8598-D174B83072F4} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
152158
{E69D68C9-78ED-4076-A14B-D07295A4B2A5} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
159+
{C9B7DC34-3E04-4F20-AED4-73791AF8020D} = {2FEBDE1B-83E3-445B-B9F8-5644B0E0E134}
153160
EndGlobalSection
154161
GlobalSection(ExtensibilityGlobals) = postSolution
155162
SolutionGuid = {9CA57C02-97B0-4C38-A027-EA61E8741F10}

src/coverlet.core/Instrumentation/Instrumenter.cs

+3
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,9 @@ private void InstrumentType(TypeDefinition type)
531531
private void InstrumentMethod(MethodDefinition method)
532532
{
533533
string sourceFile = method.DebugInformation.SequencePoints.Select(s => _sourceRootTranslator.ResolveFilePath(s.Document.Url)).FirstOrDefault();
534+
535+
if (string.IsNullOrEmpty(sourceFile)) return;
536+
534537
if (!string.IsNullOrEmpty(sourceFile) && _excludedFilesHelper.Exclude(sourceFile))
535538
{
536539
if (!(_excludedSourceFiles ??= new List<string>()).Contains(sourceFile))

test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs

+33-9
Original file line numberDiff line numberDiff line change
@@ -615,15 +615,8 @@ public int SampleMethod()
615615
var instrumenter = new Instrumenter(excludedbyattributeDll, "_xunit_excludedbyattribute", parametes, loggerMock.Object, instrumentationHelper, partialMockFileSystem.Object, new SourceRootTranslator(loggerMock.Object, new FileSystem()), new CecilSymbolHelper());
616616

617617
InstrumenterResult result = instrumenter.Instrument();
618-
if (expectedExcludes)
619-
{
620-
Assert.Empty(result.Documents);
621-
loggerMock.Verify(l => l.LogVerbose(It.IsAny<string>()));
622-
}
623-
else
624-
{
625-
Assert.NotEmpty(result.Documents);
626-
}
618+
Assert.Empty(result.Documents);
619+
if (expectedExcludes) { loggerMock.Verify(l => l.LogVerbose(It.IsAny<string>())); }
627620
}
628621

629622
[Fact]
@@ -807,5 +800,36 @@ public void TestReachabilityHelper()
807800

808801
instrumenterTest.Directory.Delete(true);
809802
}
803+
804+
[Fact]
805+
public void Instrumenter_MethodsWithoutReferenceToSource_AreSkipped()
806+
{
807+
var loggerMock = new Mock<ILogger>();
808+
809+
string module = Directory.GetFiles(Directory.GetCurrentDirectory(), "coverlet.tests.projectsample.vbmynamespace.dll").First();
810+
string pdb = Path.Combine(Path.GetDirectoryName(module), Path.GetFileNameWithoutExtension(module) + ".pdb");
811+
812+
DirectoryInfo directory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()));
813+
814+
File.Copy(module, Path.Combine(directory.FullName, Path.GetFileName(module)), true);
815+
File.Copy(pdb, Path.Combine(directory.FullName, Path.GetFileName(pdb)), true);
816+
817+
var instrumentationHelper =
818+
new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock<ILogger>().Object,
819+
new SourceRootTranslator(module, new Mock<ILogger>().Object, new FileSystem()));
820+
821+
CoverageParameters parameters = new();
822+
823+
var instrumenter = new Instrumenter(Path.Combine(directory.FullName, Path.GetFileName(module)), "_coverlet_tests_projectsample_vbmynamespace", parameters,
824+
loggerMock.Object, instrumentationHelper, new FileSystem(), new SourceRootTranslator(Path.Combine(directory.FullName, Path.GetFileName(module)), loggerMock.Object, new FileSystem()), new CecilSymbolHelper());
825+
826+
instrumentationHelper.BackupOriginalModule(Path.Combine(directory.FullName, Path.GetFileName(module)), "_coverlet_tests_projectsample_vbmynamespace");
827+
828+
InstrumenterResult result = instrumenter.Instrument();
829+
830+
Assert.False(result.Documents.ContainsKey(string.Empty));
831+
832+
directory.Delete(true);
833+
}
810834
}
811835
}

test/coverlet.core.tests/coverlet.core.tests.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<ProjectReference Include="$(RepoRoot)test\coverlet.core.tests.samples.netstandard\coverlet.core.tests.samples.netstandard.csproj" />
3030
<ProjectReference Include="$(RepoRoot)test\coverlet.tests.xunit.extensions\coverlet.tests.xunit.extensions.csproj" />
3131
<ProjectReference Include="$(RepoRoot)test\coverlet.tests.projectsample.netframework\coverlet.tests.projectsample.netframework.csproj" />
32+
<ProjectReference Include="$(RepoRoot)test\coverlet.tests.projectsample.vbmynamespace\coverlet.tests.projectsample.vbmynamespace.vbproj" />
3233
</ItemGroup>
3334

3435
<ItemGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Public Class SampleVbClass
2+
Sub SampleSub()
3+
Return
4+
End Sub
5+
End Class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<RootNamespace>coverlet.tests.projectsample.vbmynamespace</RootNamespace>
5+
<TargetFramework>net48</TargetFramework>
6+
<LangVersion>latest</LangVersion>
7+
</PropertyGroup>
8+
9+
</Project>

0 commit comments

Comments
 (0)