Skip to content

Commit

Permalink
(cake-contribGH-7) Pass null for warnings belonging to a file but wit…
Browse files Browse the repository at this point in the history
…h line 0
  • Loading branch information
pascalberger committed Sep 7, 2017
1 parent 44425a5 commit 58c0efc
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Testfiles\IssueWithLineZero.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
Expand Down
6 changes: 6 additions & 0 deletions src/Cake.Issues.MsBuild.Tests/Testfiles/IssueWithLineZero.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<build started="3/7/2017 8:31:20 AM">
<project file="c:\Source\Cake.Issues.MsBuild\Cake.Prca.shfbproj" started="9/7/2017 7:22:28 AM">
<warning code="BE0006" file="SHFB" line="0" column="0" started="9/7/2017 7:22:31 AM"><![CDATA[Unable to locate any documentation sources for 'c:\Source\Cake.Prca\Cake.Prca..csproj' (Configuration: Debug Platform: AnyCPU)]]></warning>
</project>
</build>
21 changes: 21 additions & 0 deletions src/Cake.Issues.MsBuild.Tests/XmlFileLoggerFormatTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,27 @@ public void Should_Read_Issue_With_File_Without_Path_Correct()
"The variable 'foo' is assigned but its value is never used");
}

[Fact]
public void Should_Read_Issue_With_Line_Zero_Correct()
{
// Given
var fixture = new MsBuildIssuesProviderFixture("IssueWithLineZero.xml");

// When
var issues = fixture.ReadIssues().ToList();

// Then
issues.Count.ShouldBe(1);
var issue = issues.Single();
CheckIssue(
issue,
@"SHFB",
null,
"BE0006",
0,
@"Unable to locate any documentation sources for 'c:\Source\Cake.Prca\Cake.Prca..csproj' (Configuration: Debug Platform: AnyCPU)");
}

[Fact]
public void Should_Read_Issue_Without_File_Correct()
{
Expand Down
4 changes: 2 additions & 2 deletions src/Cake.Issues.MsBuild/XmlFileLoggerFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ private static bool TryGetLine(XElement warning, out int? line)

line = int.Parse(lineValue, CultureInfo.InvariantCulture);

// Convert negative lines numbers to null
if (line < 0)
// Convert negative line numbers or line number 0 to null
if (line <= 0)
{
line = null;
}
Expand Down

0 comments on commit 58c0efc

Please sign in to comment.