Skip to content
This repository has been archived by the owner on Dec 25, 2023. It is now read-only.

Commit

Permalink
(GH-4) Add BinaryLogFileFormat
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Sep 11, 2018
1 parent 88a7392 commit c692378
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
</PropertyGroup>

<ItemGroup>
<None Remove="Testfiles\FullLog.binlog" />
<None Remove="Testfiles\FullLog.xml" />
<None Remove="Testfiles\IssueWithFile.xml" />
<None Remove="Testfiles\IssueWithLineZero.xml" />
Expand All @@ -24,6 +25,7 @@
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Testfiles\BinaryLogFileFormat\FullLog.binlog" />
<EmbeddedResource Include="Testfiles\XmlFileLoggerLogFileFormat\FullLog.xml" />
<EmbeddedResource Include="Testfiles\XmlFileLoggerLogFileFormat\IssueWithoutCode.xml" />
<EmbeddedResource Include="Testfiles\XmlFileLoggerLogFileFormat\IssueWithFile.xml" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
namespace Cake.Issues.MsBuild.Tests.LogFileFormat
{
using System.Linq;
using Cake.Core.Diagnostics;
using Cake.Issues.MsBuild.LogFileFormat;
using Core.IO;
using Shouldly;
using Testing;
using Xunit;

public sealed class BinaryLogFileFormatTests
{
public sealed class TheCtor
{
[Fact]
public void Should_Throw_If_Log_Is_Null()
{
// Given
ICakeLog log = null;

// When
var result = Record.Exception(() => new BinaryLogFileFormat(log));

// Then
result.IsArgumentNullException("log");
}
}

public sealed class TheReadIssuesMethod
{
[Fact]
public void Should_Read_Full_Log_Correct()
{
// Given
var fixture = new MsBuildIssuesProviderFixture<BinaryLogFileFormat>("FullLog.binlog");
fixture.RepositorySettings = new RepositorySettings(@"c:\Git\Test\Cake.Prca\");

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

// Then
issues.Count.ShouldBe(19);
CheckIssue(
issues[0],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
13,
"CS0219",
300,
"Warning",
@"The variable 'foo' is assigned but its value is never used");
CheckIssue(
issues[1],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
1,
"SA1652",
300,
"Warning",
@"Enable XML documentation output");
CheckIssue(
issues[2],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
1,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[3],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
2,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[4],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
3,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[5],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
4,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[6],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
5,
"SA1200",
300,
"Warning",
@"Using directive must appear within a namespace declaration");
CheckIssue(
issues[7],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
1,
"SA1633",
300,
"Warning",
@"The file header is missing or not located at the top of the file.");
CheckIssue(
issues[8],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
1,
"SA1652",
300,
"Warning",
@"Enable XML documentation output");
CheckIssue(
issues[9],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
1,
"SA1633",
300,
"Warning",
@"The file header is missing or not located at the top of the file.");
CheckIssue(
issues[10],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
5,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[11],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
17,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[12],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
18,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[13],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
28,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[14],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Properties\AssemblyInfo.cs",
32,
"SA1028",
300,
"Warning",
@"Code must not contain trailing whitespace");
CheckIssue(
issues[15],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
null,
null,
"CA2210",
300,
"Warning",
@"Microsoft.Design : Sign 'ClassLibrary1.dll' with a strong name key.");
CheckIssue(
issues[16],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
null,
null,
"CA1014",
300,
"Warning",
@"Microsoft.Design : Mark 'ClassLibrary1.dll' with CLSCompliant(true) because it exposes externally visible types.");
CheckIssue(
issues[17],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
12,
"CA1822",
300,
"Warning",
@"Microsoft.Performance : The 'this' parameter (or 'Me' in Visual Basic) of 'Class1.Foo()' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in the method body or at least one property accessor, if appropriate.");
CheckIssue(
issues[18],
@"src\ClassLibrary1\ClassLibrary1.csproj",
"ClassLibrary1",
@"src\ClassLibrary1\Class1.cs",
13,
"CA1804",
300,
"Warning",
@"Microsoft.Performance : 'Class1.Foo()' declares a variable, 'foo', of type 'string', which is never used or is only assigned to. Use this variable or remove it.");
}

private static void CheckIssue(
IIssue issue,
string projectFileRelativePath,
string projectName,
string affectedFileRelativePath,
int? line,
string rule,
int priority,
string priorityName,
string message)
{
issue.ProviderType.ShouldBe("Cake.Issues.MsBuild.MsBuildIssuesProvider");
issue.ProviderName.ShouldBe("MSBuild");

if (issue.ProjectFileRelativePath == null)
{
projectFileRelativePath.ShouldBeNull();
}
else
{
issue.ProjectFileRelativePath.ToString().ShouldBe(new FilePath(projectFileRelativePath).ToString());
issue.ProjectFileRelativePath.IsRelative.ShouldBe(true, "Issue path is not relative");
}

issue.ProjectName.ShouldBe(projectName);

if (issue.AffectedFileRelativePath == null)
{
affectedFileRelativePath.ShouldBeNull();
}
else
{
issue.AffectedFileRelativePath.ToString().ShouldBe(new FilePath(affectedFileRelativePath).ToString());
issue.AffectedFileRelativePath.IsRelative.ShouldBe(true, "Issue path is not relative");
}

issue.Line.ShouldBe(line);
issue.Rule.ShouldBe(rule);
issue.Priority.ShouldBe(priority);
issue.PriorityName.ShouldBe(priorityName);
issue.Message.ShouldBe(message);
}
}
}
}
Binary file not shown.
3 changes: 2 additions & 1 deletion src/Cake.Issues.MsBuild/Cake.Issues.MsBuild.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
Expand Down Expand Up @@ -27,6 +27,7 @@
<PackageReference Include="Cake.Core" Version="0.28.0" />
<PackageReference Include="Cake.Issues" Version="0.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.1" />
<PackageReference Include="MSBuild.StructuredLogger" Version="2.0.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2" />
</ItemGroup>

Expand Down
Loading

0 comments on commit c692378

Please sign in to comment.