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

Commit

Permalink
Merge pull request #60 from pascalberger/feature/gh-49
Browse files Browse the repository at this point in the history
 (GH-49) Update to Cake.Issues 0.7.0-beta003
  • Loading branch information
pascalberger committed May 27, 2019
2 parents 7c41e20 + c51a493 commit 6ee300b
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 134 deletions.
4 changes: 2 additions & 2 deletions src/Cake.Issues.EsLint.Tests/Cake.Issues.EsLint.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.1.0" />
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Testing" Version="0.33.0" />
<PackageReference Include="Cake.Issues" Version="0.6.0" />
<PackageReference Include="Cake.Issues.Testing" Version="0.6.0" />
<PackageReference Include="Cake.Issues" Version="0.7.0-beta0003" />
<PackageReference Include="Cake.Issues.Testing" Version="0.7.0-beta0003" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand Down
38 changes: 20 additions & 18 deletions src/Cake.Issues.EsLint.Tests/EsLintIssuesSettingsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public sealed class EsLintIssuesSettingsTests
{
public sealed class TheEsLintIssuesSettingsCtor
public sealed class TheCtor
{
[Fact]
public void Should_Throw_If_LogFilePath_Is_Null()
Expand All @@ -20,7 +20,8 @@ public void Should_Throw_If_LogFilePath_Is_Null()
var format = new JsonLogFileFormat(new FakeLog());

// When
var result = Record.Exception(() => new EsLintIssuesSettings(logFilePath, format));
var result = Record.Exception(() =>
new EsLintIssuesSettings(logFilePath, format));

// Then
result.IsArgumentNullException("logFilePath");
Expand All @@ -44,53 +45,54 @@ public void Should_Throw_If_Format_For_LogFilePath_Is_Null()
}

[Fact]
public void Should_Throw_If_LogContent_Is_Null()
public void Should_Throw_If_LogFileContent_Is_Null()
{
// Given
byte[] logFileContent = null;
var format = new JsonLogFileFormat(new FakeLog());

// When
var result = Record.Exception(() => new EsLintIssuesSettings(logFileContent, format));
var result = Record.Exception(() =>
new EsLintIssuesSettings(logFileContent, format));

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

[Fact]
public void Should_Throw_If_LogContent_Is_Empty()
public void Should_Throw_If_Format_For_LogFileContent_Is_Null()
{
// Given
byte[] logFileContent = Array.Empty<byte>();
var format = new JsonLogFileFormat(new FakeLog());
var logFileContent = "foo".ToByteArray();
BaseEsLintLogFileFormat format = null;

// When
var result = Record.Exception(() => new EsLintIssuesSettings(logFileContent, format));
var result = Record.Exception(() =>
new EsLintIssuesSettings(logFileContent, format));

// Then
result.IsArgumentException("logFileContent");
result.IsArgumentNullException("format");
}

[Fact]
public void Should_Throw_If_Format_For_LogFileContent_Is_Null()
public void Should_Set_LogFileContent()
{
// Given
var logFileContent = "foo".ToByteArray();
BaseEsLintLogFileFormat format = null;
var logFileContent = "Foo".ToByteArray();
var format = new JsonLogFileFormat(new FakeLog());

// When
var result = Record.Exception(() =>
new EsLintIssuesSettings(logFileContent, format));
var settings = new EsLintIssuesSettings(logFileContent, format);

// Then
result.IsArgumentNullException("format");
settings.LogFileContent.ShouldBe(logFileContent);
}

[Fact]
public void Should_Set_LogContent()
public void Should_Set_LogFileContent_If_Empty()
{
// Given
var logFileContent = "Foo".ToByteArray();
byte[] logFileContent = Array.Empty<byte>();
var format = new JsonLogFileFormat(new FakeLog());

// When
Expand All @@ -101,7 +103,7 @@ public void Should_Set_LogContent()
}

[Fact]
public void Should_Set_LogContent_From_LogFilePath()
public void Should_Set_LogFileContent_From_LogFilePath()
{
// Given
var format = new JsonLogFileFormat(new FakeLog());
Expand Down
196 changes: 83 additions & 113 deletions src/Cake.Issues.EsLint.Tests/LogFileFormat/JsonLogFileFormatTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Cake.Issues.EsLint.Tests.LogFileFormat
{
using System;
using System.Linq;
using Cake.Core.IO;
using Cake.Issues.EsLint.LogFileFormat;
using Cake.Issues.Testing;
using Shouldly;
using Xunit;

Expand Down Expand Up @@ -34,127 +35,96 @@ public void Should_Read_Issue_Correct()

// Then
issues.Count.ShouldBe(9);
CheckIssue(
IssueChecker.Check(
issues[0],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
1,
"no-unused-vars",
"http://eslint.org/docs/rules/no-unused-vars",
400,
"Error",
"'addOne' is defined but never used.");
CheckIssue(
IssueBuilder.NewIssue(
"'addOne' is defined but never used.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 1)
.OfRule("no-unused-vars", new Uri("http://eslint.org/docs/rules/no-unused-vars"))
.WithPriority(IssuePriority.Error)
.Create());
IssueChecker.Check(
issues[1],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
2,
"use-isnan",
"http://eslint.org/docs/rules/use-isnan",
400,
"Error",
"Use the isNaN function to compare with NaN.");
CheckIssue(
IssueBuilder.NewIssue(
"Use the isNaN function to compare with NaN.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 2)
.OfRule("use-isnan", new Uri("http://eslint.org/docs/rules/use-isnan"))
.WithPriority(IssuePriority.Error)
.Create());
IssueChecker.Check(
issues[2],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
3,
"space-unary-ops",
"http://eslint.org/docs/rules/space-unary-ops",
400,
"Error",
"Unexpected space before unary operator '++'.");
CheckIssue(
IssueBuilder.NewIssue(
"Unexpected space before unary operator '++'.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 3)
.OfRule("space-unary-ops", new Uri("http://eslint.org/docs/rules/space-unary-ops"))
.WithPriority(IssuePriority.Error)
.Create());
IssueChecker.Check(
issues[3],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
3,
"semi",
"http://eslint.org/docs/rules/semi",
300,
"Warning",
"Missing semicolon.");
CheckIssue(
IssueBuilder.NewIssue(
"Missing semicolon.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 3)
.OfRule("semi", new Uri("http://eslint.org/docs/rules/semi"))
.WithPriority(IssuePriority.Warning)
.Create());
IssueChecker.Check(
issues[4],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
4,
"no-else-return",
"http://eslint.org/docs/rules/no-else-return",
300,
"Warning",
"Unnecessary 'else' after 'return'.");
CheckIssue(
IssueBuilder.NewIssue(
"Unnecessary 'else' after 'return'.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 4)
.OfRule("no-else-return", new Uri("http://eslint.org/docs/rules/no-else-return"))
.WithPriority(IssuePriority.Warning)
.Create());
IssueChecker.Check(
issues[5],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
5,
"indent",
"http://eslint.org/docs/rules/indent",
300,
"Warning",
"Expected indentation of 8 spaces but found 6.");
CheckIssue(
IssueBuilder.NewIssue(
"Expected indentation of 8 spaces but found 6.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 5)
.OfRule("indent", new Uri("http://eslint.org/docs/rules/indent"))
.WithPriority(IssuePriority.Warning)
.Create());
IssueChecker.Check(
issues[6],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
5,
"consistent-return",
"http://eslint.org/docs/rules/consistent-return",
400,
"Error",
"Function 'addOne' expected a return value.");
CheckIssue(
IssueBuilder.NewIssue(
"Function 'addOne' expected a return value.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 5)
.OfRule("consistent-return", new Uri("http://eslint.org/docs/rules/consistent-return"))
.WithPriority(IssuePriority.Error)
.Create());
IssueChecker.Check(
issues[7],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
5,
"semi",
"http://eslint.org/docs/rules/semi",
300,
"Warning",
"Missing semicolon.");
CheckIssue(
IssueBuilder.NewIssue(
"Missing semicolon.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 5)
.OfRule("semi", new Uri("http://eslint.org/docs/rules/semi"))
.WithPriority(IssuePriority.Warning)
.Create());
IssueChecker.Check(
issues[8],
@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js",
7,
"no-extra-semi",
"http://eslint.org/docs/rules/no-extra-semi",
400,
"Error",
"Unnecessary semicolon.");
}

private static void CheckIssue(
IIssue issue,
string affectedFileRelativePath,
int? line,
string rule,
string ruleUrl,
int priority,
string priorityName,
string message)
{
issue.ProviderType.ShouldBe("Cake.Issues.EsLint.EsLintIssuesProvider");
issue.ProviderName.ShouldBe("ESLint");

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);

if (issue.RuleUrl == null)
{
ruleUrl.ShouldBeNull();
}
else
{
issue.RuleUrl.ToString().ShouldBe(ruleUrl);
}

issue.Priority.ShouldBe(priority);
issue.PriorityName.ShouldBe(priorityName);
issue.Message.ShouldBe(message);
IssueBuilder.NewIssue(
"Unnecessary semicolon.",
"Cake.Issues.EsLint.EsLintIssuesProvider",
"ESLint")
.InFile(@"src\Cake.Issues.EsLint.Tests\Testfiles\fullOfProblems.js", 7)
.OfRule("no-extra-semi", new Uri("http://eslint.org/docs/rules/no-extra-semi"))
.WithPriority(IssuePriority.Error)
.Create());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Issues.EsLint/Cake.Issues.EsLint.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

<ItemGroup>
<PackageReference Include="Cake.Core" Version="0.33.0" />
<PackageReference Include="Cake.Issues" Version="0.6.0" />
<PackageReference Include="Cake.Issues" Version="0.7.0-beta0003" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="System.Runtime.Serialization.Json" Version="4.3.0" />
Expand Down

0 comments on commit 6ee300b

Please sign in to comment.